
A Step-by-Step Guide to Installing WordPress on Fedora with Nginx
Powering a significant portion of the web, WordPress is a world-class content management system (CMS). When paired with a high-performance Nginx web server on a cutting-edge Linux distribution like Fedora, you get a powerful, secure, and lightning-fast platform for your website or blog. This combination, known as a LEMP stack (Linux, Nginx, MySQL/MariaDB, PHP), is a popular choice for developers and system administrators seeking optimal performance.
This comprehensive guide will walk you through every step of installing WordPress on a Fedora system using the Nginx web server, MariaDB for the database, and PHP-FPM.
Prerequisites
Before we begin, ensure you have the following:
- A system running a recent version of Fedora.
- Access to a user account with sudo or root privileges.
- A domain name pointed to your server’s IP address (optional, but recommended for a live site).
Step 1: Install and Configure the Nginx Web Server
Nginx is a lightweight, high-performance web server that will serve your WordPress site’s pages to visitors.
First, install the Nginx package using Fedora’s DNF package manager:
sudo dnf install nginx
Once the installation is complete, you need to start and enable the Nginx service. Enabling it ensures that Nginx automatically starts whenever the server reboots.
sudo systemctl start nginx
sudo systemctl enable nginx
To verify that Nginx is running correctly, you can check its status:
sudo systemctl status nginx
Next, you must configure the system’s firewall to allow web traffic. Add rules to permit both standard HTTP (port 80) and secure HTTPS (port 443) traffic.
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
You can now test your Nginx installation by navigating to your server’s IP address or domain name in a web browser. You should see the default Nginx welcome page.
Step 2: Install and Secure the MariaDB Database
WordPress uses a database to store all of your site’s content, including posts, pages, user information, and settings. We will use MariaDB, a popular and fully compatible open-source fork of MySQL.
Install MariaDB and its server package:
sudo dnf install mariadb-server mariadb
After installation, start and enable the MariaDB service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
With the database server running, it is critically important to run the included security script. This script will guide you through removing insecure default settings, setting a root password, and locking down access to your database.
sudo mysql_secure_installation
Follow the on-screen prompts. It’s highly recommended that you set a strong root password and answer “Y” (yes) to all subsequent questions.
Create a Dedicated WordPress Database
For security and management purposes, WordPress should have its own dedicated database and user.
Log in to the MariaDB prompt as the root user:
sudo mysql -u root -p
Enter the root password you just created.
Now, run the following commands to create the database, a new user, and grant that user the necessary privileges. Replace wordpress_db, wp_user, and 'your_strong_password' with your own secure values.
CREATE DATABASE wordpress_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_strong_password';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Make a note of these credentials, as you will need them later to configure WordPress.
Step 3: Install and Configure PHP
WordPress is built on PHP, so we need to install it along with several extensions that WordPress requires to function correctly. We’ll install PHP-FPM (FastCGI Process Manager), which is the standard way to handle PHP processing with Nginx.
sudo dnf install php php-fpm php-mysqlnd php-gd php-xml php-mbstring php-json
Next, we need to make a small but crucial configuration change. By default, PHP-FPM runs as the apache user. Since we are using Nginx, we must change the user and group to nginx.
Open the configuration file with a text editor like nano:
sudo nano /etc/php-fpm.d/www.conf
Find the user and group directives and change them from apache to nginx:
...
user = nginx
...
group = nginx
...
Save and close the file. Now, start and enable the PHP-FPM service:
sudo systemctl start php-fpm
sudo systemctl enable php-fpm
Step 4: Download and Prepare WordPress
With the server components in place, we can now download and set up the WordPress files.
First, navigate to the /tmp directory, download the latest version of WordPress, and extract it.
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
Next, move the extracted WordPress files into the Nginx web root directory. We’ll place it in /usr/share/nginx/html/wordpress.
sudo mv wordpress /usr/share/nginx/html/
For WordPress to work correctly, Nginx needs to have ownership and proper permissions for these files and directories.
sudo chown -R nginx:nginx /usr/share/nginx/html/wordpress
Fedora uses SELinux for enhanced security. We must update the SELinux security context to allow Nginx to write to the WordPress directory. This is essential for uploading media and installing themes or plugins.
sudo semanage fcontext -a -t httpd_sys_rw_content_t "/usr/share/nginx/html/wordpress(/.*)?"
sudo restorecon -Rv /usr/share/nginx/html/wordpress
Step 5: Configure Nginx to Serve WordPress
The final server configuration step is to tell Nginx how to serve our WordPress site. We will create a new server block configuration file.
sudo nano /etc/nginx/conf.d/wordpress.conf
Paste the following configuration into the file. Be sure to replace your_domain.com with your actual domain name or server IP address.
server {
listen 80;
server_name your_domain.com www.your_domain.com;
root /usr/share/nginx/html/wordpress;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass unix:/run/php-fpm/www.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
deny all;
}
}
This configuration tells Nginx where to find your website’s files and how to pass PHP files to PHP-FPM for processing.
After saving the file, test your Nginx configuration for syntax errors:
sudo nginx -t
If you see a “syntax is ok” message, you can safely restart the Nginx service to apply the changes.
sudo systemctl restart nginx
Step 6: Finalize Installation Through the Web Browser
The server-side work is complete! Now you can finish the WordPress installation through its user-friendly web interface.
Navigate to your domain or IP address in your web browser. You will be greeted by the WordPress setup screen.
- Select your language and click Continue.
- On the next screen, you will be prompted for your database information. Click Let’s go!.
- Enter the database name, username, and password you created in Step 2.
- Leave the Database Host as
localhostand the Table Prefix aswp_. - Click Submit. If the credentials are correct, you will see a success message.
- Click Run the installation.
- Finally, fill in your Site Title, create an Administrator Username and a strong password, enter your email address, and click Install WordPress.
Congratulations! You have successfully installed a high-performance WordPress site on your Fedora server with Nginx. You can now log in to your WordPress dashboard and start building your website.
Source: https://kifarunix.com/install-wordpress-5-with-nginx-on-fedora-30-fedora-29/


