FedoraLinuxTutorials

How To Install LEMP Stack on Fedora 35

Install LEMP Stack on Fedora 35

In this tutorial, we will show you how to install LEMP Stack on Fedora 35. For those of you who didn’t know, LEMP refers to the first letters of Linux (Operating system), Nginx Server, MariaDB (database software), and PHP principal components to build a viable general-purpose webserver.

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 LEMP Stack on a Fedora 35.

Prerequisites

  • A server running one of the following operating systems: Fedora 34 or Fedora 35.
  • It’s recommended that you use a fresh OS install to prevent any potential issues
  • A non-root sudo user or 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 LEMP Stack on Fedora 35

Step 1. Before proceeding, update your Fedora operating system to make sure all existing packages are up to date. Use this command to update the server packages:

sudo dnf upgrade
sudo dnf update

Step 2. Installing Nginx on Fedora 35.

By default, Nginx is available on Fedora 35 base repository. Then we can install Nginx with the following command:

sudo dnf install nginx

Verify the installation using this command:

nginx -v

Output:

nginx version: nginx/1.20.2

After installation is complete we need to start the Nginx server to start operating. We do that with the following command below:

sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

By default, the firewall is enabled on Fedora Linux. Now we add HTTP and HTTPS ports in the firewall using the following command:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Accessing Nginx web test page, open your web browser, and access the Nginx using the URL http://your-IP-address. You will get the following screen:

Install LEMP Stack on Fedora 35

Step 3. Installing MariaDB on Fedora 35.

By default, MariaDB is available on Fedora 35 base repository. Then we can install MariaDB with the following command below:

sudo dnf install mariadb-server

Verify installation of MariaDB:

mariadb --version

Once the installation is complete, we need to start the MariaDB server to start operating. We do that with the following command below:

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl status mariadb

By default, MariaDB is not hardened. You can secure MariaDB using the mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:

mysql_secure_installation

Configure it like this:

- Set root password? [Y/n] y
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y

To log into MariaDB, use the following command (note that it’s the same command you would use to log into a MariaDB database):

mysql -u root -p

Step 4. Installing PHP 8 on Fedora 35.

By default, PHP is not available on Fedora 35 base repository. Then we add the Remi repository  to your system with the following command below:

sudo dnf install http://rpms.remirepo.net/fedora/remi-release-35.rpm

After that, reset the PHP module and enable PHP 8 from the Remi-8.1 module using the following command:

sudo dnf module reset php
sudo dnf config-manager --set-enabled remi
sudo dnf module enable php:remi-8.1

Finally, you can install PHP 8.1 using the following command below:

sudo dnf install php-fpm php-cli php-opcache php-curl php-zip php-mysqlnd

Check installed version of PHP on your Fedora:

php -v

Optionally, if you would like to install PHP extensions using the name format php-<extension>. For example:

sudo dnf install php-gd php-devel php-common php-imagick php-xmlrpc php-json php-readline php-memcached php-xml

Step 5. Configure PHP-FPM and Nginx Access.

By default, PHP-FPM runs as the Apache user. Since we are using an Nginx web server, we need to change the following line:

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

Add the following configuration:

user = apache
group = apache

Change them to:

user = nginx
group = nginx

Save the file and restart both Nginx and PHP-FPM for the changes to come into effect:

sudo systemctl restart nginx
sudo systemctl restart php-fpm

To confirm that our web server is accessible and that PHP is working as expected, we can create a file called info.php inside the /usr/share/nginx/html directory:

sudo nano /usr/share/nginx/html/info.php

Add the following line:

<?php
phpinfo ();
?>

Save and close the file, then reload or restart your PHP-FPM service:

sudo systemctl restart php-fpm

Finally, we confirm the PHP info page at your browser IP address http://your-ip-address/info.php.

Congratulations! You have successfully installed LEMP. Thanks for using this tutorial for installing the LEMP (Nginx, MariaDB, and PHP) Stack on your Fedora 35 system. For additional help or useful information, we recommend you check the official LEMP website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button