Set Up WordPress with OpenLiteSpeed on Ubuntu

This tutorial will show you how to set up WordPress with OpenLiteSpeed web server on Ubuntu or Debian.


You will need one (physical or virtual) machine installed with Ubuntu  or Debian having sudo non-root user privileges.

Set Timezone

Type the following command to correct your Ubuntu server's timezone.
sudo timedatectl set-timezone Asia/Karachi

Adding OpenLiteSpeed Repository

OpenLiteSpeed provides a repository for its software you can use with Ubuntu’s standard apt command to install:
wget -qO - | sudo apt-key add -

sudo add-apt-repository 'deb bionic main'

Installing Ubuntu 19 Dependencies

You will need to perform this particular section only if you are running Ubuntu 19. If you are on Ubuntu 18.04, you can safely skip this and move to next step.
wget -qO - | sudo apt-key add -
sudo add-apt-repository 'deb bionic main' sudo add-apt-repository 'deb bionic-updates main' wget sudo dpkg -i libzip4_1.5.1-4_amd64.deb

Installing OpenLiteSpeed

You can install OpenLiteSpeed web server by typing the following command:
sudo apt install openlitespeed lsphp73

sudo ln -sf /usr/local/lsws/lsphp73/bin/lsphp /usr/local/lsws/fcgi-bin/lsphp5

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/

Updating Firewall Rules

You need to open up these two ports on firewall to allow access.
sudo ufw allow 7080
sudo ufw allow 80
Now access administrative web interface and change port from 8088 to default HTTP port 80:

Open up your favorite web browser and navigate to https://server_name_or_IP:7080 and login with username and password you created with script in earlier step.

Click Listeners in the list of options on the left side of the interface. A list of all available listeners will load.

In the list of listeners, click the “View/Edit” button for the Default listener:

This will load a page with more details about the Default listener. Click the edit button in the top-right corner of the “Address Settings” table to modify its values:

On the next screen, change port 8088 to port 80, then click the floppy disk icon, Save:

After the modification, you will need to restart the server. Click the “reload” arrow icon to restart OpenLiteSpeed:

Installing MySQL

First, install MySQL database and afterwards run the mysql_secure_installation script and follow the on screen instruction to secure it:
sudo apt install mysql-server
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

Now you need to create a user and database with the following command. For this guide, we will name this database wordpress to keep things simple and easy to remember, but you can name it whatever you’d like:
sudo mysql -u root -p

CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'wordpress';

GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost';


sudo mysql -u root -p wordpress
ALTER USER 'wordpress'@'localhost' IDENTIFIED WITH mysql_native_password BY 'wordpress';



Installing PHP Dependencies

You will need to install some of these additional PHP extensions commonly used with WordPress:
sudo apt install lsphp73-curl lsphp73-imagick lsphp73-imap lsphp73-memcached lsphp73-mysql lsphp73-redis

Downloading WordPress

Now that your server software is configured, you can install and set up WordPress. For security reasons in particular, it is always recommended that you get the latest version of WordPress directly from their site.
curl -O
tar xzvf latest.tar.gz

Configuring WordPress

Before we can go through the web-based setup process for WordPress, we need to adjust some items in our WordPress directory.
touch ~/wordpress/.htaccess
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
mkdir ~/wordpress/wp-content/upgrade
sudo cp -a ~/wordpress/. /usr/local/lsws/Example/html/wordpress
sudo chown -R nobody:nogroup /usr/local/lsws/Example/html/wordpress
sudo find /usr/local/lsws/Example/html/wordpress/ -type f -exec chmod 640 {} \;
sudo find /usr/local/lsws/Example/html/wordpress/ -type d -exec chmod 750 {} \;
curl -s
You will receive the output like below, copy the output you received to your clipboard,

and then open the WordPress configuration file located in your document root:
sudo nano /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 values you copied from the command line in the same section.

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.

The other change you must make is to set the define('FS_METHOD', 'direct'); that WordPress should use to write to the file-system. Failure to set this parameter would result in WordPress prompting for FTP credentials when you perform certain actions.

This parameter can be added below the database connection settings.

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 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 Ubuntu 19.10 server running with OpenLiteSpeed web server.

No comments:

Powered by Blogger.