Tech News

How To Install WordPress with OpenLiteSpeed on CentOS/RHEL 7/8

This tutorial will show you how to install WordPress with OpenLiteSpeed web server on a CentOS or RHEL 8 machine. These instruction can also be applied if you are running an earlier version of CentOS or RHEL 7.

Note: With CentOS 8 release, yum command has been replaced with dnf and in near future yum package manager will be discontinued. It is now recommended to use dnf for installing packages but if you still wish to use yum you can use it.


You will need one CentOS or RHEL 8 (physical or virtual) machine with minimal installed having sudo non-root user privileges.

Disabling SELinux

You should change from SELINUX=enforcing to SELINUX=disabled in /etc/selinux/config file for smooth installation:
sudo vi /etc/selinux/config

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
# SELINUXTYPE= can take one of these three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
Save and close file when you are finished.

Now reboot your machine to take changes into effect:
sudo reboot

Adding EPEL Repository

It is always recommended to install extra packages for enterprise Linux repository before proceeding to install packages using yum package manager:
sudo yum -y install

sudo ARCH=$( /bin/arch )

sudo dnf config-manager --set-enabled PowerTools

Installing Dependencies

You will need to install following required dependencies prior to install openlitespeed web server:
sudo dnf -y install openssl openssl-libs libargon2 wget tar zip unzip php python36

Installing OpenLiteSpeed

OpenLiteSpeed provides a repository for its software you can use to download and install the server with CentOS’s standard yum command.
sudo rpm --import

sudo dnf -y install

sudo dnf -y install openlitespeed lsphp73

Setting the Administrative Password

By default, the password is set to 123456, so you should change this immediately. You can do this by running a script provided by OpenLiteSpeed:
sudo /usr/local/lsws/admin/misc/

Verifying Server Status

OpenLiteSpeed should have started automatically after it was installed. You can verify this using the lswsctrl command:
sudo /usr/local/lsws/bin/lswsctrl status

litespeed is running with PID 9776.
If it is not started, you can start the server using lswsctrl:
sudo /usr/local/lsws/bin/lswsctrl start

Adding Firewall Rules

Now you need to allow these ports from firewall to access OpenLiteSpeed web interface.
sudo firewall-cmd --zone=public --permanent --add-port=8088/tcp
sudo firewall-cmd --zone=public --permanent --add-port=7080/tcp
sudo firewall-cmd --reload

Installing MySQL

You can install MySQL database using the following command:
sudo dnf -y install mysql-server

Securing MySQL

After fresh installation of MySQL database, you will need to run the following mysql_secure_installation script and follow the instruction to make it secure:
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...

 - Removing privileges on test database...

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done!

Creating Database for WordPress

WordPress uses MySQL to manage and store site and user information. We already have MySQL installed, but we need to create a database and a user for WordPress to use.

Log in to the root MySQL account like below
sudo mysql -u root -p
Then enter your root user’s password when prompted.

At this point, we will create and name this database and user wordpress to keep things simple and easy to remember, but you can name it whatever you’d like.

From the MySQL prompt, create a database and a user with the following commands:
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';
You’re done setting up your MySQL installation to work with WordPress.

Installing Required PHP Extensions

To install these required PHP extensions commonly used with WordPress, execute the following command:
sudo dnf -y install lsphp73-common lsphp73-curl lsphp73-imagick lsphp73-imap lsphp73-json lsphp73-memcached lsphp73-mysqlnd lsphp73-opcache lsphp73-redis

Downloading WordPress

For security reasons, it is recommended that you download the latest version of WordPress directly from their website.

Change into user home directory and then download the latest release by typing:
cd ~/Downloads
curl -O
tar xzvf latest.tar.gz
Now add a dummy .htaccess file so that it will be available for WordPress to use later:
touch ~/Downloads/wordpress/.htaccess
Next, copy over the sample configuration file to the filename that WordPress actually reads:
cp ~/Downloads/wordpress/wp-config-sample.php ~/Downloads/wordpress/wp-config.php
Also, create the upgrade directory so that WordPress won’t run into permissions issues when trying to do this on its own following an update to its software:
mkdir ~/Downloads/wordpress/wp-content/upgrade
Then, copy the entire contents of the directory into your document root. OpenLiteSpeed comes with a default virtual host named Example located in the /usr/local/lsws/ directory. The document root for the Example virtual host is the html sub-directory:
sudo cp -a ~/Downloads/wordpress/. /usr/local/lsws/Example/html/wordpress
Notice that this command includes a dot at the end of the source directory to indicate that everything within the directory should be copied, including hidden files (like the .htaccess file you created):

You’ve successfully installed WordPress onto your web server and performed some of the initial configuration steps.

Configuring WordPress

Before you begin with the web-based setup process for WordPress, you need to adjust some items in your WordPress directory.

The following commands will grant OpenLiteSpeed the ability to read and write files in the wordpress directory, allowing it to serve the website and perform automatic updates:
sudo chown -R nobody:nobody /usr/local/lsws/Example/html/wordpress

sudo find /usr/local/lsws/Example/html/wordpress/ -type d -exec chmod 750 {} \;

sudo find /usr/local/lsws/Example/html/wordpress/ -type f -exec chmod 640 {} \;
Now you will need to make some changes to the main WordPress configuration file.
curl -s
You will get back unique values that look something like this:

These are configuration lines that you will paste directly into your configuration file to set secure keys. Copy the output you received to your clipboard, and then open the WordPress configuration file located in your document root:
sudo vi /usr/local/lsws/Example/html/wordpress/wp-config.php
Find the section that contains the dummy values for those settings. It will look something like this:

Delete these lines and paste in the values you copied from the command line, the file will look like below:

Next, modify the database connection settings at the top of the file. You need to adjust the database name, database user, and the associated password that you configured within MySQL. Lastly, add the define('FS_METHOD', 'direct'); parameter:

Save and close the file when you are finished.

Configuring OpenLiteSpeed

In this step, you’ll access the OpenLiteSpeed administrative interface and make a few changes to your server’s configuration.

Open up your favorite web browser, navigate to the OpenLiteSpeed administrative interface:

http://server_name_or_IP:7080 and log in with the username admin and password you set up with script.

From the OpenLiteSpeed console, find and click on Server Configuration in the left-hand sidebar menu. Then navigate to the External App tab, find the row of the LiteSpeed SAPI App, and click on its Edit button:

You installed the lsphp73 package, a compilation of PHP optimized to work with OpenLiteSpeed through the LiteSpeed SAPI. However, the default settings in the External App page point to lsphp rather than lsphp73. Due to this, your OpenLiteSpeed installation won’t be able to correctly execute PHP scripts.

To correct this, change the Name field to lsphp73, change the Address field to uds://tmp/lshttpd/lsphp73.sock, and change the Command field to read $SERVER_ROOT/lsphp73/bin/lsphp:

After making those changes, click on the Save icon in the upper right-hand corner of the LiteSpeed SAPI App box.

Next, click on Virtual Hosts in the left-hand menu. On the Virtual Hosts page, find the virtual host you plan to use and click on its View icon. For this guide, we’ll use the default Example virtual host:

Navigate to the virtual host’s General tab. There, find the General section, and click on its Edit button:

All of your WordPress content and files are stored in the wordpress directory you created earlier, update the Document Root field to point to that directory. To do this, all you need to do is append wordpress/ to the end of the default value:

Click the Save icon to save this change.

While still in the General tab, scroll down to find the Index Files section and click on its Edit icon:

In the Index Files field, precede index.html with index.php and after updating this field, it will look like below:

Click the Save icon before continuing.

Next, navigate to the virtual host’s Rewrite tab. Find the Rewrite Control section and press the Edit button:

Set both the Enable Rewrite and Auto Load from .htaccess options to Yes by clicking the respective radial buttons. Configuring rewrite instructions in this fashion will allow you to use permalinks within your WordPress installation:

Click the Save icon after making those changes.

Now click on the Security tab, and then click the Delete button next to SampleProtectedArea within the Realms List table:

You will be asked to confirm the deletion. Click Delete to proceed.

Next, click on the Context tab. In the Context List, delete the /protected/ context that was associated with the security realm you just deleted:

Again, you will have to confirm the deletion by clicking Delete.

Now, press the green Graceful Restart icon in the upper-right corner of the OpenLiteSpeed console. This will restart the OpenLiteSpeed server, taking the changes we’ve made into effect:

Now, you’re ready to setup WordPress in your browser.

Finishing the WordPress Installation

Open up your favorite i.e. Firefox, Chrome web browser, navigate to your server’s name or IP address:

http://server_name_or_IP:8088 and select the language if it ask you would like to use:

Next, you will see the main setup page. Select a name for your WordPress site and choose a username. A strong password is generated automatically. Save this password or select an alternative strong password.

Enter your email address and select whether you want to discourage search engines from indexing your site:

When ready, click the Install WordPress button. You’ll be taken to a page that prompts you to log in:

Enter your username and password to log in

Once you log in, you will be taken to the WordPress administration dashboard:

From the dashboard, you can begin making changes to your site’s theme and publishing content.

Wrapping Up

By completing this tutorial, you installed and configured a WordPress instance on a CentOS 8 server running OpenLiteSpeed web server.

No comments

Comments with links will not be published.