How to Install Laravel with LAMP on CentOS Stream 9

Laravel is a web application framework with expressive, elegant syntax. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, and caching.

Pre-requisites :

  • A system with CentOS Stream 9 installed and running.

  • root access to the system.

  • LAMP Stack installed and running, for this, you can refer to one of our guides on installing the LAMP Stack (Apache, MariaDB and PHP).

Once you're all set, we'll proceed with Laravel installation and configuration.

Disable SELinux

Next, let us disable SELinux. We are going to set SELinux to permissive. Edit this file:

vi /etc/selinux/config

Then update, Edit this line to permissive:

SELINUX=permissive

Install PHP Composer

First, Install PHP Composer as follows:

curl -sS https://getcomposer.org/installer | php

mv composer.phar /usr/local/bin/composer

chmod +x /usr/local/bin/composer

Creating Laravel Application

Let's create a Laravel application using the composer package manager:

cd /var/www

composer create-project laravel/laravel CrownCloud-Laravel-App

This will download the laravel and its dependencies on your CentOS Stream 9.

Now, Let's create an encryption key:

cd /var/www/CrownCloud-Laravel-App

php artisan key:generate

Configuring Apache vHost

Create a new apache configuration file laravel.conf for Laravel with the following command:

vi /etc/httpd/conf.d/laravel.conf

Add the following codes:

<VirtualHost *:80>
   ServerName dev.domainhere.info
   DocumentRoot /var/www/CrownCloud-Laravel-App/public
   <Directory /var/www/CrownCloud-Laravel-App>
          AllowOverride All
   </Directory>
</VirtualHost>

Change dev.domainhere.info with Your Domain Name. If you are using with IP, Please remove the entire server_name line.

Now, press the Esc key, and type in :wq! and press the Enter key to save and exit the file.

Set directory and file permissions:

chown -R apache.apache /var/www/CrownCloud-Laravel-App

chmod -R 755 /var/www/CrownCloud-Laravel-App

chmod -R 755 /var/www/CrownCloud-Laravel-App/storage

chcon -R -t httpd_sys_rw_content_t /var/www/CrownCloud-Laravel-App/storage

Access Laravel Application

Now, open the domain from your browser, this will redirect you to the Laravel landing page on your server.

http://dev.domainhere.info

Replace the dev.domainhere.info with the actual IP or domain configured on the server.

Now you have successfully installed Laravel with LAMP on your server.