How to Install WordPress with Nginx on AlmaLinux 8

WordPress is a free, open-source, and the world's most popular CMS built entirely in PHP. It is used by thousands of people around the globe for running blogs, business websites, and e-commerce stores. It has some great features including, a simple and easy-to-use admin panel, thousands of plugins, a huge community, in-depth theming, customization, and more.

In this guide, we will show you how to install WordPress with Apache and Let's Encrypt SSL on AlmaLinux 8.

Prerequisites

  • A server running AlmaLinux 8.
  • A valid domain name pointed with your server IP.
  • A root password is configured on the server.

Install LAMP Server

WordPress requires the LAMP server to be installed in your server. You can install it using the following command:

dnf install httpd mariadb-server php php-mysqlnd php-dom php-simplexml php-xml php-xmlreader php-curl php-exif php-ftp php-gd php-iconv php-json php-mbstring php-posix php-sockets php-tokenizer unzip -y

After installing the LAMP server, start the Apache and MariaDB service, and enable them to start at system reboot:

systemctl start mariadb
systemctl start httpd
systemctl enable mariadb
systemctl enable httpd

Once you are done, you can proceed to the next step.

Configure MariaDB Database

First, you will need to set the MariaDB root password and secure the MariaDB installation. You can do it using the following command:

mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none): 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
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

Once you are done, log in to MariaDB with the following command:

mysql -u root -p

Once you are log in, create a database and user for WordPress:

MariaDB [(none)]> CREATE DATABASE wordpress;
MariaDB [(none)]> CREATE USER `wordpress`@`localhost` IDENTIFIED BY 'password';

Next, grant all the privileges to the WordPress database using the command below:

MariaDB [(none)]> GRANT ALL ON wordpress.* TO `wordpress`@`localhost`;

Next, flush the privileges and exit from the MariaDB shell with the following command:

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;

Once you are done, you can proceed to the next step.

Download WordPress

Next, change the directory to the Apache web root and download the latest version of WordPress using the following command:

cd /var/www/html
wget https://wordpress.org/latest.tar.gz

Once the download is completed, extract the downloaded file with the following command:

tar -xvzf latest.tar.gz

Next, change the directory to the wordpress and rename the sample configuration file:

cd wordpress
mv wp-config-sample.php wp-config.php

Next, edit the configuration file with the following command:

nano wp-config.php

Define your database configuration as shown below:

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

/** MySQL database username */
define( 'DB_USER', 'wordpress' );

/** MySQL database password */
define( 'DB_PASSWORD', 'password' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

Save and close the file when you are finished then set proper permission to the WordPress directory:

chown -R apache:apache /var/www/html/wordpress

Once you are finished, you can proceed to the next step.

Configure Apache for WordPress

Next, you will need to create an Apache virtual host configuration file for WordPress. You can create it with the following command:

nano /etc/httpd/conf.d/wordpress.conf

Add the following lines:

<VirtualHost *:80>
   ServerAdmin [email protected]
   DocumentRoot "/var/www/html/wordpress"
   ServerName wordpress.example.com
   ErrorLog "/var/log/httpd/example.com-error_log"
   CustomLog "/var/log/httpd/example.com-access_log" combined

<Directory "/var/www/html/wordpress">
   DirectoryIndex index.html index.php
   Options FollowSymLinks
   AllowOverride All
   Require all granted
</Directory>
</VirtualHost>

Save and close the file then restart the Apache service to apply the changes:

systemctl restart httpd

You can check the status of the Apache with the following command:

systemctl status httpd

You should get the following output:

? httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Fri 2021-07-09 03:30:47 EDT; 3s ago
     Docs: man:httpd.service(8)
 Main PID: 4153 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 12524)
   Memory: 24.5M
   CGroup: /system.slice/httpd.service
           ??4153 /usr/sbin/httpd -DFOREGROUND
           ??4155 /usr/sbin/httpd -DFOREGROUND
           ??4156 /usr/sbin/httpd -DFOREGROUND
           ??4157 /usr/sbin/httpd -DFOREGROUND
           ??4158 /usr/sbin/httpd -DFOREGROUND

Jul 09 03:30:47 AlmaLinux systemd[1]: Stopped The Apache HTTP Server.
Jul 09 03:30:47 AlmaLinux systemd[1]: Starting The Apache HTTP Server...

Once you are finished, you can proceed to the next step.

Secure WordPress with Let's Encrypt SSL

Next, you will need to install the Certbot client to install the Let's Encrypt SSL for WordPress. You can install it with the following command:

dnf install epel-release -y 
dnf install certbot python3-certbot-apache

Next, obtain and install an SSL certificate for your lets domain with the following command:

certbot --apache -d wordpress.example.com

You will be asked to provide your email address and accept the term of service:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices)
 (Enter 'c' to cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, to
share your email address with the Electronic Frontier Foundation, a founding
partner of the Let's Encrypt project and the non-profit organization that
develops Certbot? We'd like to send you email about our work encrypting the web,
EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Account registered.
Requesting a certificate for wordpress.example.com
Performing the following challenges:
http-01 challenge for wordpress.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/httpd/conf.d/wordpress.conf
Redirecting all traffic on port 80 to ssl in /etc/httpd/conf.d/wordpress.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://wordpress.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: [email protected]).


IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/wordpress.example.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/wordpress.example.com/privkey.pem
   Your certificate will expire on 2022-02-09. 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"
 - 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

Configure Firewall

Next, you will need to allow ports 80 and 443 through the firewalld. You can allow them with the following command:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https

Next, reload the firewalld to apply the changes:

firewall-cmd --reload

Once you are finished, you can proceed to the next step.

Access WordPress Dashboard

Next, open your web browser and access the WordPress admin panel using the URL https://wordpress.example.com. You will be redirected to the following page:

Choose language

Select your language and click on the Continue. You should see the WordPress site configuration page:

Site details

Provide your site information and click on Install WordPress button. Once the installation has been completed, you should see the following page:

WordPress installation successful

Click on the Login button. You will be redirected to the WordPress login page:

Log into WordPress

Provide your admin username, password and click on the Login button. You should see the WordPress dashboard on the following page:

WordPress Dashboard

Conclusion

Congratulations! you have successfully installed WordPress with Apache and Let's Encrypt SSL on AlmaLinux 8. You can now create your own website easily using WordPress. Feel free to ask me if you have any questions.

Share this page:

Suggested articles

1 Comment(s)

Add comment

Comments

By: Jacky at: 2021-07-17 03:15:20

The howto is for apache http server and not nginx.  The title is misleading.