To install Laravel PHP framework on Rocky Linux 9, you will build a Laravel 13 application with PHP 8.4, Apache, MariaDB, and Composer in about 20 minutes. The result serves Laravel from its protected public directory, keeps SELinux enforcing, and is ready for HTTPS.
Prerequisites
- A fresh 64-bit Rocky Linux 9 VPS with at least 2 GB of RAM and 15 GB of free disk space.
- SSH access as
root, or a normal account with workingsudoprivileges and outbound HTTPS access. - A public IP address and a DNS record such as
YOUR_DOMAINpointing to it before you request TLS. - A VPSLake Linux VPS with root access if you need a Rocky Linux server for this stack.
These commands assume a sudo-enabled 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 9 and install PHP 8.4
Rocky Linux 9 can provide PHP 8.3 through AppStream, but this setup selects Remi’s PHP 8.4 module for smoother current Laravel 13 dependency resolution and installs the web stack in one pass.
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 curl git unzip policycoreutils-python-utils
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf module reset php -y
sudo dnf module install php:remi-8.4 -y
sudo dnf install -y php php-cli php-fpm php-mysqlnd php-mbstring php-xml php-bcmath php-curl php-gd php-intl php-opcache php-process 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 9 and x86_64 on a normal VPS. PHP should begin with 8.4, followed by four active lines. PHP 8.4 also avoids the PHP 8.3 dependency edge cases that can appear with newer Laravel 13 packages.
PRETTY_NAME="Rocky Linux 9.x (Blue Onyx)"
VERSION_ID="9.x"
x86_64
PHP 8.4.x (cli) ...
active
active
active
active
Step 2: Create a private MariaDB database
Laravel should use a dedicated database account, not MariaDB’s administrative login, so a web-application compromise does not grant server-wide database access.
sudo mariadb-secure-installation
When the wizard asks, remove anonymous users and the test database, disallow remote root login, and reload the privilege tables. Local socket authentication for the database administrator is suitable here.
Create the database and matching local accounts. Replace YOUR_DB_PASSWORD with a long, unique password before submitting this block.
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';"
The final command should print laravel_app. Both account hosts are local; do not open MariaDB’s port 3306 in firewalld.
Database (laravel_app)
laravel_app
Step 3: Install Composer with checksum verification
Composer resolves Laravel’s PHP dependencies, and checking its installer hash before execution prevents a changed download from being run as root.
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 last line should report Composer 2.x. This is Composer’s official programmatic installation method; its published checksum changes when the installer changes.
Composer version 2.x.x 20xx-xx-xx
Step 4: Create the Laravel project and configure its environment
Installing the project as Apache’s account keeps the generated Composer cache and application files accessible to PHP-FPM without making the web process run as root. Laravel’s deployment documentation also requires the web server to expose only the application’s public directory.
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 environment file:
sudoedit /var/www/laravelapp/.env
Keep the generated APP_KEY line for now, then set these values. Use the same database password from Step 2.
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 encryption key and run the initial migrations. --force is required because this is a non-interactive production setup.
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 Application key set successfully followed by completed migration lines. Do not run db:seed unless your application has seed data you actually want to load.
Step 5: Configure Apache to serve Laravel’s public directory
Pointing Apache at public keeps .env, Composer metadata, and the rest of the application source outside the document root.
Create /etc/httpd/conf.d/zz-laravel.conf with sudoedit:
sudoedit /etc/httpd/conf.d/zz-laravel.conf
Replace YOUR_DOMAIN before saving:
<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>
Check the syntax and reload Apache:
sudo apachectl configtest
sudo systemctl reload httpd
Syntax OK confirms that Apache accepted the virtual host. PHP-FPM’s local Unix socket avoids exposing a separate PHP service port.
Step 6: Set permissions while keeping SELinux enforcing
Laravel only needs write access to storage and bootstrap/cache; the application code can remain owned by root and readable by Apache.
sudo semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/laravelapp/(storage|bootstrap/cache)(/.*)?'
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 restorecon -Rv /var/www/laravelapp
sudo setsebool -P httpd_can_network_connect_db on
The persistent SELinux file-context rule survives a later relabel, and the boolean permits the PHP web process to reach local MariaDB. Do not switch SELinux to permissive mode.
Step 7: Open web ports and enable HTTPS
Allow only SSH and web traffic in the active firewalld zone, leaving the database bound to local access.
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 this VPS, install Certbot and let it add the Apache TLS configuration. Replace YOUR_EMAIL with an address for 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
Edit .env again and change APP_URL to https://YOUR_DOMAIN, then cache the production configuration:
sudoedit /var/www/laravelapp/.env
sudo -u apache -H php /var/www/laravelapp/artisan config:cache
If DNS is not ready, postpone Certbot and test over HTTP. Do not use an unencrypted 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. After TLS is enabled, check the public URL too:
curl -fsSI https://YOUR_DOMAIN/
active
active
active
active
Syntax OK
Laravel Framework 13.x
HTTP/1.1 200 OK
Open https://YOUR_DOMAIN in a browser. The default Laravel page confirms that Apache is using the intended directory and PHP-FPM is executing the framework.
Troubleshooting
Your requirements could not be resolved or PHP is below 8.4
The Rocky module may still be on its default stream, or an older PHP installation is first in PATH. Switch the stream and restart PHP-FPM, then repeat the Composer command.
sudo dnf module reset php -y
sudo dnf module install php:remi-8.4 -y
sudo systemctl restart php-fpm
php -v
SQLSTATE[HY000] [1045] Access denied
Laravel’s DB_PASSWORD must match the account created for the exact host in DB_HOST. Reset both local account entries, then clear Laravel’s cached configuration.
sudo mariadb -e "ALTER USER 'laravel_app'@'127.0.0.1' IDENTIFIED BY 'YOUR_DB_PASSWORD';"
sudo -u apache -H php /var/www/laravelapp/artisan config:clear
sudo -u apache -H php /var/www/laravelapp/artisan migrate:status
403 Forbidden or Permission denied
Apache may have lost the Rocky Linux security labels, or the runtime directories may not be writable by Apache. Reapply the labels and inspect the error log.
sudo restorecon -Rv /var/www/laravelapp
sudo chown -R apache:apache /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache
sudo tail -n 30 /var/log/httpd/laravel-error.log
503 Service Unavailable or PHP appears as source code
PHP-FPM is stopped or Apache’s handler points at a missing socket. Confirm the service and socket, then reload Apache.
sudo systemctl restart php-fpm
sudo ls -l /run/php-fpm/www.sock
sudo apachectl configtest
sudo systemctl reload httpd
Hardening
- Keep
APP_DEBUG=falseand runphp artisan config:cacheafter environment changes. - Restrict SSH in firewalld to your administration network when possible, and use SSH keys instead of password authentication.
- Back up the database and
.envsecurely; never commit.envor expose the project root through another Apache virtual host.
FAQ
Which PHP version does Laravel 13 need?
Laravel 13 requires PHP 8.3 or newer. This guide uses PHP 8.4 because it is available for Enterprise Linux 9 through Remi and gives current Laravel dependencies more room to resolve.
Can I test the site before the domain is ready?
Yes. Keep the temporary APP_URL value, test locally with the curl command from the verification section, or map YOUR_DOMAIN to the VPS IP in your workstation’s hosts file. Let’s Encrypt still requires a real DNS name for a trusted certificate.
Why must Apache use /public as the document root?
Laravel’s public directory contains the front controller and is designed to be web-accessible. The project root also contains .env and dependency files that should never be downloadable.
Can Laravel use PostgreSQL or SQLite instead of MariaDB?
Yes. Laravel supports several database drivers, but each needs its PHP extension and matching DB_* values. Change the environment configuration and verify the connection before running your application’s migrations.