Complete VPS Setup Guide for Laravel, PHP, Apache & MySQL on Ubuntu

Last Updated On - February 13th, 2026 Published On - Feb 13, 2026

This guide provides a complete production-ready VPS setup for Laravel applications running on Ubuntu with Apache, MySQL and PHP. It is designed for developers and DevOps engineers who want a stable, secure and scalable deployment environment.


1. Initial Ubuntu Server Preparation

Connect to your VPS via SSH and update system packages:

sudo apt update && sudo apt -y upgrade

Create a secure non-root sudo user:

sudo adduser prashant
sudo usermod -aG sudo prashant

2. Install Apache Web Server

sudo apt install -y apache2
sudo a2enmod rewrite headers ssl
sudo systemctl enable apache2
sudo systemctl start apache2

3. Install and Secure MySQL

sudo apt install -y mysql-server
sudo mysql_secure_installation

Create database and user for Laravel:

CREATE DATABASE laravel_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;

4. Install PHP (mod_php Setup)

sudo apt install php php-mysql php-xml php-mbstring php-curl php-zip php-gd php-bcmath php-intl

Edit php.ini (usually located at /etc/php/8.x/apache2/php.ini) and update:

memory_limit = 512M
max_execution_time = 300
upload_max_filesize = 64M
post_max_size = 64M

Restart Apache:

sudo systemctl restart apache2

5. Deploy Laravel Application

sudo mkdir -p /var/www/html/project
sudo chown prashant:www-data /var/www/html/project
cd /var/www/html/project
git clone your_repo .
composer install --no-dev --optimize-autoloader
cp .env.example .env
php artisan key:generate
php artisan migrate --seed

Fix storage permission issues:

sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
php artisan optimize:clear

6. SSL Configuration with Let’s Encrypt

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d example.com -d www.example.com

If using Cloudflare, set SSL mode to Full (Strict) and avoid duplicate HTTPS redirects in Apache.


7. Configure Supervisor for Laravel Queues

sudo apt install supervisor
[program:laravel-worker]
command=/usr/bin/php /var/www/html/project/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data

Reload Supervisor:

sudo supervisorctl reread
sudo supervisorctl update


8. Firewall and Security Hardening

sudo apt install ufw
sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable
sudo apt install fail2ban

Frequently Asked Questions

What causes “Too Many Redirects” in Laravel VPS setup?

Duplicate HTTPS redirect rules between Apache and Cloudflare usually cause redirect loops. Use Full (Strict) SSL mode and avoid redundant redirects.

Why can’t Laravel write to storage/framework/views?

Incorrect ownership. Ensure storage and bootstrap/cache are owned by www-data and have 775 permissions.

How do I reload updated php.ini?

If using mod_php, restart Apache using: sudo systemctl restart apache2

Should I use mod_php or PHP-FPM?

For high-traffic applications, PHP-FPM is recommended. For smaller projects, mod_php works fine.