Last Updated on 2 weeks by Sachin G
This blog article guides you through installing the Laravel PHP framework on CentOS, RHEL, and Ubuntu Linux servers. It covers installing prerequisites like Apache, PHP, and Composer, setting up the Laravel environment, and configuring the Apache virtual host for your Laravel project deployment.
Why Laravel? And Why Linux?
Laravel is a PHP-based web application framework that manages its dependencies through Composer. When combined with a Linux server — whether it’s Ubuntu, CentOS Stream, or RHEL (Red Hat Enterprise Linux) — you unlock flexibility, speed, and control. It will be downloaded to the system and can be archived as a Phar file in the local project path, or you can use it globally through/usr/local/bin. For Windows Composer, there is its own installer. The use of the Laravel framework enables developers to write the best code.
As someone who’s deployed Laravel apps in production on all three distros, I’ve learned the small differences matter — and permissions will always trip you up if you don’t set them right.
Laravel Requirements on a Linux Server
Before diving into commands, let’s cover the Laravel prerequisites on Linux:
- PHP (v8.1 or higher recommended)
- Composer (for managing Laravel and PHP packages)
- A web server (usually Apache)
- A database (like MySQL)
- PHP extensions:
bcmath
,ctype
,fileinfo
,json
,mbstring
,openssl
,pdo
,tokenizer
,xml
Tip: Use
php -m
to confirm required PHP modules are installed.
Step-by-Step Laravel Installation on Ubuntu 22.04
Update & Install Packages
Keep your server up-to-date for stability and security.
sudo apt update && sudo apt upgrade -y
sudo apt install -y php php-cli php-mbstring php-bcmath php-json php-xml php-mysql php-curl php-mysql apache2 mysql-server composer git -y
Composer Install Laravel
Composer is a key part of Laravel PHP framework installation commands
composer global require laravel/installer
Make sure to add Composer’s global bin directory to your $PATH
.
Create a New Laravel Project
laravel new myapp
Or if you want to use Composer directly:
composer create-project --prefer-dist laravel/laravel myapp
Configure Apache Virtual Host Laravel
sudo nano /etc/apache2/sites-available/myapp.conf
ServerName myapp.local
DocumentRoot /var/www/html/myapp/public
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot /var/www/html/myapp/public
<Directory /var/www/html/myapp>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
then:
sudo a2ensite myapp.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
Secure Laravel Installation on RHEL-Based Systems
Installing Laravel on RHEL 8 or CentOS Stream 9 is slightly different. SELinux, firewall, and repository quirks can slow you down.
Common Hurdles I’ve Faced:
SELinux blocking public access to Laravel routes
Firewall rules not allowing HTTP/HTTPS
- Missing EPEL repos for PHP packages
- Firewall rules not allowing HTTP/HTTPS
- Missing EPEL repos for PHP packages
Laravel Installation Summary for RHEL :
sudo dnf install epel-release
sudo dnf module enable php:8.1
sudo dnf install php php-cli php-mbstring php-xml php-bcmath php-curl php-mysqlnd composer httpd git unzip -y
Start Apache and enable on boot:
sudo systemctl start httpd
sudo systemctl enable httpd
Then proceed with Composer to install Laravel just like Ubuntu.
Laravel Project Directory Permissions
This step is often overlooked and causes 500 Internal Server Errors.
sudo chown -R apache:apache /var/www/html/myapp
sudo chmod -R 775 /var/www/html/myapp/storage
sudo chmod -R 775 /var/www/html/myapp/bootstrap/cache
For Ubuntu, replace apache
with www-data
.
Enable Laravel .env on Linux
Laravel relies heavily on the .env
file for environment configuration. Make sure it’s copied from .env.example
and permissions are set:
cp .env.example .env
php artisan key:generate
Laravel with MySQL Setup
Create a new MySQL database and user:
sudo mysql -u root -p
CREATE DATABASE myapp_db;
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'securepassword';
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;
Update .env
file:
DB_DATABASE=myapp_db
DB_USERNAME=myapp_user
DB_PASSWORD=securepassword
Run Laravel migration:
php artisan migrate
Real-World Use Case: Deploying a Laravel CRM on RHEL
One of my recent projects involved deploying a custom Laravel CRM on RHEL 8 with Composer. SELinux blocked /storage
access, so I had to:
sudo chcon -R -t httpd_sys_rw_content_t /var/www/html/myapp/storage
Without that, file uploads were silently failing — no logs, no errors. Lesson learned: SELinux isn’t broken, but it’s strict.
FAQs
Use dnf
to install PHP + extensions, install Composer, and run composer create-project laravel/laravel myproject
.
PHP 8.1+, Composer, required PHP extensions, database (MySQL/PostgreSQL), and Apache/Nginx.
Both work. Apache is simpler for beginners; Nginx performs better for high-traffic apps.
Yes, but you’ll need sudo
privileges for PHP/Composer installation and web server configuration.
Composer manages all Laravel dependencies, making framework updates and package installation seamless.
Installing Laravel on Linux servers (CentOS Stream, RHEL, Ubuntu) might look complex at first, but once you master the PHP extensions, Composer installation, and Apache/Nginx configuration, it becomes second nature.
I’m Sachin Gupta — a freelance IT support specialist and founder of techtransit.org. I’m certified in Linux, Ansible, OpenShift (Red Hat), cPanel, and ITIL, with over 15 years of hands-on experience. I create beginner-friendly Linux tutorials, help with Ansible automation, and offer IT support on platforms like Upwork, Freelancer, and PeoplePerHour. Follow Tech Transit for practical tips, hosting guides, and real-world Linux expertise!