Atlantic.Net Blog

How to Install Laravel PHP Framework on Rocky Linux 8

Hitesh Jethva
by Atlantic.Net (345 posts) under Dedicated Server Hosting, Tutorials
0 Comments

Laravel is an open-source PHP framework designed for web application development. It is built on various components of the Symfony framework and makes it easier to program PHP web applications. It provides a meaningful and creative syntax for simplifying common tasks such as authentication, routing, sessions, working with databases, and more. It makes development process simple for developers without compromising program capabilities.

In this post, we will show you how to install Laravel PHP Framework on Rocky Linux 8.

Prerequisites

  • A server running RockyLinux 8 on the Atlantic.Net Cloud Platform
  • A root password is configured on your server

Step 1 – Create Atlantic.Net Cloud Server

First, log in to your Atlantic.Net Cloud Server. Create a new server, choosing Rocky Linux 8 as the operating system with at least 2GB RAM. Connect to your Cloud Server via SSH and log in using the credentials highlighted at the top of the page.

Once you are logged in to your server, run the following command to update your base system with the latest available packages.

dnf update -y

Step 2 – Install Nginx, MariaDB and PHP

First, you will need to install the Nginx web server, MariaDB database server, PHP, and other PHP extensions to your server. You can install all of them using the following command:

dnf install nginx mariadb-server php php-fpm php-common php-xml php-mbstring php-json php-zip php-mysqlnd curl unzip -y

Once all the packages are installed, start and enable the Nginx, MariaDB and PHP-FPM services using the following command:

systemctl start php-fpm nginx mariadb
systemctl enable php-fpm nginx mariadb

Next, you will need to edit the PHP-FPM configuration file and change the user and group from apache to nginx.

nano /etc/php-fpm.d/www.conf

Change the following lines:

listen.owner = nginx
listen.group = nginx

Save and close the file, then edit the php.ini file:

nano /etc/php.ini

Change the following lines:

date.timezone = UTC
cgi.fix_pathinfo=1

Save and close the file, then restart the PHP-FPM service to apply the changes.

systemctl restart php-fpm

Step 3 – Install Composer

Composer is a dependency manager for PHP. It is used to install various PHP dependencies required for your project. You can install it using the following command:

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

You should get the following output:

All settings correct for using Composer
Downloading...

Composer (version 2.1.6) successfully installed to: /root/composer.phar
Use it: php composer.phar

Next, move the downloaded binary to the system path and set proper permission:

mv composer.phar /usr/local/bin/composer
chmod +x /usr/local/bin/composer

Now, verify the Composer version with the following command:

composer --version

You should get the following output:

Composer version 2.1.6 2021-08-19 17:11:08

Step 4 – Install Laravel

First, navigate to Nginx web root directory and download the latest version of Laravel using the following command:

cd /var/www/html/
composer create-project --prefer-dist laravel/laravel laravelsite

You should get the following output:

Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
Discovered Package: facade/ignition
Discovered Package: fruitcake/laravel-cors
Discovered Package: laravel/sail
Discovered Package: laravel/sanctum
Discovered Package: laravel/tinker
Discovered Package: nesbot/carbon
Discovered Package: nunomaduro/collision
Package manifest generated successfully.
76 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi
No publishable resources for tag [laravel-assets].
Publishing complete.
> @php artisan key:generate --ansi
Application key set successfully.

Next, set proper permissions and ownership to laravel directories:

chown -R nginx:nginx /var/www/html/laravelsite/storage/
chown -R nginx:nginx /var/www/html/laravelsite/bootstrap/cache/
chmod -R 0777 /var/www/html/laravelsite/storage/
chmod -R 0775 /var/www/html/laravelsite/bootstrap/cache/

Step 5 – Configure Nginx for Laravel

Now, you will need to create an Nginx virtual host configuration file to host Laravel on the Internet.

You can create it using the following command:

nano /etc/nginx/conf.d/laravel.conf

Add the following lines:

server {
       listen 80;
       server_name laravel.yourdomain.com;
       root        /var/www/html/laravelsite/public;
       index       index.php;
       charset utf-8;
       gzip on;
	gzip_types text/css application/javascript text/javascript application/x-javascript  image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon;
        location / {
        	try_files $uri $uri/ /index.php?$query_string;
        }

        location ~ \.php {
                include fastcgi.conf;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/run/php-fpm/www.sock;
        }
        location ~ /\.ht {
                deny all;
        }
}

Save and close the file then verify Nginx for any syntax error susing the following command:

nginx -t

You should get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart both the Nginx and PHP-FPM services to apply the changes:

systemctl restart php-fpm
systemctl restart nginx

You can also verify the Nginx status using the following command:

systemctl status nginx

You should see the following output:

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Drop-In: /usr/lib/systemd/system/nginx.service.d
           └─php-fpm.conf
   Active: active (running) since Tue 2021-09-14 09:36:05 UTC; 4s ago
  Process: 17025 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 17023 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 17020 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 17026 (nginx)
    Tasks: 3 (limit: 23695)
   Memory: 5.0M
   CGroup: /system.slice/nginx.service
           ├─17026 nginx: master process /usr/sbin/nginx
           ├─17027 nginx: worker process
           └─17028 nginx: worker process

Step 6 – Configure Firewall

If firewalld is installed and running in your server then you will need to allow HTTP and HTTPS service through the firewall. You can allow both services using the following command:

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https

Next, reload the firewalld to apply the changes:

firewall-cmd --reload

Step 7 – Access Laravel Dashboard

You can now access the Laravel dashboard using the URL http://laravel.yourdomain.com. You will be redirected to the Laravel default screen:
Laravel dashboard page

Conclusion

Congratulations! You have successfully installed Laravel with Nginx on Rocky Linux 8. You can now start working smoothly to create PHP web applications on this framework. Get started on dedicated hosting from Atlantic.Net.

Get A Free To Use Cloud VPS

Free Tier Includes:
G3.2GB Cloud VPS Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


Looking for a Hosting Solution?

We Provide Cloud, Dedicated, & Colocation.

  • Seven Global Data Center Locations.
  • Flexible Private, Public, & Hybrid Hosting.
  • 24x7x365 Security, Support, & Monitoring.
Contact Us Now! Med Tech Award FTC
SOC Audit HIPAA Audit HITECH Audit

Recent Posts

How to Install Python 3.10 on Rocky Linux 8
How to Install TaskBoard on Rocky Linux 8
How to Set Up Pritunl VPN Server on Rocky Linux 8
How to Install Teampass Password Manager on Rocky Linux 8
How to Install and Configure RabbitMQ Server on Rocky Linux 8

Get started with 12 months of free cloud VPS hosting

Free Tier includes:
G3.2GB Cloud VPS Server Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources