Fedora users who learn to install LEMP on Fedora Linux gain a robust platform for hosting dynamic websites and applications. The powerful combination of Linux, Nginx, MariaDB, and PHP boasts performance, security, and flexibility. Here are compelling reasons to consider the LEMP stack on Fedora Linux:
- Cutting-Edge Technology: Fedora Linux incorporates the latest technologies, keeping your server environment up-to-date and secure.
- High Performance: Nginx, known for its high concurrency and event-driven architecture, delivers fast response times and excellent scalability.
- Solid Security: With security as a foundational principle, Fedora Linux offers a secure base for the LEMP stack, providing peace of mind for hosting web applications.
- Customizable: The LEMP stack on Fedora Linux is highly customizable, allowing you to tailor the server environment to meet your specific hosting needs.
This guide will walk you through installing and configuring LEMP on Fedora Linux and setting up a reliable and efficient platform for your web applications.
Table of Contents
Step 1: Update Fedora Linux Before LEMP Installation
Before we begin, ensuring your system is up-to-date with the latest software packages is essential. To update Fedora Linux, open a terminal window and run the following command:
sudo dnf upgrade --refresh
This will check for available updates and prompt you to confirm the installation of any updates found. Follow the on-screen prompts to complete the update process.
Step 2: Install Nginx For LEMP on Fedora
To install Nginx on Fedora Linux, open a terminal window and run the following command:
sudo dnf install nginx
This will install the latest version of Nginx and its dependencies. Once the installation is complete, you can start the Nginx service by running the following command:
sudo systemctl enable nginx --now
This command will enable the Nginx service to start automatically on system boot and start the service immediately.
To verify that Nginx is running correctly, you can check its status by running the following command:
systemctl status nginx
If Nginx is running without any errors, you should see a message indicating that the service is active and running, similar to the following output:

If no errors have occurred, move on to the next step.
Configure Nginx Firewall Rules on Fedora
Installing Nginx does not automatically configure firewall rules for standard ports 80 (HTTP) and 443 (HTTPS). You need to set appropriate rules for the ports you plan to use. Use the following commands for reference:
To open port 80 or HTTP, run the following command:
sudo firewall-cmd --permanent --zone=public --add-service=http
To open port 443 or HTTPS, run the following command:
sudo firewall-cmd --permanent --zone=public --add-service=https
After adding the rules, reload the firewall with the following command:
sudo firewall-cmd --reload
Before proceeding, open your browser and ensure you can access the Nginx access page:
http://localhost
Or
http://server-ip
Step 3: Install MariaDB For LEMP on Fedora
MariaDB is a popular open-source relational database management system. To install MariaDB on Fedora Linux, use the following command:
sudo dnf install mariadb-server mariadb
After installation, start the MariaDB service by running the following command:
sudo systemctl enable mariadb --now
To check the status of the MariaDB service, run the following command:
systemctl status mariadb

Run MariaDB Security Script on Fedora
Industry standards deem the default settings for a new MariaDB installation weak, presenting a security risk. Experts advise running the mysql_secure_installation script during installation to enhance security, thwart potential intrusions, and prevent exploits.
Execute the script with the following command:
sudo mariadb-secure-installation
Follow the prompts to configure the root password, disallow remote access from external sources, remove anonymous user accounts, and delete the test database.
As you go through the mysql_secure_installation settings, you’ll see prompts similar to the example below:
For example, the script will prompt you with various questions like:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
To secure your installation, answer “Y” to all the above questions.
If no errors have occurred, proceed to the next step.
Step 4: Install PHP For LEMP on Fedora
To install PHP on Fedora Linux, use the following command:
sudo dnf install php php-fpm php-cli php-mysqlnd
Once the installation is complete, start the PHP-FPM service with this command:
sudo systemctl enable php-fpm --now
To check the status of the PHP-FPM service, use this command:
systemctl status php-fpm

If no errors have occurred, move on to step 5.
Step 5: Configure Nginx Server Block on Fedora
To configure Nginx to work with PHP, you must make changes to the configuration file located at /etc/nginx/nginx.conf
. Add the following lines to the server block:
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
Once you have made the changes, test to ensure no errors occur in your syntax:
sudo nginx -t
Now, you will need to restart the Nginx service for the changes to take effect:
sudo systemctl restart nginx
Step 6: Configure Nginx & PHP-FPM For Fedora
On Debian/Ubuntu distributions, the “www-data” user typically handles PHP-FPM tasks. However, on the Fedora family, installations configure the PHP-FPM service to run under the “Apache” user by default, which doesn’t suit Nginx use. Therefore, you must make adjustments.
First, open the configuration file (www.conf) with the following command:
sudo nano /etc/php-fpm.d/www.conf
Substitute the (Apache) user and group with the (Nginx) user and group.
Change from:
user = apache
group = apache
Change to:
user = nginx
group = nginx
Save the file by pressing (CTRL+O), then exit (CTRL+X).
Now, you can restart your PHP-FPM service:
sudo systemctl restart php-fpm
Step 7: Create a Test PHP File
Create a test PHP file to verify that PHP works correctly with Nginx. Place this file in the Nginx web root directory, typically located at /usr/share/nginx/html/
.
sudo nano /usr/share/nginx/html/info.php
Create a file called info.php
and paste the following code:
<?php
phpinfo();
?>
Step 8: Test LEMP Installation on Fedora
After completing the installation, you can test that everything works correctly by visiting the test PHP file in a web browser. Open a web browser and visit the following URL:
http://your-server-ip/info.php
The output of your PHP test page might vary depending on your installed PHP version. For example, a PHP test page will display different outputs with different installed PHP versions.
As a final step, it’s a good idea to remove the `info.php` file you created earlier, as it can expose sensitive information about your server:
sudo rm /usr/share/nginx/html/info.php
Conclusion
In conclusion, this guide provided a comprehensive, step-by-step approach to setting up a LEMP stack on Fedora Linux. By following these instructions, even novice to intermediate users can install and configure Nginx, MariaDB, and PHP to create a solid foundation for hosting web applications. It’s crucial to adhere to security best practices and maintain your server regularly to ensure optimal performance and reliability. With this LEMP stack setup, you can confidently deploy your web projects and achieve higher visibility on Google search rankings.