Deploying Laravel is not the same as uploading a WordPress site. Here are the steps that matter and the mistakes that cause most errors.
1. Check the requirements
Each Laravel version needs a minimum PHP version and several PHP extensions, such as mbstring, openssl, pdo, tokenizer, xml, ctype and fileinfo. Check the documentation for your version, then confirm that the server provides it, along with Composer.
2. Upload the code
Use Git where possible. Do not upload your local vendor folder or your local .env file.
3. Install the dependencies
composer install --no-dev --optimize-autoloader
4. Create the .env file
Set at least these values on the server:
APP_ENV=production
APP_DEBUG=false
APP_URL=https://yourdomain.com
Then add the database details and generate the key:
php artisan key:generate
Never leave APP_DEBUG on in production, because errors can expose secrets.
5. Point the domain to the public folder
The web server must serve the public folder, not the project root. In cPanel, set the domain’s document root to the public folder. Do not leave the project files in a web-accessible folder.
6. Set permissions
The storage and bootstrap/cache folders must be writable by the web server user.
7. Run the migrations and cache the configuration
php artisan migrate --force
php artisan storage:link
php artisan config:cache
php artisan route:cache
php artisan view:cache
After config:cache, use env() only inside config files, because it will not read .env elsewhere.
8. Set up the scheduler and queues
Add a cron job that runs every minute:
* * * * * php /path/to/project/artisan schedule:run >> /dev/null 2>&1
For queues, a process manager such as Supervisor on a VPS is the reliable option. On shared hosting you can run queue:work with the –stop-when-empty option from cron.
Common errors
- 500 error: check storage/logs/laravel.log, a missing APP_KEY and folder permissions.
- 404 on every route except the home page: the document root or mod_rewrite is wrong.
- No application encryption key has been specified: run php artisan key:generate.
We deploy and maintain Laravel and Node.js applications. Tell us about your project.
Leave a Reply