One of the final steps in every web-project is deploying to live server. Often I see a problem when server is provided by the client from their hosting they had purchased long time ago, and it is not suitable for convenient Laravel deployment. So in this article I will make some recommendations for clients, what hosting to prepare.
Disclaimer: this article is my personal advice after 5 years working with Laravel. Other people may have different recommendations on the process of deployment, may have different preferences for servers or hosting, so this article is what works well for my team and my clients.
To understand what server we need, let’s recap how deployment works in Laravel:
- Code should be stored in repository, in a system like Github or Bitbucket
- Then developer needs to have SSH access to the server, connect and run a set of commands, like
git cloneto download the code to the server, and then some Laravel-related commands like
artisan migrateand a few others, depending on the app details.
- Then, every time some new code changes are pushed to the repository, same procedure – SSH connect to the machine and running a few commands to pull the latest code version.
To perform that, the best option is to have a dedicated server with SSH access. Dedicated in this case means that it’s not shared with any other websites, so you can safely configure it, without breaking other projects.
Now, there are a few providers of dedicated servers tailored specifically to PHP projects, so they come with pre-installed software for PHP, MySQL database, Web-server like Nginx etc. These are mostly good for smaller projects:
So all you need, as a client, is to purchase a server (starting from $5/month) and give access to developer.
With server you will get its unique IP address, and then you should point your domain (yourdomain.com) DNS records to that IP address.
Another popular option is AWS (stands for Amazon Web Services) which provides many more Amazon tools for scaling the server, within Amazon ecosystem. It’s a better option for bigger projects, but it’s much more difficult to set up, and requires specific knowledge from a developer.
To recap, I recommend clients would choose one of those three providers above, my personal preference is Digital Ocean.
Why shared-hosting is bad for Laravel
Most popular and cheap hosting providers offer so-called “shared” hosting, which means your space on the server is shared with other customers, therefore you have limited access to configure it.
Shared-hosting is good for simple CMS sites based on WordPress or Drupal, but for custom Laravel apps it’s not enough. Here’s why:
- Without SSH access developer can’t easily copy latest code with one command, uploading via FTP is unreliable and untraceable in case of errors
- Some Laravel apps require specific software, PHP libraries, write permissions to some folders, additional settings. Quite often shared hosting restricts you from it.
- You generally share resources with other hosting customers which may slow performance
I have a video-rant about it:
Tools for more convenient deployment
Developers can make their lives easier by using a few more tools for faster deployment.
Created by Laravel’s author Taylor Otwell himself, it’s an online tool that connects to your Digital Ocean account and does things like:
- create new server
- perform deployment with a click of a button, without doing SSH connect
- set up auto deployment, which would be launched whenever new code is pushed to the repository
And many other things unrelated to deployment: SSL certificate installation, queue cron jobs management, error logging to Slack etc.
I’ve shot a video demo how Forge works, see here:
Also from the same author Taylor, another tool from Laravel ecosystem which allows you to pull the latest code changes without taking down your website. It’s so-called “zero time deployment”.
In general, deployment takes some time – pulling the code, running some scripts, clearing cache etc. Meanwhile, your web app is taken down with some maintenance page, or, even worse, it’s stay live to users and have unpredictable error messages. To avoid that, if you have more sensitive audience or higher traffic, I do advice Envoyer.
It also saves 5 previous deployment events, and allows you to rollback to previous deployments, in case something went wrong.
I also have a video for Envoyer, check this out.
Basically, that’s it about servers, deployment and additional tools.
- Don’t use shared-hosting
- I recommend Digital Ocean hosting for smaller projects
- My personal preference is using Laravel Forge to save more time
P.S. advice to developers: don’t do hosting yourselves, unless it’s part of your business. It’s a pretty hard work to guarantee 99.9% uptime, provide 24/7 support and just have anxiety waking up in the middle of the night when some site is down. And it’s not big revenue, just not worth the money. So let your clients purchase the hosting and servers.