This tutorial will guide you how to install WordPress on OpenLiteSpeed web server. Before we start, make sure that you have OpenLiteSpeed web server, PHP, MySQL are installed and configured. If you didn’t have already, you can see How to install OpenLiteSpeed, PHP 7.3, MySQL on Debian 7/8 and CentOS 7

Preparing database for WordPress

Step 1: We will create a specific database and user for WordPress. To create a database, first log into your server and execute following command.

mysql -u root -p

Now we will create the user and database. Run the following commands one by one:

create database wordpress;
create user 'wpuser'@'localhost' identified by 'giveRandomPasswordHere';

Granting all the privileges to ‘wpuser’ on wordpress database

grant all privileges on wordpress.* to 'wpuser'@'localhost';
flush privileges;
exit;

To sum up, here we configure the following things which will be needed to setup WordPress later:
Database Name: wordpress
Username: wpuser
Password: givenRandomPassword

Download WordPress and give the right permission

Let’s say our domain’s public directory is in /usr/local/lsws/example10/html So we will download and extract WordPress to that directory.

  1. First, let’s download the WordPress:
cd /usr/local/lsws/example10/html
wget http://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz

NOTE: if you are following my Deploy WordPress with OpenLiteSpeed in Docker swarm, navigate to /var/www/vhosts/example10/html instead of /usr/local/lsws/example10/html

  1. If you want to install WordPress in a sub-directory (http://yourdomain.com/wordpress), then skip the next step. Otherwise, run the following commands to install WordPress in root directory
mv ./wordpress/* .
rmdir ./wordpress
  1. The above commands will move all the WordPress files from WordPress folder to the root directory and remove the empty WordPress directory. Now let’s set the correct permission for all the files and directory
chown -R nobody:nogroup .

 

Configuring Web Server to handle index files and rewrite rules for WordPress

Before we start installing WordPress, we need to set the index files. In that way, the web server can render PHP files.

  1. First select your virtual host. In our case it is example10.

<img class="alignnone size-full wp-image-135" src="/uploads/2019/04/select_vhost.png" alt="" width="1510" height="633" srcset="/uploads/2019/04/select_vhost.png 1510w, /uploads/2019/04/select_vhost-768x322.png 768w" sizes="(max-width: 1510px) 100vw, 1510px" />

  1. Now go to “General” tab edit “Index Files” configuration

<img class="alignnone size-full wp-image-136" src="/uploads/2019/04/set_index.png" alt="" width="1510" height="730" srcset="/uploads/2019/04/set_index.png 1510w, /uploads/2019/04/set_index-768x371.png 768w" sizes="(max-width: 1510px) 100vw, 1510px" />

  1. Set configuration like this:
Use Server Index Files: Yes
Index Files: index.html, index.php
Auto Index: Yes

Click save icon to save the changes

<img class="alignnone size-full wp-image-137" src="/uploads/2019/04/save_index_config.png" alt="" width="1514" height="552" srcset="/uploads/2019/04/save_index_config.png 1514w, /uploads/2019/04/save_index_config-768x280.png 768w" sizes="(max-width: 1514px) 100vw, 1514px" />

Now we will configure the rewrite rules so that the permalink of WordPress works perfectly.

  1. Go to the “Rewrite” tab and edit the “Rewrite Control” settings.

<img class="alignnone size-full wp-image-138" src="/uploads/2019/04/rewrite_rules_config.png" alt="" width="1526" height="462" srcset="/uploads/2019/04/rewrite_rules_config.png 1526w, /uploads/2019/04/rewrite_rules_config-768x233.png 768w" sizes="(max-width: 1526px) 100vw, 1526px" />
5. Set the “Enable Rewrite” & “Auto Load from .htaccess” to “Yes” and save
<img class="alignnone size-full wp-image-139" src="/uploads/2019/04/set_correct_rewrite.png" alt="" width="1519" height="431" srcset="/uploads/2019/04/set_correct_rewrite.png 1519w, /uploads/2019/04/set_correct_rewrite-768x218.png 768w" sizes="(max-width: 1519px) 100vw, 1519px" />

  1. Now edit the “Rewrite Rules” settings and paste the following line then click save. Replace ‘example10’ with the name of the directory of your virtual host
rewriteFile /usr/local/lsws/example10/html/.htaccess

<img class="alignnone size-full wp-image-149" src="/uploads/2019/04/set_rewrite_file_save.png" alt="" width="1411" height="613" srcset="/uploads/2019/04/set_rewrite_file_save.png 1411w, /uploads/2019/04/set_rewrite_file_save-768x334.png 768w" sizes="(max-width: 1411px) 100vw, 1411px" />

  1. Finally restart the server gracefully to apply the changes

<img class="alignnone size-full wp-image-150" src="/uploads/2019/04/restart_server_rewrite_added.png" alt="" width="1621" height="579" srcset="/uploads/2019/04/restart_server_rewrite_added.png 1621w, /uploads/2019/04/restart_server_rewrite_added-768x274.png 768w" sizes="(max-width: 1621px) 100vw, 1621px" />

Visit your domain and install WordPress to build your amazing website!