How to Install Laravel PHP Framework on Rocky Linux 8

Install Laravel PHP framework on Rocky Linux 8 with PHP 8.3, Apache, MariaDB, Composer, HTTPS, firewalld, and SELinux-safe permissions for production.
A glowing PHP application gateway connects a Rocky Linux server to a protected MariaDB database.

To install Laravel PHP framework on Rocky Linux 8, you will set up Laravel 13 with PHP 8.3, Apache, PHP-FPM, and MariaDB in about 20 minutes. The finished application serves only Laravel’s public directory, keeps SELinux enforcing, and is ready for HTTPS.

Prerequisites

  • A fresh 64-bit Rocky Linux 8 VPS with at least 2 GB of RAM and 15 GB of free disk space.
  • SSH access as root, or a normal account with working sudo privileges and outbound HTTPS access.
  • A public IP address. A DNS name such as YOUR_DOMAIN is required for a trusted Let’s Encrypt certificate.
  • A VPSLake Linux VPS with root access if you need a Rocky Linux server for this setup.

These commands assume a non-root account. If you are logged in as root, remove sudo. Replace uppercase placeholders with real values before running the related command.

Step 1: Confirm Rocky Linux 8 and install PHP 8.3

Rocky Linux 8’s built-in PHP stream is older than Laravel 13 requires, so this release uses the Remi PHP 8.3 module while keeping the rest of the operating system packages native.

grep -E '^(PRETTY_NAME|VERSION_ID|PLATFORM_ID)=' /etc/os-release
uname -m
sudo dnf upgrade -y
sudo dnf install -y epel-release firewalld httpd mariadb-server mariadb curl git unzip policycoreutils-python-utils
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 php-cli php-fpm php-mysqlnd php-mbstring php-xml php-bcmath php-curl php-gd php-opcache php-pecl-zip
sudo systemctl enable --now firewalld httpd php-fpm mariadb
php -v
sudo systemctl is-active firewalld httpd php-fpm mariadb

The release check should identify Rocky Linux 8 and the architecture should normally be x86_64. PHP should start with 8.3, followed by four active lines.

PRETTY_NAME="Rocky Linux 8.x (Green Obsidian)"
VERSION_ID="8.x"
x86_64
PHP 8.3.x (cli) ...
active
active
active
active

PHP 8.3 is supplied by Remi’s Enterprise Linux 8 module. The Rocky Linux PHP documentation explains the distribution’s module-based PHP layout; do not enable the Rocky 9 or 10 instructions on this server.

Step 2: Prepare a MariaDB database

Laravel should have its own database credentials, so a compromised application cannot reuse the database administrator account.

sudo mariadb-secure-installation

When the hardening wizard asks, remove anonymous users and the test database, disallow remote root login, and reload the privilege tables. Keeping local administrative socket authentication is fine for this setup.

Create a database and two local account entries. The 127.0.0.1 entry matches the TCP connection Laravel will use in .env.

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

Use a long, unique password instead of YOUR_DB_PASSWORD. The check should print the database name. MariaDB remains local, so do not open port 3306 in firewalld.

Database (laravel_app)
laravel_app

Step 3: Install Composer safely

Composer downloads Laravel and resolves its dependencies; checking the installer checksum before execution protects this administrative step from a damaged download.

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. This follows Composer’s official programmatic installation procedure, which publishes the current SHA-384 value separately from the installer.

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

Step 4: Create the Laravel project and set its environment

Creating the project as Apache’s service account avoids a root-owned Composer cache and lets PHP-FPM access the generated 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

Open the generated environment file:

sudoedit /var/www/laravelapp/.env

Keep the generated APP_KEY line for the moment, then set these values. Replace YOUR_DOMAIN and YOUR_DB_PASSWORD with the same values used in the previous steps.

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_app
DB_USERNAME=laravel_app
DB_PASSWORD=YOUR_DB_PASSWORD

Generate the application key and run the initial migrations as Apache:

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

You should see an application-key success message and completed migration lines. Do not run db:seed here: a new Laravel project does not need sample records, and production data should come from your own application.

Step 5: Configure Apache and PHP-FPM

Apache must point at public, not the project root, because .env and Composer metadata must stay outside the web-exposed directory.

Create the virtual host and replace both occurrences of YOUR_DOMAIN before saving:

sudo tee /etc/httpd/conf.d/zz-laravel.conf > /dev/null <<'APACHE'
<VirtualHost *:80>
    ServerName YOUR_DOMAIN
    ServerAlias www.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 that Apache accepted the file. The PHP-FPM socket keeps PHP execution on the local server instead of exposing a separate application port.

Step 6: Set permissions without weakening SELinux

Laravel writes logs, sessions, compiled views, and cache data only in storage and bootstrap/cache; the application source can remain owned by root.

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 persistent file-context rule survives a later relabel. The boolean allows the PHP process to reach MariaDB, while the narrow ownership rules keep the rest of the project read-only to Apache. Leave SELinux in enforcing mode.

Step 7: Open web ports and add HTTPS

Allow SSH, HTTP, and HTTPS in the active firewalld zone while leaving the database private.

FIREWALL_ZONE="$(sudo firewall-cmd --get-default-zone)"
sudo firewall-cmd --permanent --zone="$FIREWALL_ZONE" --add-service=ssh
sudo firewall-cmd --permanent --zone="$FIREWALL_ZONE" --add-service=http
sudo firewall-cmd --permanent --zone="$FIREWALL_ZONE" --add-service=https
sudo firewall-cmd --reload
sudo firewall-cmd --zone="$FIREWALL_ZONE" --list-services

After YOUR_DOMAIN resolves to the VPS, 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 adds the HTTPS virtual host and redirect. If DNS is not ready, postpone the certificate command, test over HTTP, and do not use the temporary endpoint for real credentials.

Verify the Laravel installation

Run these checks before opening the site in a browser:

sudo systemctl is-active firewalld httpd php-fpm mariadb
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 -H 'Host: YOUR_DOMAIN' http://127.0.0.1/

Expect four active results, Syntax OK, a Laravel 13 version, migration statuses, and an HTTP response. A 301 is normal after Certbot enables the HTTPS redirect.

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

Once DNS and TLS are working, open https://YOUR_DOMAIN. The default Laravel page proves that Apache is using the intended document root and PHP-FPM is executing the framework.

Troubleshooting

No available modular metadata or PHP remains at 8.0

The Remi repository may not have been installed, or an older PHP stream is still selected. Check the module inventory and switch to the EL8 PHP 8.3 stream rather than mixing packages from another Rocky release.

sudo dnf repolist
sudo dnf module list php
sudo dnf module reset php -y
sudo dnf module switch-to php:remi-8.3/common -y
php -v

The module list should show remi-8.3 enabled and php -v should report 8.3 or later. If the switch reports conflicting extensions, remove only the conflicting old PHP extension and repeat the module operation.

SQLSTATE[HY000] [1045] Access denied

The password in .env may differ from MariaDB, or Laravel may have cached the previous value. Test the application account outside Laravel, then clear the cached configuration.

mariadb -h 127.0.0.1 -u laravel_app -p laravel_app -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

The query should return 1. If it fails, reset the password for both laravel_app host entries instead of granting the application administrative access.

AH01071: Got error 'Primary script unknown'

Apache is reaching PHP-FPM, but the script path does not match the public document root or the PHP-FPM socket handler was not loaded. Check the socket and the virtual host, then reload both services.

sudo test -S /run/php-fpm/www.sock && echo 'PHP-FPM socket exists'
sudo apachectl configtest
sudo systemctl restart php-fpm httpd
sudo tail -20 /var/log/httpd/laravel-error.log

The socket test should print PHP-FPM socket exists, and Apache should return Syntax OK. Confirm that DocumentRoot ends in /public.

403 Forbidden or Permission denied

The Apache group may not be able to traverse the project, or SELinux labels may be stale after files were copied. Restore labels and reapply the two writable-directory owners.

sudo restorecon -Rv /var/www/laravelapp
sudo chown -R apache:apache /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache
sudo ausearch -m AVC -ts recent | tail -20
sudo systemctl reload httpd

If ausearch reports a denial, fix the path or boolean named by the event. Do not disable SELinux or apply a broad chmod.

Hardening

  • Keep APP_DEBUG=false and run sudo -u apache -H php /var/www/laravelapp/artisan optimize after a production deployment.
  • Keep port 3306 closed and restrict SSH to trusted source addresses in the provider firewall where possible.
  • Back up /var/www/laravelapp and the MariaDB database before upgrades.
  • Apply Rocky updates regularly and test certificate renewal with sudo certbot renew --dry-run.

FAQ

Why does Rocky Linux 8 need Remi for this Laravel version?

Rocky Linux 8’s standard PHP stream is 8.0, while Laravel 13 requires PHP 8.3 or newer. Remi provides PHP 8.3 as an EL8 module so the package names and service layout remain familiar.

Can I use an IP address instead of a domain?

You can use the IP address for a local HTTP check with the Host header shown above. A publicly resolving domain is still needed for a normal virtual host and a trusted Let’s Encrypt certificate.

Where should Laravel write files?

Only storage and bootstrap/cache should be writable by Apache. Logs, sessions, compiled views, and framework caches use those locations; application source and .env should not be writable by the web process.

Is php artisan serve suitable for production?

No. It is a development server and does not replace Apache, PHP-FPM, firewalld, or HTTPS. Use it only for temporary local testing, not for a public Rocky Linux VPS.

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

Remote Desktop Licensing Grace Period: RDS 120 Days

Next Article

How to Install Laravel PHP Framework on Rocky Linux 9

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 ✨