Updated: 18 November 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9
CentOS 7 is end of life. This guide installs the current Laravel with Nginx and PHP-FPM on Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9.
Before you start
- A VPS or dedicated server with a fresh Ubuntu 24.04 / Debian 12 or AlmaLinux 9 / Rocky Linux 9 installation, and root or sudo access.
- A domain or subdomain pointing to the server (an A record), if you want HTTPS.
- The system updated:
apt update && apt upgradeordnf upgrade.
Install Nginx, MariaDB and PHP-FPM
Ubuntu 24.04 / Debian 12:
apt install nginx mariadb-server php-fpm php-mysql php-xml php-mbstring php-curl php-zip php-gd php-intl systemctl enable --now nginx mariadb php8.3-fpm # php8.2-fpm on Debian 12
AlmaLinux 9 / Rocky Linux 9:
dnf module reset php && dnf module enable php:8.3 dnf install nginx mariadb-server php-fpm php-mysqlnd php-xml php-mbstring php-gd php-intl php-opcache php-pecl-zip systemctl enable --now nginx mariadb php-fpm
On AlmaLinux 9 / Rocky Linux 9, edit /etc/php-fpm.d/www.conf and set user = nginx and group = nginx, then restart php-fpm. Secure MariaDB with mariadb-secure-installation.
Install Composer
apt install composer # Ubuntu 24.04 / Debian 12
# or the official installer (any system):
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm composer-setup.php
Create a database
mariadb -u root -p CREATE DATABASE laravel CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'laraveluser'@'localhost' IDENTIFIED BY 'Strong-Password'; GRANT ALL PRIVILEGES ON laravel.* TO 'laraveluser'@'localhost'; FLUSH PRIVILEGES; EXIT;
Create the Laravel project
cd /var/www composer create-project laravel/laravel example-app cd example-app cp .env.example .env # if not created php artisan key:generate
Set the database details in .env (DB_DATABASE, DB_USERNAME, DB_PASSWORD), then run php artisan migrate.
Permissions
chown -R www-data:www-data storage bootstrap/cache # apache or nginx on AlmaLinux/Rocky chmod -R 775 storage bootstrap/cache
The web server's document root must be the project's public folder, never the project folder itself.
Note: Laravel 13 (the current version) needs PHP 8.3 or newer: Ubuntu 24.04 and AlmaLinux/Rocky 9 with the php:8.3 stream are fine. On Debian 12 (PHP 8.2) Composer installs Laravel 12 instead, which receives security fixes until February 2027.
Create the Nginx server block
Create /etc/nginx/sites-available/example.com and link it into sites-enabled (Ubuntu/Debian), or create /etc/nginx/conf.d/example.com.conf (AlmaLinux/Rocky):
server {
listen 80;
server_name example.com www.example.com;
root /var/www/example-app/public;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php8.3-fpm.sock; # /run/php-fpm/www.sock on AlmaLinux/Rocky
}
}
Check and reload: nginx -t && systemctl reload nginx.
Add a free SSL certificate
apt install certbot python3-certbot-nginx # Ubuntu / Debian dnf install epel-release && dnf install certbot python3-certbot-nginx # AlmaLinux / Rocky certbot --nginx -d example.com -d www.example.com
Certbot installs a timer that renews the certificate automatically; test it with certbot renew --dry-run.
Note: On AlmaLinux 9 / Rocky Linux 9 SELinux is on. Let Apache/Nginx write where the application needs it, for example: semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/example-app/storage(/.*)?" && restorecon -R /var/www/example-app, and allow outgoing connections if the app calls APIs: setsebool -P httpd_can_network_connect 1.