Install Laravel on AlmaLinux 10 with Nginx, PHP-FPM and MySQL

By Raman Kumar

Share:

Updated on Mar 16, 2026

Install Laravel on AlmaLinux 10 with Nginx, PHP-FPM and MySQL

Learn how to install Laravel on AlmaLinux 10 VPS using Nginx, PHP-FPM, MySQL and Composer. This guide covers Laravel server setup, SSL configuration with Certbot.

Introduction

Laravel is one of the most widely used PHP frameworks for modern web applications. Running Laravel on a VPS provides full control over performance, security, and scalability. In this guide we configure a production-ready Laravel environment on AlmaLinux 10, including Nginx, PHP-FPM, MySQL, Composer, and SSL with Certbot.

The process follows the same type of environment used by many professional hosting providers and cloud platforms.

Prerequisites

Before we begin, ensure we have the following:

  • An AlmaLinux 10 on dedicated server or KVM VPS.
  • Basic Linux Command Line Knowledge.
  • A domain name pointing A DNS record to server IP.

Learn how to install Laravel on AlmaLinux 10 VPS using Nginx, PHP-FPM, MySQL and Composer.

Update the Server

Before installing any packages, the system should be updated to ensure security patches and stable dependencies are installed.

sudo dnf update -y

Install some essential utilities used during deployment.

sudo dnf install curl unzip git -y

Keeping the server updated helps maintain system stability and security.

Install Nginx Web Server

Nginx is widely used for Laravel deployments because of its performance and efficiency.

Install Nginx:

sudo dnf install nginx -y

Start and enable the service:

sudo systemctl enable --now nginx

Verify the service status:

sudo systemctl status nginx

Opening the server IP in a browser should display the default Nginx welcome page.

Configure Firewall

AlmaLinux uses firewalld by default. We need to allow HTTP and HTTPS traffic.

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

This ensures the web server can accept public connections.

Install MySQL (MariaDB)

Laravel applications typically use MySQL-compatible databases.

Install MariaDB server:

sudo dnf install mariadb-server -y

Start and enable the database service:

sudo systemctl enable --now mariadb

Secure the installation:

sudo mysql_secure_installation

Create a database and user for the Laravel application.

sudo mysql
CREATE DATABASE laravel_app;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'StrongPasswordHere';
GRANT ALL PRIVILEGES ON laravel_app.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

This creates a dedicated database environment for the Laravel application.

Install PHP 8.3 and Required Extensions

Laravel requires several PHP extensions to function properly.

Install PHP and required modules:

sudo dnf install php php-fpm php-mysqlnd php-cli php-curl php-mbstring php-xml php-bcmath php-zip php-gd php-intl -y

Verify installation:

php -v

Start and enable PHP-FPM:

sudo systemctl enable --now php-fpm

Configure PHP-FPM

Edit the PHP-FPM configuration so Nginx can communicate with it.

sudo nano /etc/php-fpm.d/www.conf

Ensure the following lines are set:

user = nginx
group = nginx
listen = /run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx

Restart PHP-FPM:

sudo systemctl restart php-fpm

Install Composer

Composer is the dependency manager used by Laravel.

Download and install Composer:

cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer

Verify installation:

composer --version

Install Laravel Application

Navigate to the web root directory.

cd /var/www

Create a Laravel project using Composer.

composer create-project laravel/laravel laravel-app

Set correct ownership for the web server.

sudo chown -R nginx:nginx /var/www/laravel-app

Update required directory permissions.

sudo chmod -R 775 /var/www/laravel-app/storage
sudo chmod -R 775 /var/www/laravel-app/bootstrap/cache

These directories must be writable for Laravel to store cache, sessions, and logs.

Configure Laravel Environment

Move to the Laravel project directory.

cd /var/www/laravel-app

Generate the application key.

php artisan key:generate

Edit the environment file:

nano .env

Update database settings:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_app
DB_USERNAME=laravel_user
DB_PASSWORD=StrongPasswordHere

Run migrations if the application includes database tables.

php artisan migrate

Configure Nginx for Laravel

Create a new Nginx server configuration.

sudo nano /etc/nginx/conf.d/laravel.conf

Add the following configuration:

server {
    listen 80;
    server_name example.com;

    root /var/www/laravel-app/public;
    index index.php index.html;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~ /\.ht {
        deny all;
    }
}

Test Nginx configuration:

sudo nginx -t

Reload the server:

sudo systemctl reload nginx

Opening the domain should now display the Laravel welcome page.

Install SSL with Certbot

Secure HTTPS connections are essential for modern web applications.

Install Certbot:

sudo dnf install certbot python3-certbot-nginx -y

Generate the SSL certificate:

sudo certbot --nginx -d example.com -d www.example.com

Verify automatic renewal:

sudo certbot renew --dry-run

Certbot automatically renews certificates before expiration.

Configure SELinux (If enabled):

Set the correct SELinux context:

sudo chcon -R -t httpd_sys_rw_content_t /var/www/laravel-app/storage
sudo chcon -R -t httpd_sys_rw_content_t /var/www/laravel-app/bootstrap/cache

Make the SELinux rule persistent. chcon fixes it immediately but may reset after relabeling.

So we also define a permanent rule.

sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/laravel-app/storage(/.*)?"
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/laravel-app/bootstrap/cache(/.*)?"

Apply the contexts:

sudo restorecon -Rv /var/www/laravel-app

Allow Nginx/PHP to make outbound connections:

sudo setsebool -P httpd_can_network_connect 1

Access Laravel

Navigate to your browser and access the URL:

https://example.com

Deploy Laravel on Ubuntu

Optimize Laravel for Production

Laravel provides several optimization commands to improve application performance.

Run the following commands inside the project directory.

php artisan config:cache
php artisan route:cache
php artisan view:cache

These commands reduce runtime processing and improve response speed.

Configure Background Queue Workers (Optional)

Laravel applications often process tasks in the background using queues.

Install Supervisor:

sudo dnf install supervisor -y

Create a worker configuration.

sudo nano /etc/supervisord.d/laravel-worker.ini

Example configuration:

[program:laravel-worker]
command=php /var/www/laravel-app/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=nginx
numprocs=3
redirect_stderr=true
stdout_logfile=/var/www/laravel-app/worker.log

Restart Supervisor:

sudo systemctl restart supervisord

Summary

In this tutorial, we have seen how to install Laravel on AlmaLinux 10 with Nginx, PHP-FPM and MySQL. A properly configured Laravel server includes several layers working together: Nginx, PHP-FPM, database services, Composer dependencies, and SSL security. Once these components are configured correctly, Laravel applications can scale reliably on VPS infrastructure.

This setup provides a strong foundation for running production Laravel applications while maintaining performance, security, and flexibility.