Skip to content

How to Install WordPress on Fedora with LAMP Stack

Install WordPress on Fedora - Featured Image

In this post, I'll show you how to install WordPress on Fedora Linux, as well as the Apache web server, the MariaDB database server, and the PHP scripting language.

WordPress is one of the most popular website content management systems. Installing WordPress locally on your computer is useful if you want to learn how to use it or if you want to test different components such as themes, fonts, layouts, and colors before applying them to your production site.

The localhost is set up with the following details:

  • Operating System: Fedora Workstation 35
  • Hostname: wpress.sysguides.kvm
  • IP Address: 192.168.122.35/24

So let's get straight to the terminal and start installing the necessary packages required to set up WordPress on localhost.

1. Install Apache HTTP Server

The Apache HTTP Server (httpd) is a free and open-source cross-platform web server software developed and maintained by the Apache Software Foundation.

Install the httpd package.

[[email protected] ~]# dnf install httpd httpd-tools

Verify the installed Apache Server version.

[[email protected] ~]# httpd -v
Server version: Apache/2.4.52 (Fedora Linux)
Server built:   Dec 22 2021 00:00:00

Open the /etc/httpd/conf/httpd.conf configuration file and set your server name. Also, in the <Directory "/var/www/html"> directive, change AllowOverride to All.

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf
...
ServerName wpress.sysguides.kvm:80
...
<Directory "/var/www/html">
    ...
    AllowOverride All
    ...
</Directory>
...

Check the configuration to see if there are any errors.

[[email protected] ~]#  apachectl configtest
Syntax OK

Open TCP port 80 (HTTP) in the local firewall.

[[email protected] ~]# firewall-cmd --add-service=http --permanent
[[email protected] ~]# firewall-cmd --reload
[[email protected] ~]# firewall-cmd --list-services
dhcpv6-client http mdns samba-client ssh

Enable and start the httpd service.

[[email protected] ~]# systemctl enable --now httpd

Set the httpd server's IP address in the /etc/hosts file.

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

192.168.122.35  wpress.sysguides.kvm

Now, open a web browser and type http://wpress.sysguides.kvm or just localhost into the address bar. You should see a webpage something like this.

Install WordPress on Fedora - Apache HTTP Webserver Test

2. Add TLS encryption to an Apache HTTP Server

By default, Apache provides the content to clients using an unencrypted HTTP connection. However, you may wish to add TLS encryption to an Apache HTTP Server as well, so that it can simulate the actual production website.

First, you must install the mod_ssl module. This module offers strong cryptography to the Apache HTTP server via the Secure Sockets Layer (SSL) and Transport Layer Security (TLS) protocols.

[[email protected] ~]# dnf install mod_ssl

Then, you need to generate a self-signed TLS certificate using the openssl command-line tool to enable HTTPS connections. Use the command below to generate your private key and public certificate. Answer questions and provide information according to your set-up. When prompted for the Common Name, provide your server name, in this example wpress.sysguides.kvm.

[[email protected] ~]# dnf install openssl

[[email protected] ~]# openssl req -x509 -newkey rsa:4096 -sha256 -days 365 -nodes \
  -out /etc/pki/tls/certs/wpress.sysguides.kvm.crt \
  -keyout /etc/pki/tls/private/wpress.sysguides.kvm.key
Generating a RSA private key
..............................................++++
......................................++++
writing new private key to '/etc/pki/tls/private/wpress.sysguides.kvm.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:IN
State or Province Name (full name) []:Karnataka
Locality Name (eg, city) [Default City]:Bengaluru
Organization Name (eg, company) [Default Company Ltd]:SysGuides
Organizational Unit Name (eg, section) []:WebDev
Common Name (eg, your name or your server's hostname) []:wpress.sysguides.kvm
Email Address []:[email protected]

Review the newly generated certificate.

[[email protected] ~]# openssl x509 -text -noout \
  -in /etc/pki/tls/certs/wpress.sysguides.kvm.crt

Open the /etc/httpd/conf.d/ssl.conf file and edit/add the following lines.

[[email protected] ~]# vim /etc/httpd/conf.d/ssl.conf
...
<VirtualHost _default_:443>
    ...
    ServerName wpress.sysguides.kvm:443
    SSLCertificateFile /etc/pki/tls/certs/wpress.sysguides.kvm.crt
    SSLCertificateKeyFile /etc/pki/tls/private/wpress.sysguides.kvm.key
    ...
</VirtualHost>

<VirtualHost *:80>
    ServerName wpress.sysguides.kvm
    Redirect permanent / https://wpress.sysguides.kvm
</VirtualHost>

In the above config file,

  • The <VirtualHost default:443> directive specifies the HTTPS server name and the location of the TLS certificate.
  • The <VirtualHost *:80> directive directs the server to redirect to HTTPS if the address is specified in HTTP.

Now open TCP port 443 (HTTPS) in the local firewall:

[[email protected] ~]# firewall-cmd --add-service=https --permanent
[[email protected] ~]# firewall-cmd --reload
[[email protected] ~]# firewall-cmd --list-services
dhcpv6-client http https mdns samba-client ssh

Restart the httpd service.

[[email protected] ~]# systemctl restart httpd

Open a web browser and now type https://wpress.sysguides.kvm in the address bar to open a web page with an HTTPS connection. Since you are using a self-signed certificate, you will receive a warning message. Don't worry; simply accept the risk and continue.

3. Install MariaDB Database Server

Now that your Apache web server is operational with TLS encryption, you need to install the MariaDB relational database management system to store your website data.

As of this writing, the MariaDB version in Fedora's default module stream is 10.5. However, I want the most recent version 10.7, so I'll change the module stream.

List the available module streams for MariaDB.

[[email protected] ~]# dnf module list mariadb
Fedora Modular 35 - x86_64
Name      Stream   Profiles                             Summary
mariadb   10.3     client, devel, galera, server [d]    MariaDB: a very fast and robust SQL database server
mariadb   10.4     client, devel, galera, server [d]    MariaDB: a very fast and robust SQL database server
mariadb   10.5     client, devel, galera, server [d]    MariaDB: a very fast and robust SQL database server

Fedora Modular 35 - x86_64 - Updates
Name      Stream   Profiles                             Summary
mariadb   10.3     client, devel, galera, server [d]    MariaDB: a very fast and robust SQL database server
mariadb   10.4     client, devel, galera, server [d]    MariaDB: a very fast and robust SQL database server
mariadb   10.5     client, devel, galera, server [d]    MariaDB: a very fast and robust SQL database server
mariadb   10.6     client, devel, galera, server        MariaDB: a very fast and robust SQL database server
mariadb   10.7     client, devel, galera, server        MariaDB: a very fast and robust SQL database server

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Enable the MariaDB 10.7 module stream.

[[email protected] ~]# dnf module enable mariadb:10.7

Now install the MariaDB database server.

[[email protected] ~]# dnf install mariadb-server

Verify the installed version.

[[email protected] ~]# mariadb -V
mariadb  Ver 15.1 Distrib 10.7.1-MariaDB, for Linux (x86_64) using  EditLine wrapper

Enable and start the mariadb service.

[[email protected] ~]# systemctl enable --now mariadb

Now run the mariadb-secure-installation shell script to secure your MariaDB installation. For more information on the script, see the MariaDB Knowledge Base page on secure installation. I'll use unix_socket authentication, a passwordless security mechanism, for the root user. The unix_socket authentication plugin allows the root user to use operating system credentials when connecting to MariaDB via the local Unix socket file.

[[email protected] ~]# mariadb-secure-installation
    Enter current password for root (enter for none):
    Switch to unix_socket authentication [Y/n] Y
    Change the root password? [Y/n] n
    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    

The installation of MariaDB is complete; the only thing left is to disable CoW on the database file when you create one. This only applies if you have a BTRFS file system.

[[email protected] ~]# systemctl stop mariadb
[[email protected]wpress ~]# chattr -R +C /var/lib/mysql/
[[email protected] ~]# systemctl start mariadb

4. Install PHP Scripting Language

The final component to be installed in the LAMP stack is PHP. PHP is a widely-used general-purpose scripting language that is especially well suited for web development.

WordPress recommends PHP 7.4 or higher. At the time of writing, PHP version 8.0 is available in the Fedora repository.

So let's install PHP 8.0 with some recommended extensions. To learn more about these extensions, refer to the page PHP Extensions.

[[email protected] ~]# dnf install php php-fpm php-mysqlnd php-opcache php-gd \
  php-xml php-mbstring php-curl php-pecl-imagick php-pecl-zip libzip

Verify the installed PHP version.

[[email protected] ~]# php -v
PHP 8.0.17 (cli) (built: Mar 15 2022 08:24:20) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.17, Copyright (c), by Zend Technologies

When you install WordPress, you'll need to download/upload images, videos, plugins, themes, and other files. By default, the post/upload size, execution/input time, and RAM limit are all set to be pretty small. As a result, you might want to consider increasing them.

Open the /etc/php.ini file and modify the following lines. The new sizes that have been set are adequate, but you can adjust them if necessary to meet your needs.

max_execution_time = 300 
max_input_time = 300 
memory_limit = 512M 
post_max_size = 256M 
upload_max_filesize = 256M

Enable and start the php-fpm service.

[[email protected] ~]# systemctl enable --now php-fpm

Restart the httpd service.

[[email protected] ~]# systemctl restart httpd

Create a small PHP script to test the configuration of PHP and its extensions.

[[email protected] ~]# echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php

Now open a web browser and type https://wpress.sysguides.kvm/phpinfo.php into the address bar to see all of the information on PHP and its extensions.

Install WordPress on Fedora - PHP Info Test

5. Install WordPress Content Management System

Now that you have installed all the components in the LAMP stack, it is time to install and configure WordPress CMS.

Go to the /var/www/html/ directory and download the most recent WordPress version.

[[email protected] ~]# cd /var/www/html/

[[email protected] /var/www/html]# wget https://www.wordpress.org/latest.tar.gz

Extract the latest.tar.gz file.

[[email protected] /var/www/html]# tar -xvf latest.tar.gz --strip-components=1
[[email protected] /var/www/html]# ls -lh
total 19M
-rw-r--r--. 1 nobody nobody  405 Feb  6  2020 index.php
-rw-r--r--. 1 root   root    18M Mar 11 06:10 latest.tar.gz
-rw-r--r--. 1 nobody nobody  20K Jan  1 05:45 license.txt
-rw-r--r--. 1 root   root     20 Mar 21 18:38 phpinfo.php
-rw-r--r--. 1 nobody nobody 7.3K Dec 28 23:08 readme.html
-rw-r--r--. 1 nobody nobody 7.0K Jan 21  2021 wp-activate.php
drwxr-xr-x. 1 nobody nobody 2.8K Mar 11 06:09 wp-admin
-rw-r--r--. 1 nobody nobody  351 Feb  6  2020 wp-blog-header.php
-rw-r--r--. 1 nobody nobody 2.3K Nov 10 04:37 wp-comments-post.php
-rw-r--r--. 1 nobody nobody 3.0K Dec 14 14:14 wp-config-sample.php
drwxr-xr-x. 1 nobody nobody   44 Mar 11 06:09 wp-content
-rw-r--r--. 1 nobody nobody 3.9K Aug  3  2021 wp-cron.php
drwxr-xr-x. 1 nobody nobody 8.9K Mar 11 06:09 wp-includes
-rw-r--r--. 1 nobody nobody 2.5K Feb  6  2020 wp-links-opml.php
-rw-r--r--. 1 nobody nobody 3.9K May 15  2021 wp-load.php
-rw-r--r--. 1 nobody nobody  47K Jan  4 14:00 wp-login.php
-rw-r--r--. 1 nobody nobody 8.4K Sep 23 02:31 wp-mail.php
-rw-r--r--. 1 nobody nobody  23K Nov 30 23:02 wp-settings.php
-rw-r--r--. 1 nobody nobody  32K Oct 25 05:53 wp-signup.php
-rw-r--r--. 1 nobody nobody 4.7K Oct  9  2020 wp-trackback.php
-rw-r--r--. 1 nobody nobody 3.2K Jun  9  2020 xmlrpc.php

You can now delete the latest.tar.gz file. You don't require it anymore.

[[email protected] /var/www/html]# rm latest.tar.gz

For some reason, the uploads directory is missing within the wp-content directory. So create it.

[[email protected] /var/www/html]# mkdir wp-content/uploads

Before you can begin configuring WordPress, you must first create a database that will be used by WordPress. So, start the MariaDB command-line shell.

[[email protected] /var/www/html]# mariadb
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.7.1-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> 

Create a database. I'm going to name it wpressdb. But you may name it whatever you like.

MariaDB [(none)]> CREATE DATABASE wpressdb;
Query OK, 1 row affected (0.002 sec)

Create a user who will have access to the wpressdb database. For the purpose of simplicity, I’ll use ‘madhudbpw‘ as the password. However, you must ensure that a strong password is used.

MariaDB [(none)]> CREATE USER 'madhu'@'wpress.sysguides.kvm'
    -> IDENTIFIED BY 'madhudbpw';
Query OK, 0 rows affected (0.268 sec)

Give user madhu full access to the wpressdb database.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON wpressdb.*
    -> TO 'madhu'@'wpress.sysguides.kvm'
    -> IDENTIFIED BY 'madhudbpw';
Query OK, 0 rows affected (0.092 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.002 sec)

Confirm that user madhu has access to the wpressdb database.

MariaDB [(none)]> SELECT Host,Db,User FROM mysql.db WHERE Db='wpressdb';
+----------------------+----------+-------+
| Host                 | Db       | User  |
+----------------------+----------+-------+
| wpress.sysguides.kvm | wpressdb | madhu |
+----------------------+----------+-------+
1 row in set (0.001 sec)

Exit the MariaDB shell.

MariaDB [(none)]> EXIT
Bye

Continue to configure WordPress. Make a copy of wp-config-sample.php as wp-config.php.

[[email protected] /var/www/html]# cp wp-config-sample.php wp-config.php

Generate WordPress salts. WordPress salts are random strings of code that comprise eight variables and are used to encrypt your login information. They add to your password to further safeguard your WordPress login credentials. This protects your credentials against brute-force assaults and other hacking tactics.

[[email protected] /var/www/html]# curl -S https://api.wordpress.org/secret-key/1.1/salt/
define('AUTH_KEY',         'Sbnq;5sI|,5^bP}s-I^-SiIE!Chxvvr%fx*)>5PB6_%0E:FtqJSZ*#GCMLF5t3r?');
define('SECURE_AUTH_KEY',  'Ex-OIFpY.N~U0d(w?z-tT;Ramd]wNU/>m#[email protected]!-eaIFH[@`sRGbfL[Y)V[FE[*J+');
define('LOGGED_IN_KEY',    '-kpGsx#jjgY5f<mV-c|HXgE}nG&)XG`;m<5.4m[~Q+*/oImiX9s*-HdS> RW&M+s');
define('NONCE_KEY',        '6:}@+8+p|>BPv.{Ckwva4mAK]vMDi5Kn$PV+)frMY=RP/s[,(+-}^NfVs(7ngV|w');
define('AUTH_SALT',        '>u*`Xf{Y_7w#ML?3~3-6LIg<TZ%p=E#?nl$x}dG0^U3Xc3~L-:,87kt^|^ZytfEH');
define('SECURE_AUTH_SALT', 'G]wR(0<{:U|]n8|DYrJBn1B[fv6j5L*F]vK.aBYIPy%m=_+`+pf)#z,j([email protected],');
define('LOGGED_IN_SALT',   '2w,&/E[qUIZmp-A6v`rfVl:B^BJ9K_L:aIyPY+v(4T~1M5[!U<L~IRsR~h}(}6pJ');
define('NONCE_SALT',       ',X*GpyfGV|i4_%|w_r+uzhEW_oruK-|CvV=QM6+UBGopXh*@e>Nn:48o;yXVS7;G');

Copy all the generated salts, open the wp-config.php file and replace this,

define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );

with this.

define('AUTH_KEY',         'Sbnq;5sI|,5^bP}s-I^-SiIE!Chxvvr%fx*)>5PB6_%0E:FtqJSZ*#GCMLF5t3r?');
define('SECURE_AUTH_KEY',  'Ex-OIFpY.N~U0d(w?z-tT;Ramd]wNU/>m#[email protected]!-eaIFH[@`sRGbfL[Y)V[FE[*J+');
define('LOGGED_IN_KEY',    '-kpGsx#jjgY5f<mV-c|HXgE}nG&)XG`;m<5.4m[~Q+*/oImiX9s*-HdS> RW&M+s');
define('NONCE_KEY',        '6:}@+8+p|>BPv.{Ckwva4mAK]vMDi5Kn$PV+)frMY=RP/s[,(+-}^NfVs(7ngV|w');
define('AUTH_SALT',        '>u*`Xf{Y_7w#ML?3~3-6LIg<TZ%p=E#?nl$x}dG0^U3Xc3~L-:,87kt^|^ZytfEH');
define('SECURE_AUTH_SALT', 'G]wR(0<{:U|]n8|DYrJBn1B[fv6j5L*F]vK.aBYIPy%m=_+`+pf)#z,j([email protected],');
define('LOGGED_IN_SALT',   '2w,&/E[qUIZmp-A6v`rfVl:B^BJ9K_L:aIyPY+v(4T~1M5[!U<L~IRsR~h}(}6pJ');
define('NONCE_SALT',       ',X*GpyfGV|i4_%|w_r+uzhEW_oruK-|CvV=QM6+UBGopXh*@e>Nn:48o;yXVS7;G');

Now, scroll to the top of the same wp-config.php file and make the modifications listed below. Replace information that is relevant to your setup.

/** The name of the database for WordPress */
define( 'DB_NAME', 'wpressdb' );

/** Database username */
define ('DB_USER', 'madhu');

/** Database password */
define( 'DB_PASSWORD', 'madhudbpw' );

/** Database hostname */
define( 'DB_HOST', 'wpress.sysguides.kvm' );

Recursively change the ownership of the /var/www/html directory to apache.

[[email protected] /var/www/html]# chown -R apache:apache *

You must provide SELinux write permission to the .htaccess file separately. The .htaccess file is a configuration file for web servers that run the Apache Web Server software.

[[email protected] /var/www/html]# semanage fcontext -a -t httpd_sys_rw_content_t /var/www/html/.htaccess

Recursively restore the default SELinux security contexts of the /var/www/html directory.

[[email protected] /var/www/html]# restorecon -RFv *

Enable httpd_can_network_connect SELinux boolean value. When enabled, this boolean allows HTTP scripts and modules from initiating a connection to a network or remote port.

[[email protected] /var/www/html]# setsebool -P httpd_can_network_connect on

Now open a web browser and type https://wpress.sysguides.kvm into the address bar. WordPress will begin the installation process.

Select your language, then press Continue to proceed.

Install WordPress on Fedora - WordPress Language

You must provide some information. Give your website a suitable title, as well as your username/password and email address. Then, to proceed, click the 'Install WordPress' button.

Install WordPress on Fedora - WordPress Info

If everything goes smoothly, you'll receive a success message. Hit the 'Log In' button.

Install WordPress on Fedora - WordPress Success

To log in, enter your username and password.

Install WordPress on Fedora - WordPress Login

You will be taken to the WordPress Dashboard screen.

Install WordPress on Fedora - WordPress Dash

Your WordPress CMS has now been successfully installed. You can now begin building your dream website.

Watch on YouTube

guest
21 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Ads Blocker Image Powered by Code Help Pro

Ad-Blocker Detected !!!

Please consider supporting me by disabling your Ad-Blocker. It really helps me to maintain this website so I can provide even better content.

To view the content, disable Ad-Blocker and refresh the page.