How to Install Laravel on Rocky Linux 10

Install Laravel PHP framework on Rocky Linux 10 with PHP 8.3, Apache, MariaDB, Composer, SELinux, firewalld, HTTPS, and production-ready permissions.
A blue-lit server rack connects a glowing PHP application to a protected database cylinder.

To install Laravel PHP framework on Rocky Linux 10, you will build a Laravel 13 application with PHP 8.3, Apache, PHP-FPM, and MariaDB in about 20 minutes. The finished site uses the public document root, keeps SELinux enforcing, and can be protected with HTTPS.

Prerequisites

  • A fresh 64-bit Rocky Linux 10 VPS with at least 2 GB of RAM and 15 GB of available 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 is needed for a trusted Let’s Encrypt certificate, although you can perform the first HTTP check with an IP address and host header.
  • A VPSLake Linux VPS with root access if you need a server for this deployment.

The commands assume a non-root SSH account. If you are logged in as root, remove sudo. Replace every uppercase placeholder with your own value; use a long, unique database password.

Step 1: Confirm Rocky Linux 10 and install the web stack

Rocky Linux 10 supplies PHP 8.3 directly through AppStream, so this release does not need the older dnf module stream commands used on earlier Enterprise Linux versions.

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 php php-cli php-fpm php-mysqlnd php-mbstring php-xml php-bcmath php-curl php-gd php-opcache php-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 10 and the architecture should normally be x86_64. PHP should report version 8.3 or later, and each service should print active.

PRETTY_NAME="Rocky Linux 10.x (Red Quartz)"
VERSION_ID="10.x"
x86_64
PHP 8.3.x (cli) ...
active
active
active
active

The EPEL package is used later for Certbot. php-fpm listens on Rocky’s local Unix socket, /run/php-fpm/www.sock, so MariaDB and PHP do not need public network ports.

Step 2: Install Composer with checksum verification

Composer downloads Laravel and resolves its PHP dependencies; verifying the installer checksum before running it prevents a modified installer from being executed.

cd /tmp
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
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 command should show Composer 2.x. This follows Composer’s official programmatic installation procedure; the exact patch number changes as Composer releases updates.

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

Step 3: Create a private MariaDB database

Give Laravel its own database and account so the application never needs MariaDB’s administrative credentials.

sudo mariadb-secure-installation

Remove anonymous users and the test database, disallow remote root login, and reload the privilege tables when the hardening wizard asks. Then create the database and local application accounts. Replace YOUR_DB_PASSWORD inside the SQL before running it.

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';"

The two host entries make the account work with Laravel’s explicit 127.0.0.1 TCP setting as well as local socket-style connections. The check should return the new database, and you should not open port 3306 in firewalld.

Database (laravel_db)
laravel_db

Step 4: Create and configure the Laravel application

Install the project as the Apache account so Composer’s cache and the files used by PHP-FPM start with sensible ownership.

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 13 requires PHP 8.3 or newer. Its deployment documentation also requires the web server to point at public and identifies storage and bootstrap/cache as writable locations.

Edit the environment file:

sudoedit /var/www/laravelapp/.env

Keep the generated APP_KEY line for now, then set these values. Replace YOUR_DOMAIN and YOUR_DB_PASSWORD with your real domain and the same password used in MariaDB.

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

Generate the encryption key and run Laravel’s built-in migrations. The --force option is intentional 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 own application supplies seed data that you want to load.

Step 5: Point Apache and PHP-FPM at Laravel’s public directory

Serving only public keeps .env, Composer metadata, and application source outside the document root.

Replace YOUR_DOMAIN before saving this virtual host:

<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>

Save it as /etc/httpd/conf.d/zz-laravel.conf:

sudoedit /etc/httpd/conf.d/zz-laravel.conf
sudo apachectl configtest
sudo systemctl reload httpd

Syntax OK confirms Apache accepted the configuration. The zz- filename lets this site-specific PHP-FPM handler load after generic PHP configuration files.

Step 6: Apply safe ownership and SELinux labels

Only Laravel’s runtime directories need write access; the application code can remain owned by root and readable through the Apache group.

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 file-context rule lets Apache write logs, sessions, compiled views, and cache files after a relabel. Keep SELinux enforcing; the database boolean permits the local PHP process to reach MariaDB without weakening the rest of the policy.

Step 7: Open only web ports and enable HTTPS

Allow SSH, HTTP, and HTTPS in the active firewalld zone, while leaving MariaDB private to the VPS.

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 points to the VPS, request a certificate. 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
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:cache

Certbot updates Apache and redirects HTTP to HTTPS. If DNS is not ready, postpone Certbot, test over HTTP, and do not use that 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 lines, Syntax OK, a Laravel 13 version, migration statuses, and an HTTP response. After DNS and TLS are configured, also check the public endpoint:

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 public directory and PHP-FPM is executing the application.

Troubleshooting

Your requirements could not be resolved during Composer install

Laravel 13 needs PHP 8.3 or newer. Check that the server is really Rocky Linux 10 and that AppStream metadata is current; do not try dnf module enable on this release.

cat /etc/rocky-release
sudo dnf whatprovides php
php -v
sudo dnf upgrade -y

The available php package should be an EL10 AppStream build and php -v should begin with 8.3. If an extension is missing, install the matching php-* package from the Rocky repositories and rerun Composer.

SQLSTATE[HY000] [1045] Access denied

The password in .env does not match the account host Laravel selected, or Laravel is using cached settings. Test the TCP account directly, correct .env, and clear the configuration cache.

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

The query should return 1. Reset both laravel_user host entries if the database password was changed after the project was created.

403 Forbidden or Permission denied

Apache may lack group traversal permission, or SELinux labels may be wrong after files were copied into the project. Restore the labels and confirm the runtime directories are writable by Apache.

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

If ausearch reports a denial, fix the file context or boolean indicated by the event instead of disabling SELinux.

503 Service Unavailable or PHP appears as source code

PHP-FPM may be stopped, or Apache may be pointing at a socket that does not exist. Check the service and socket, then validate the virtual host.

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

The socket test should print PHP-FPM socket present and Apache should return Syntax OK. A PHP source response usually means the <FilesMatch> handler was not loaded, so inspect the error log before changing permissions.

Hardening

  • Run sudo -u apache -H php /var/www/laravelapp/artisan optimize after each production deployment so Laravel caches configuration and routes.
  • Keep .env readable only by the project owner and Apache group, and store a protected copy of the database credentials outside the web root.
  • Restrict SSH to trusted source addresses in your VPS firewall or provider firewall, and keep Rocky Linux packages updated.

FAQ

Which PHP version does Laravel 13 require?

Laravel 13 requires PHP 8.3 or newer plus extensions such as cURL, DOM, Fileinfo, Mbstring, OpenSSL, PDO, Tokenizer, and XML. Rocky Linux 10’s AppStream PHP 8.3 package satisfies that baseline.

Does Rocky Linux 10 use dnf module for PHP?

No. Rocky Linux 10 phased out the old modular AppStream workflow. Use the PHP packages exposed by AppStream and check availability with dnf whatprovides php.

Can I install Laravel without a domain name?

Yes. You can test Apache locally with the Host header shown above or use the server IP, but a domain is the practical choice for a trusted HTTPS certificate and normal virtual-host routing.

Why must Apache use Laravel’s public directory?

The project root contains .env, dependency metadata, and source files that should not be downloadable. The public directory is the intended web entry point and forwards requests to Laravel’s index.php.

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

“The Remote Computer Requires Network Level Authentication”

Next Article

Remote Desktop Licensing Grace Period: RDS 120 Days

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 ✨