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 clone
to download the code to the server, and then some Laravel-related commands likecomposer install
,artisan migrate
and 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.
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
Tools for more convenient deployment
Developers can make their lives easier by using a few more tools for faster deployment. 1. Laravel Forge 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
2. Laravel Envoyer 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. To recap:
- Don't use shared-hosting
- I recommend Digital Ocean hosting for smaller projects
- My personal preference is using Laravel Forge to save more time
No comments or questions yet...