When you work with Laravel and need to take care of the actual launch of the web application there tend to be two things you need to take care of. You need to set up the server or provision it as they call it. Two, you need to set up a deployment system to update it. When you roam the web for options you will find out there aren’t really many out of the box solutions.
Let me briefly touch upon local development. Homestead or Laravel Valet are awesome for local development. And these options are totally for free. There is even Laradock if you prefer to work with Docker containers. But from local development you will need to go to staging and production to test things online and ultimately push to production. So what are the options out there?
There are as always multiple options to set up your own staging or production server that plays nice with Laravel PHP. Here are the main ones.
To have a server setup online for staging and or production Laravel Forge is your go to person. It is a provisioning and basic deployment GUI set up by the folks behind Laravel itself and is really easy to work with. It will cost you though. It comes at a minimum $19 dollars per month. You do get unlimited servers, websites and deployments though. The only downside is that deployment will not be without downtime. For that you will need Envoyer . More on that later.
Cloudways Managed Laravel Cloud Hosting
Another option is Cloudways Managed Laravel Hosting. They have a relatively new managed hosting package for Laravel. And it sets you up nicely and on top offers all their goodies like basic githooks, server or app cloning and so on. I was and still am interested in this set up. The server setup is beautiful with caching, Nginx for static files, Apache for dynamic files, PHP 7 and so on. Downside here is no zero downtime deployment available nor full root access it being managed hosting.
DIY Server Stack
A third option is a DIY option. You set up the entire server yourself using the command line, Bash scripts or Ansible Playbooks. I have not found any decent repos that help you set up a server let alone one that mirrors Homestead. But you could do a first setup and create Bash scripts based on it. You could also clone a setup you use a base for future Laravel setups. And you can of course always get started with a LEMP VPS with Digital Ocean or another Cloud Provider.
Stedding is a set of Ansible playbooks for a Laravel LEMP Stack I have been working on for the last two to three weeks. The project Stedding is ongoing. If you do have time and interest, please take it for a spin and send in your pull requests. I could sure use some help and or feedback. Mind you, it is not done as of yet. Still a work in progress. It does however set up a:
- LEMP stack with
- PHP 7.1
- admin and web users
- Certbot Let’s Encrypt SSL
- Laravel Webroot
I am also going to add Deployer for zero downtime deployment, but for now I have not added it to the server.yml as a role to be included. There are other issues I have to work on first like
- Composer inside web user path,
- Cerbot Nginx Plugin full SSL certificate automation – only partly done now,
- Nginx config tweaks to have browser caching and compression taken care of
and what not. But hey, I am getting there and with your help things will go even quicker 😉 .
For deployment Laravel has setup a zero downtime solution called Envoyer. And it can work in tandem with Forge and is also a really nifty tool. Again, you would need to pay for this and perhaps on top of your Forge setups. It starts at $10 USD a month. For this you can work on ten projects. So if you work with three Git branches I assume that would be 3 projects already.
So what are the alternatives when you do not want to cough up $10 or more a month? Well you could use Deployer or Deploybot. The former is 100% for free and works with Laravel and is recommended by us. The Deploybot also looks good but is commercial and is at least $15 a month. So Deploybot is not much of a choice here as Envoyer will be cheaper.
The other alternative is of course setting up your own Githooks and setting up symlinking the latest deploy to your production webroot. But to me as Deployer is a great a free tool and helps out with all this I would not really roll my own. Just like I am not writing all Ansible Playbooks myself. No need to reinvent the wheel no is there?
Well, there you have it, the lowdown on Laravel PHP Server provisioning and deployment. If you have a great alternatives or know of great repositories that we could use to automate the setting up of staging and or production servers please let us know!
Here is the Ansible auto provisioning script for local and remote environments:
Thanks Denys, I checked it out and looks promising. More recent than my Stedding package and better organized. Looking forward to seeing options to add Redis, Fast CGI Caching. What I also always miss is the option to split the database from the application server using its own server. The same goes for Redis by the way. Other things we had to do manually using a Laravel ACME package for LE SSL automation for all incoming domains. Would be great if Ansible can have an environment set up for that as well as this is really DevOps too. Finally, a load balancer where all traffic enters and or SSL is dealt with is the next step. Keep up the good work!