In this tutorial, we will show you how to install Laravel on AlmaLinux 8. For those of you who didn’t know, Laravel is a PHP web application framework with expressive, elegant syntax. It has a refined, simple, and readable syntax for developing modern, robust and powerful applications from the ground up. Laravel offers powerful features including, Artisan, MVC Architecture, Object-relational mapping, Template Engine, Unit-Testing, and Database Migration System.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Laravel PHP Framework on AlmaLinux 8. You can follow the same instructions for CentOS and Rocky Linux.
- A server running one of the following operating systems: AlmaLinux 8, CentOS, and Rocky Linux 8.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- SSH access to the server (or just open Terminal if you’re on a desktop).
non-root sudo useror access to the
root user. We recommend acting as a
non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.
Install Laravel on AlmaLinux 8
Step 1. First, let’s start by ensuring your system is up-to-date.
sudo dnf clean all sudo dnf install epel-release sudo dnf update
Step 2. Installing a LEMP server.
An AlmaLinux LEMP server is required. If you do not have LEMP installed, you can follow our guide here.
Step 3. Installing Composer.
Now we install Composer (dependency manager for PHP) for installing the required Laravel dependencies using the following commands:
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer chmod +x /usr/local/bin/composer
Verify the Composer version:
Step 4. Installing Laravel on AlmaLinux 8.
By default, Laravel is not available on the AlmaLinux 8 base repository. Now we run the following command to install Laravel using Composer:
cd /var/www/html/ composer create-project --prefer-dist laravel/laravel laravel
We will need to change some folders permissions:
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/
Step 5. Configure Nginx.
Now we create an Nginx configuration file for Laravel:
Add the following lines:
Save and close the file, then restart the Apache service for the changes to take effect:
sudo systemctl restart php-fpm sudo systemctl restart nginx
Step 5. Configure Firewall.
AlmaLinux comes with firewalld enabled by default, and it will block other connections from other computers that are trying to access our Laravel service. We must open the appropriate ports so that the Laravel resources can be accessed from other machines:
sudo firewall-cmd --zone=public --permanent --add-service=http sudo firewall-cmd --zone=public --permanent --add-service=https sudo firewall-cmd --reload
Step 6. Secure Nginx with Let’s Encrypt SSL Free Certificate
First, we install Certbot using the following command below:
sudo dnf install certbot python3-certbot-nginx
Then, install the SSL certificate for Apache as below:
sudo certbot --nginx -d laravel.your-domain.com
Proceed to an interactive prompt and install the certificate. If the certificate is installed you will see the below congratulatory message:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://laravel.your-domain.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=laravel.your-domain.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/laravel.your-domain.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/laravel.your-domain.com/privkey.pem Your cert will expire on 2022-04-11. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le - We were unable to subscribe you the EFF mailing list because your e-mail address appears to be invalid. You can try again later by visiting https://act.eff.org.
Step 7. Accessing Laravel Web Interface.
Once successfully installed, open your web browser and access the Laravel using the URL
https://laravel.your-domain.com. You will be redirected to the following page:
Congratulations! You have successfully installed Laravel. Thanks for using this tutorial for installing the Laravel PHP Framework on your AlmaLinux 8 system. For additional help or useful information, we recommend you check the official Laravel website.