WordPress is a widely used content management system for hosting static and dynamic websites. It's free and open-source, and it's written in PHP with MariaDB/MySQL as the database backend. WordPress is made for small enterprises, personal blogs, and online shopping. WordPress is becoming more popular by the day, and it's a terrific way to get a website up and running quickly.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Wordpress Installation and configuration queries.
In this context, we shall look into the installation of WordPress using the LAMP stack on Rocky Linux 8.
Steps to install WordPress using the LAMP stack on Rocky Linux 8
1. Install LAMP Stack
Before starting, the LAMP stack must be installed in your system. First, let's install Apache and MariaDB with the command:
$ sudo dnf install httpd mariadb-server -y
After that, install PHP and the required PHP extensions on your system.
First, reset the default PHP 7.2 with the following command:
$ sudo dnf module reset php
Now, enable the PHP version you wish to install. Here, we will use PHP 7.4:
$ sudo dnf module enable php:7.4
Next, install PHP 7.4 with some common required extensions with the below command:
$ sudo dnf install php php-cli php-json php-gd php-mbstring php-pdo php-xml php-mysqlnd php-pecl-zip curl -y
2. Create a Database for WordPress
WordPress needs a database to store your site's configuration settings, usernames, posts, pages, and themes among others. You need to create a database and user for WordPress. To do this, start by logging into the MariaDB Database:
$ sudo mysql -u root -p
Next, create a database and user for WordPress:
CREATE DATABASE wordpressdb;
CREATE USER `wordpressuser`@`localhost` IDENTIFIED BY 'strong@password';
Next, grant all the privileges on the WordPress database to the user. Run:
GRANT ALL ON wordpressdb.* TO `wordpressuser`@`localhost`;
Then apply the changes and exit.
3. Download WordPress
At the time of this writing, the latest version of WordPress is 5.8.1 . To download it from the WordPress official site, use the following wget command:
$ wget https://wordpress.org/latest.tar.gz -O wordpress.tar.gz
Once downloaded, extract the contents of the archive file. Run:
$ tar xf wordpress.tar.gz
Next, copy the unzipped WordPress directory to the /var/www/html folder:
$ sudo cp -R wordpress /var/www/html/
Then, change the ownership of the WordPress folder to apache user and group. Execute the command:
$ sudo chown -R apache:apache /var/www/html/wordpress
Also, set the directory permissions so as to allow global users to access WordPress content. Run:
$ sudo chmod -R 775 /var/www/html/wordpress
Thereafter, configure the SELinux context for the WordPress directory:
$ sudo semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html/wordpress(/.*)?"
To apply the SELinux changes, execute the command:
$ sudo restorecon -Rv /var/www/html/wordpress
4. Configure Apache to Host WordPress
Here, we will create an Apache virtual host file for WordPress. This will point Apache to the WordPress directory on your system.
Run the following command:
$ sudo nano /etc/httpd/conf.d/wordpress.conf
Append the following lines to the file:
ServerName server-IP or FQDN
Options Indexes FollowSymLinks
Require all granted
CustomLog /var/log/httpd/wordpress_access.log common
Save and exit the file. Then, restart Apache for the changes to be applied:
$ sudo systemctl restart httpd
5. Access WordPress Installer
Now that all the configurations are done, finalize the WordPress installation using the web wizard. Open your browser and access the WordPress installer using your server's IP:
Select a language then click on Continue to proceed with the installation.
Next, provide your database details and click Submit.
Once you have connected to your database successfully, you will see the "Run the installation" page. Click on Run installation to proceed.
Thereafter, create a user and set a strong password for the Admin user. Take note of your credentials since you will need them to log in to Worpress later.
Click on install WordPress. After it is done, you will see a notification confirming that the installation was successful.
Now, log in to WordPress using your credentials.
This takes you to the WordPress dashboard. Now you can start to explore how to fully utilize WordPress for your websites.
[Need assistance in fixing WordPress issues ? We can help you. ]