How to Install Laravel on AlmaLinux 8

Install Laravel on AlmaLinux 8 with PHP 8.3, Apache, MariaDB, Composer, firewalld, TLS, and SELinux-safe permissions for a production-ready app.
A glowing PHP application layer connects an AlmaLinux server to a protected database in a blue-lit data center.

Install Laravel on AlmaLinux 8 in about 20 minutes and finish with a Laravel 13 application served by Apache and PHP-FPM. You will configure MariaDB, Composer, firewalld, HTTPS, and SELinux without turning off the protection that keeps the server safe.

Prerequisites

  • A fresh 64-bit AlmaLinux 8 VPS with at least 2 GB of RAM and 15 GB of available disk space.
  • SSH access as root, or a user with working sudo privileges and outbound HTTPS access.
  • A DNS name such as YOUR_DOMAIN pointing to the VPS. You need a real domain for the HTTPS step.
  • A VPSLake Linux VPS with root access if you need a server for this installation.

The commands use sudo for a non-root account. If you are logged in as root, remove sudo. Replace every uppercase placeholder before running the related command.

Step 1: Update AlmaLinux 8 and install the server packages

Updating first gives the PHP repository and web stack current AlmaLinux 8 dependencies.

sudo dnf upgrade -y
sudo dnf install -y epel-release curl git unzip firewalld httpd mariadb-server mariadb policycoreutils-python-utils

Laravel 13 needs PHP 8.3 or newer. AlmaLinux 8’s default AppStream PHP is older, so add Remi’s Enterprise Linux 8 repository and select its PHP 8.3 module stream.

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf module reset php -y
sudo dnf module install php:remi-8.3 -y
sudo dnf install -y php-fpm php-mysqlnd php-pecl-zip php-gd php-mbstring php-curl php-xml php-bcmath php-opcache
sudo systemctl enable --now firewalld httpd php-fpm mariadb
php -v
sudo systemctl is-active firewalld httpd php-fpm mariadb

The version should begin with PHP 8.3, and each service check should print active.

PHP 8.3.x (cli) ...
active
active
active
active

Step 2: Install Composer with checksum verification

Composer resolves Laravel’s PHP dependencies; checking the installer’s SHA-384 value prevents a damaged or tampered download from being installed.

cd /tmp
EXPECTED_CHECKSUM="$(curl -fsSL https://composer.github.io/installer.sig)"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then echo 'ERROR: Invalid Composer installer checksum'; rm -f composer-setup.php; exit 1; fi
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
rm -f composer-setup.php
composer --version

The final line should report Composer 2.x. The Composer installation guide explains this checksum-based installer workflow.

Composer version 2.x.x 20xx-xx-xx

Step 3: Create a MariaDB database and application user

Laravel should connect with a narrowly scoped account instead of using MariaDB’s administrative login.

sudo mariadb-secure-installation

Keep local socket authentication for the database administrator, remove anonymous accounts, reject remote root login, remove the test database, and reload the privilege tables when prompted. Then create a database and two local-only account entries; the second host entry matches Laravel’s 127.0.0.1 connection.

sudo mariadb <<'SQL'
CREATE DATABASE laravel_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';
CREATE USER 'laravel_user'@'127.0.0.1' IDENTIFIED BY 'YOUR_DB_PASSWORD';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'localhost';
GRANT ALL PRIVILEGES ON laravel_db.* TO 'laravel_user'@'127.0.0.1';
FLUSH PRIVILEGES;
SQL
sudo mariadb -e "SHOW DATABASES LIKE 'laravel_db';"

Use a long, unique password in place of YOUR_DB_PASSWORD. The check should return the new database name.

Database (laravel_db)
laravel_db

Do not open port 3306 in the firewall; Apache and MariaDB are on the same VPS.

Step 4: Create the Laravel application

Installing the project as the apache user avoids leaving a root-owned Composer cache and gives PHP-FPM access to the application files.

sudo install -d -o apache -g apache /var/www/laravelapp /usr/share/httpd/.cache /usr/share/httpd/.config
sudo -u apache -H composer create-project --no-interaction --prefer-dist laravel/laravel:^13.0 /var/www/laravelapp

Laravel’s deployment documentation requires PHP 8.3 or newer, recommends serving only the public directory, and identifies storage and bootstrap/cache as writable paths.

Open the environment file:

sudoedit /var/www/laravelapp/.env

Set these values, replacing YOUR_DOMAIN and YOUR_DB_PASSWORD. Keep the generated APP_KEY line for the next command.

APP_ENV=production
APP_DEBUG=false
APP_URL=http://YOUR_DOMAIN
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_db
DB_USERNAME=laravel_user
DB_PASSWORD=YOUR_DB_PASSWORD

Save the file, generate the encryption key, and run the initial migrations:

sudo -u apache -H php /var/www/laravelapp/artisan key:generate --force
sudo -u apache -H php /var/www/laravelapp/artisan config:clear
sudo -u apache -H php /var/www/laravelapp/artisan migrate --force

Successful migrations end with DONE or Ran. Do not run db:seed unless your own application has seed data you intend to load.

Step 5: Configure Apache and PHP-FPM

Apache must expose only Laravel’s public directory, while PHP-FPM executes PHP through its Unix socket.

Create a virtual host and replace YOUR_DOMAIN before saving it:

sudo tee /etc/httpd/conf.d/zz-laravel.conf > /dev/null <<'APACHE'
<VirtualHost *:80>
    ServerName YOUR_DOMAIN
    DocumentRoot /var/www/laravelapp/public
    DirectoryIndex index.php

    <Directory /var/www/laravelapp/public>
        AllowOverride All
        Options -Indexes +FollowSymLinks
        Require all granted
    </Directory>

    <FilesMatch \.php$>
        SetHandler "proxy:unix:/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>

    ErrorLog /var/log/httpd/laravel-error.log
    CustomLog /var/log/httpd/laravel-access.log combined
</VirtualHost>
APACHE
sudo apachectl configtest
sudo systemctl reload httpd

Syntax OK confirms Apache accepted the configuration. The zz- prefix makes this virtual host’s PHP-FPM handler load after any generic PHP configuration shipped by the package.

Step 6: Keep SELinux enforcing and set permissions

Laravel needs write access only in its cache and storage paths; persistent SELinux labels allow that access without making the entire project writable.

sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/laravelapp/(storage|bootstrap/cache)(/.*)?'
sudo restorecon -Rv /var/www/laravelapp
sudo chown -R root:apache /var/www/laravelapp
sudo find /var/www/laravelapp -type d -exec chmod 0750 {} +
sudo find /var/www/laravelapp -type f -exec chmod 0640 {} +
sudo chown -R apache:apache /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type d -exec chmod 0770 {} +
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type f -exec chmod 0660 {} +
sudo setsebool -P httpd_can_network_connect_db on

The database boolean is needed because the web process connects to MariaDB. Leave SELinux in enforcing mode and use restorecon again after deploying files outside the original project tree.

Step 7: Open web ports and enable HTTPS

Only HTTP and HTTPS need to be public; leave MariaDB private and keep your existing SSH rule unchanged.

sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --zone=public --permanent --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --zone=public --list-services

After YOUR_DOMAIN resolves to the VPS, install the Apache Certbot plugin and request a certificate. Replace YOUR_EMAIL with an address that can receive renewal notices.

sudo dnf install -y mod_ssl certbot python3-certbot-apache
sudo certbot --apache --redirect -d YOUR_DOMAIN -m YOUR_EMAIL --agree-tos --no-eff-email
sudo sed -i 's#^APP_URL=.*#APP_URL=https://YOUR_DOMAIN#' /var/www/laravelapp/.env
sudo -u apache -H php /var/www/laravelapp/artisan config:clear
sudo -u apache -H php /var/www/laravelapp/artisan config:cache

Certbot updates Apache to redirect HTTP to HTTPS. If DNS is not ready yet, skip the certificate command, test over HTTP, and do not use the site for passwords or other sensitive data until TLS is active.

Verify the Laravel installation

These checks confirm the services, Apache syntax, Laravel version, database migrations, and HTTPS response. Use the same domain in the Host header if you skipped Certbot.

sudo systemctl is-active httpd php-fpm mariadb firewalld
sudo apachectl configtest
sudo -u apache -H php /var/www/laravelapp/artisan --version
sudo -u apache -H php /var/www/laravelapp/artisan migrate:status
curl -fsSI https://YOUR_DOMAIN/

Expected results include active services, Syntax OK, a Laravel 13 version, migration statuses, and a successful HTTPS response.

active
active
active
active
Syntax OK
Laravel Framework 13.x
HTTP/2 200

Open https://YOUR_DOMAIN in a browser. The default Laravel page proves that Apache is using the public directory and PHP-FPM is executing the application.

Troubleshooting

Your requirements could not be resolved during Composer install

Composer is probably using the AlmaLinux 8 PHP 8.0 stream, or an extension is missing. Check the CLI version and the extensions Laravel requires, then confirm the Remi module is active.

php -v
php -m | grep -E 'bcmath|ctype|curl|dom|fileinfo|mbstring|openssl|PDO|tokenizer|xml|zip'
sudo dnf module list php

The CLI should show PHP 8.3 or later and the module list should mark remi-8.3 as enabled. If another stream is enabled, reset PHP and install php:remi-8.3/common again before rerunning Composer.

SQLSTATE[HY000] [1045] Access denied

The password in .env does not match the MariaDB account, or Laravel is still using cached settings. Test the account directly and clear the configuration cache after correcting the file.

mariadb -h 127.0.0.1 -u laravel_user -p laravel_db -e 'SELECT 1;'
sudo -u apache -H php /var/www/laravelapp/artisan config:clear
sudo -u apache -H php /var/www/laravelapp/artisan migrate --force

Enter the real database password when prompted. A result containing 1 proves the account works independently of Laravel.

403 Forbidden or Permission denied

Apache may have lost the group permissions or SELinux labels after files were copied into the project. Restore both without disabling SELinux.

sudo restorecon -Rv /var/www/laravelapp
sudo chown -R root:apache /var/www/laravelapp
sudo chown -R apache:apache /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type d -exec chmod 0770 {} +
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type f -exec chmod 0660 {} +
sudo systemctl reload httpd

If it still fails, inspect recent AVC denials with sudo ausearch -m AVC -ts recent and correct the reported path instead of using chmod 777.

503 Service Unavailable or PHP source appears in the browser

PHP-FPM may be stopped, or Apache may be pointing at the wrong socket. Check the service log and the socket path used in zz-laravel.conf.

sudo systemctl status php-fpm --no-pager
sudo journalctl -u php-fpm -n 40 --no-pager
sudo test -S /run/php-fpm/www.sock && echo 'PHP-FPM socket exists'
sudo apachectl configtest
sudo systemctl restart php-fpm httpd

The service should be running, the socket test should print PHP-FPM socket exists, and Apache should return Syntax OK.

Hardening

  • Keep APP_DEBUG=false and run php artisan config:cache only after .env contains its final production values.
  • Schedule backups for /var/www/laravelapp and the MariaDB database before upgrades.
  • Do not expose port 3306; allow SSH only from trusted addresses where your hosting firewall supports source restrictions.
  • Run sudo dnf upgrade -y regularly and renew the certificate with sudo certbot renew --dry-run before relying on automatic renewal.

FAQ

Which Laravel release does this guide install?

It pins the new project to Laravel 13 with laravel/laravel:^13.0. That release supports PHP 8.3, which is why this AlmaLinux 8 guide selects Remi’s PHP 8.3 stream.

Why use Remi on AlmaLinux 8?

AlmaLinux 8’s standard PHP stream is older than the version required by current Laravel. Remi supplies a maintained PHP 8.3 stream using the normal DNF module mechanism, so PHP and its extensions remain managed as packages.

Can I test Laravel without a domain?

You can test Apache over the VPS IP or with a temporary /etc/hosts entry, but Certbot needs a publicly resolving domain. Do not treat an HTTP-only IP test as a production deployment because the connection is not encrypted.

Should I run php artisan serve on the VPS?

No. That command is intended for local development and is not a replacement for a managed web server. Apache and PHP-FPM keep the application behind a service manager and allow you to use HTTPS, firewall rules, and normal logs.

Samrat Ghosh
Written by

Samrat Ghosh

Founder & Infrastructure Engineer

Samrat Ghosh is the founder of VPSLake, where he builds and runs the remote desktop and VPS hosting infrastructure the company is built on. He writes hands-on guides about RDP, Windows Server, VPS management and secure remote access - the practical documentation he wishes had…

Previous Article

How to Install Laravel PHP Framework on AlmaLinux 10

Next Article

Minecraft Server Lag: Diagnose TPS, Ping, and FPS

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨