How to Install Laravel and Enable SSL on AlmaLinux 8

Linux Topic

October 27, 2022 by Ashley

How to Install Laravel and Enable SSL on AlmaLinux 8

Laravel is a free and open-source web framework. Installing Laravel on AlmaLinux enables you to build PHP-based web applications easily and fast. This lightweight and popular provides expressive elegant syntax and brilliant features. As a developer, you can use Laravel to simplify web application development for your applications. It is possible to install Laravel on AlmaLinux 8 with the command terminal method. Once you install Laravel, you will experience dependency injection, an expressive database abstraction layer, queues, and scheduled jobs, MVC Architecture, and unit and integration testing. To offer the mentioned powerful features, Laravel provides an Artisan command-line interface to perform operations for your applications.

In this article, you will learn How to Install Laravel and Enable SSL on AlmaLinux 8. Buying a Linux VPS is the first step to reaching out for all these benefits.

Tutorial Install Laravel on AlmaLinux 8

Laravel is a free, open-source, and new generation of PHP framework. It is not a big deal if you are new to PHP web frameworks. PHP is almost old and that’s why Laravel comes into play. It is a framework that grows with you. While so many tools exist to build a web application, it is said that Laravel is the best choice for building modern and full-stack web applications.

In a few easy steps, you will learn the way you can install the popular Laravel on AlmaLinux to be more productive. But firstly, provide what you need to start the installation process. Find them below.

Prerequisites to Install Laravel on AlmaLinux 8

To go through the required steps of installing Laravel on AlmaLinux, you need to consider some Prerequisites.

  • A user account with administrative privileges. Log in to your server as a root user and set a basic firewall. PHP >= 7.2.5
  • A server running Alma Linux 8.
  • LEMP must be installed on your server.
  • RedHat Linux such as Rocky or AlmaLinux. For this, you can refer to the Install Rocky Linux OS article.
  • A valid domain name pointing to your server’s IP address.

7 Steps to Install Laravel and Enable SSL on AlmaLinux 8

Once you provided all the required options above, you are ready to pass the steps of this guide to install Laravel on your AlmaLinux successfully. Let’s get started.

Step 1: Install the latest PHP on your system

If you do not have the PHP language installed on your running system, you need to get this since Laravel is a PHP-based framework. Use the command below to install PHP 8. x or skip this step if you have already done it.

sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-8.rpm
sudo dnf update
sudo dnf module reset php
sudo dnf module enable php:remi-8.0
sudo apt install php

And to install unzip and curl, run:

sudo dnf install unzip curl

Step 2: Install required Packages and Additional PHP extensions

In the first step, you need to install the required packages and some PHP extensions on your server. To install them on AlmaLinux 8, run the command below.

dnf install php-common php-xml php-mbstring php-json php-zip curl unzip -y

Now, pass the following command to edit the PHP-FPM configuration file depending on your favorite editor.

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

OR

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

Then, change the following lines:

listen.owner = nginx
listen.group = nginx

You can save and close the file when you are done. Now, you can edit the PHP configuration file. To change the default values type:

vi /etc/php.ini

OR

nano /etc/php.ini

And finally, change the lines below by setting your own time zone.

date.timezone = Europe/London
cgi.fix_pathinfo=1

When you’re all set, save and close the file to proceed to the next step.

Step 3: Install PHP Composer

As we mentioned, installing Laravel on AlmaLinux 8 is easy even for users who do not have that high technical knowledge. To make this claim come true, we offer the easiest way to install Laravel which is using the Composer. This application-level package manager helps you to download, manage, and install the Laravel project with all its dependencies of PHP software and required libraries.
Run the command below to install Laravel by using Composer.

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

The output will be something like this:

Install composer output

Then, run the commands below to move the Composer binary to the system path and then set the correct permission for it.

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

And finally, to check the version of your Composer installed, type:

composer --version

Here, you must see the version, date, and time of the Composer installation.

Step 4: Install Laravel on AlmaLinux 8

If you have passed the recent 3 steps successfully, you can start installing Laravel on your server.  So, use the following command to switch to the Nginx web root directory.

cd /var/www/html/

Use the Composer to install Laravel by running the command below.

composer create-project --prefer-dist laravel/laravel laravel

Once you are done, the following output will appear.

Install Laravel on AlmaLinux 8

Now, you need to set proper ownership and permissions to Laravel:

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

Also, to check whether the PHP framework is working on your system or not, run the following command.

laravel

If the version of Laravel is displayed in green color, it means your installation is successful.

Step 5: Creating an Nginx Virtual Host for Laravel

In step 5, you must create an Nginx configuration file for Laravel. You can use vi or nano. So, run:

vi /etc/nginx/conf.d/laravel.conf

OR

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

Now, add the following lines to the file, and do not forget to replace the ‘’laravel.exampledomain.com’’ with your own as your domain name.

Output:

Create an Nginx Virtual Host for Laravel 1

 

Save and close the file when you are done. Then, you just need to verify the Laravel for any configuration error:

nginx -t

To verify the Nginx status, you can use the command below.

systemctl status nginx

Then, you must restart the Nginx and PHP-FPM services to apply the changes. So, type:

# systemctl restart php-fpm
# systemctl restart nginx

Finally, you must view the ”test is successful” in the output. To let this step be complete, allow ports 80 and 443 through the firewall. Use the following commands to do this.

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

Finally, run the command below to reload the firewall and apply the new rules.

firewall-cmd --reload

Step 6: Access Laravel Web UI

In this step, you will see how you can access your Laravel through the web interface. To do this, open your favorite web browser and type your domain name (http://laravel.exampledomain.com). Then, you will see the Laravel default page as shown below.

Also, you can use the following command to view the following screen.

https:// laravel.exampledomain.com

Access Laravel Web UI

Step 7: Enable SSL on AlmaLinux 8

The time has come to enable the SSL on the Laravel website and secure the connection. You are highly recommended to do this step well. As you might know, Let’s Encrypt provides a free SSL to obtain, renew, and manage SSL/TLS certificates for your domain.

Firstly, you need to install the Cerbot client. So, run:

dnf install epel-release -y
dnf install certbot -y

Now, to download Let’s Encrypt SSL for your Laravel domain, you can use the following command.

certbot --nginx -d <span style="color: #0000ff;">laravel.exampledomain.com</span>

Keep in mind to replace ‘’laravel.exampledomain.com’’ with your domain name. As shown below, you will be asked for your valid email and accept the term of service.

Output:

Enable SSL on Laravel Website

Then, select if you prefer to redirect HTTP traffic to HTTPS or not.

Output:

Secure Laravel with Let’s Encrypt on AlmaLinux 8

To start the process, type 2 and press Enter.

If you view such an output like the above, it means that your Laravel website is secured with Let’s Encrypt SSL. From now on, you will be able to access the website of Laravel securely if you use the URL of https://laravel.exampledomain.com.

https:// laravel.exampledomain.com

Conclusion

In this article, you learned How to Install Laravel and Enable SSL on AlmaLinux 8. There are 6 required steps to take the Laravel installation on AlmaLinux and in the 7th final step, the SSL will be enabled on the AlmaLinux 8. So, you are ready to develop PHP-based applications using the Laravel framework. If you encounter any problems, please do not hesitate to contact us. Our technical support team will try their best to solve your problems.

​ ​ ​ ​

About the Author Ashley

Leave a Reply

Your email address will not be published. Required fields are marked *