Laravel is an open-source PHP web framework with expressive and elegant syntax. It is robust, easy to understand, and follows a model-view-controller design pattern. Laravel provides a set of tools and resources to build modern PHP applications. If you are looking for an open-source framework to create extensible PHP-based websites and web applications at scale, then Laravel is the best option for you.

In this post, we will show you how to install Laravel on Fedora Linux.

Step 1 – Install LEMP Server

First, install the Nginx and MariaDB server using the following command.

dnf install nginx mariadb-server 

Next, add the PHP Remi repository with the following command.

dnf install -y http://rpms.remirepo.net/fedora/remi-release-34.rpm
dnf module install php:remi-8.1

Then, install PHP with additional PHP extensions using the following command.

dnf install php php-cli php-common php-fpm php-spl php-hash php-ctype php-json php-mbstring  php-gd php-curl php-mysqli php-xml php-gmp php-xmlrpc php-bcmath php-soap php-ldap unzip -y

Once all the packages are installed, start and enable Nginx, MariaDB, and PHP-FPM services.

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

Next, edit the PHP-FPM configuration file.

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

Change the following lines.

listen.owner = nginx
listen.group = nginx

Then, edit the PHP configuration file.

nano /etc/php.ini

Change the following values.

date.timezone = UTC
cgi.fix_pathinfo=1

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

systemctl restart php-fpm

Step 2 – Install Laravel

Before starting, you will need to install PHP Composer on your server. You can install it with the following command.

wget https://getcomposer.org/installer -O composer-installer.php
php composer-installer.php --filename=composer --install-dir=/usr/local/bin

Next, change the directory to the Apache root and create a Laravel project with the following command.

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

Once the Laravel is installed, you will see the following output.

> @php artisan vendor:publish --tag=laravel-assets --ansi --force

   INFO  No publishable resources for tag [laravel-assets].  

No security vulnerability advisories found
> @php artisan key:generate --ansi

   INFO  Application key set successfully.  

Next, set proper permissions and ownership to the Laravel directory.

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 3 – Configure Nginx for Laravel

Next, create an Nginx virtual host configuration file to host Laravel on the Internet.

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 edit the Nginx main configuration file.

nano /etc/nginx/nginx.conf

Add the following lines after the line http {:

server_names_hash_bucket_size 64;

Save the file, then verify the Nginx configuration for any syntax error.

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 the Nginx and PHP-FPM services to apply the changes.

systemctl restart php-fpm
systemctl restart nginx

Step 4 – Access Laravel Site

Now, Laravel is installed with Nginx on your server. You can now access it using the URL http://laravel.yourdomain.com. You will see the Laravel page on the following screen.

Laravel dashboard

Conclusion

Congratulations! You have successfully installed the Laravel framework on Fedora Linux. You can now start developing your PHP-based web application using the Laravel framework. You can now deploy the Laravel application on dedicated server hosting from Atlantic.Net!