Guides · SaaS
How to deploy a Laravel app on aaPanel with Nginx, step by step.
Deploy Laravel on a VPS using aaPanel and Nginx: PHP version, document root, rewrite rule, permissions, .env, queues.
Key takeaways
- Point the site's document root at
public, never at the project root. - Laravel needs an Nginx rewrite so every route goes through
index.php. storageandbootstrap/cachemust be writable by the PHP user.- Most 500 errors after deployment are permissions, a missing
.envor a missingAPP_KEY.
Before you start
You need a VPS with aaPanel installed, a domain pointed at the server, and a PHP version supported by your Laravel release. Check the Laravel documentation for the minimum PHP version of your version, and install that PHP version from aaPanel's App Store, along with the extensions Laravel needs (such as fileinfo, mbstring, openssl, pdo_mysql and tokenizer).
Step 1: create the site
In aaPanel, add a site with your domain and the right PHP version. Create a database at the same time if you use MySQL. Upload your code to the site folder, by Git, SFTP or a zip.
Step 2: set the document root to public
Laravel keeps public files in public/. In the site settings set the running directory to /public. If the document root is the project root, visitors may be able to reach files such as .env. This is the most important security step.
Step 3: add the rewrite rule
Open the site's URL rewrite settings and use the Laravel rule, which is equivalent to:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
Without it, only the home page works and every other route returns 404.
Step 4: install dependencies and configure
On the server, from the project root:
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
Edit .env: set APP_ENV=production, APP_DEBUG=false, your APP_URL and the database credentials. Then run php artisan migrate --force.
Step 5: permissions
PHP must be able to write to two folders:
chown -R www:www storage bootstrap/cache
chmod -R 775 storage bootstrap/cache
aaPanel's PHP user is usually www. If you ran Composer or artisan as root, files in storage can end up owned by root, and logging then fails with a 500 error.
Step 6: cache for production
php artisan config:cache
php artisan route:cache
php artisan view:cache
Run them again after every deployment. If you change .env and nothing happens, the cached config is the reason.
Step 7: scheduler and queues
Add one cron entry that runs php artisan schedule:run every minute, and run queue workers under a process manager. I cover that in Laravel queues and the scheduler on a VPS.
Troubleshooting
- 500 error, blank page: read
storage/logs/laravel.log. WithAPP_DEBUG=falsethe browser shows nothing useful. - "No application encryption key": run
php artisan key:generate. - 404 on all routes except home: the rewrite rule is missing.
- Styles missing:
APP_URLis wrong, or assets were not built and uploaded. - Changes not showing: clear caches with
php artisan optimize:clear.
Frequently asked questions
Do I need Docker?
No. A panel with Nginx and PHP-FPM is enough for many projects and simpler to manage for one server.
Should .env be in Git?
No. Keep .env out of the repository and create it on the server.
How do I update the site?
Pull the new code, run composer install --no-dev, php artisan migrate --force and the cache commands. Put the site in maintenance mode if migrations are risky.
See how I run a multi-tenant Laravel SaaS in production.
See the products