WordPress flies like a skyrocket when installed with the perfect speed-optimised OpenLiteSpeed server stack. Over 30% of the websites in the world use WordPress as CMS which defines how powerful is it to design, develop and manage a business website, blog or portal.
OpenLiteSpeed offers a fast and secure environment for running WordPress. OpenLiteSpeed understands Apache rewrite tools and you can install multiple PHP processors for different sites as well.
In this tutorial, we will optimise the OpenLiteSpeed server to host a WordPress site and then install the latest WordPress on the server.
Pre-requisites
Before installing WordPress, you need to have an OpenLiteSpeed server up and running. If you are new to OpenLiteSpeed, check out our tutorial on how to deploy the OpenLiteSpeed server.
Once your OpenLiteSpeed server is set up, you can start installing WordPress. In this guide, we’ll go over the process for:
- Installing MariaDB database
- Creating a database and the database user
- Installing the required PHP extensions
- Configuring OpenLiteSpeed
- Downloading and extracting WordPress
- Setting the right file ownership and permissions
- Installing WordPress itself
- Setting up SSL certificates to enable HTTPS
Begin by following the instructions in the next section to install MariaDB.
Installing MariaDB server
MariaDB is a popular open-source alternative to MySQL database and is conveniently available in the standard repositories. First, update the packages list on the server with the command below.
sudo apt update
Once the packages list has been updated, run the following command to install the MariaDB server and MariaDB client on your server. You’ll be prompted to confirm whether you want to use storage space. Type Y and press Enter to continue with the installation.
sudo apt install mariadb-server
Next, perform the secure installation of MySQL on your server with the following command.
sudo mysql_secure_installation
The command prompt will take you through the wizard containing the questions below. Answer each of them below:
Change the root password: N Remove anonymous user: Y Disallow root login remotely: Y Remove test database and access to it: Y Reload Privilege Table Now: Y
Now that MariaDB is installed and configured, we can create the first database.
Enter the MySQL client by running the next command.
sudo mysql
Then, use the following commands to create a database and grant all permissions on that database to a new database user account.
mysql > CREATE DATABASE wordpress; mysql > GRANT ALL ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'password';
Flush the privilege table and exit from the mysql shell.
mysql > flush privileges; mysql > exit;
Your database is then set to install WordPress at a later step.
Installing required PHP extensions
WordPress works on top of PHP and SQL. To run WordPress on a server seamlessly, install the following required PHP extensions.
sudo apt install lsphp74-common lsphp74-curl lsphp74-imap lsphp74-json lsphp74-mysql lsphp74-opcache lsphp74-imagick lsphp74-memcached lsphp74-redis
Configuring OpenLiteSpeed
Next, you need to configure the OpenLiteSpeed server to host your WordPress site. It requires you to set the right version of the PHP processor, enable the rewrite module and several other features.
Configure your server to use lsphp74 as a PHP processor instead of the default PHP processor.
Go to Server Configuration > External App and click the edit icon as shown below.
Here, you can configure your server to use any specific PHP processor. For this tutorial, we will use lsphp74.
- Replace lsphp with lsphp74
- Replace uds://tmp/lshttpd/lsphp.sock with uds://tmp/lshttpd/lsphp74.sock
- Replace lsphp73/bin/lsphp with $SERVER_ROOT/lsphp74/bin/lsphp
After you make the changes, click the save icon in the top right corner of the panel, as shown in the screenshot above.
Moving next to configure the rewrite module which is an essential requirement for the WordPress features. Go to the Virtual Hosts and click on the view icon.
Click on the General tab and edit the General options with the edit icon at the top right corner.
In the Document Root field, type $VH_ROOT/html/wordpress and click the save button at the top right corner.
Then again on the General tab of Virtual Hosts configuration, click the edit icon next to the Index Files section.
In the Index Files field, add index.php at the beginning of the section. Then click the save button at the top right corner.
Next, go to the Rewrite tab of the Virtual Hosts configuration view and edit the Rewrite Control options.
Set Enable Rewrite and Auto Load from .htaccess to Yes and click the save icon at the top right corner.
Once you’ve configured the OpenLiteSpeed server, Click the gracefully restart icon to apply the changes.
Downloading and extracting WordPress
Now that our server is configured to host WordPress, you should download and install WordPress.
Navigate to the virtual host root which is /usr/local/lsws/Example/html
cd /usr/local/lsws/Example/html/
Then download the latest version of WordPress using the wget command below.
wget https://wordpress.org/latest.tar.gz
Lastly, extract the zipped file. This will create a directory called ‘wordpress’ in /usr/local/lsws/Example/html
tar xvfz latest.tar.gz
Setting up file ownership and permissions
Setting up the right ownership of files and folders will make sure that you do not encounter problems while installing or downloading new themes or plugins.
First, remove ownership from the wordpress directory.
sudo chown -R nobody:nogroup /usr/local/lsws/Example/html/wordpress
Then, 750 permissions were set for the directories and 640 for the files. You can do this with the following commands.
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 {} \;
Once you configure the right permissions, you’re all set to open your website and install WordPress in your browser.
Installing WordPress
At this stage, you can open the WordPress installation wizard in your web browser by going to your domain if set or the IP address of your OpenLiteSpeed server.
The very first screen will ask you to choose your preferred language. Choose your language and click the Continue button.
In the second screen, WordPress prompts you to keep the database server information and credentials ready. Then just click the Let’s go! button.
In the next screen, fill up the fields as follows:
- Database name: the database you created through the MySQL shell, wordpress in this example.
- Username: Here you need to input the database user
- Password: Type in the password of your database user
- Database Host: localhost
- Table Prefix: wp_ is the default table prefix. However, you can type something else to enhance the security of your website.
Once you fill up all the information, click the Submit button to confirm.
At this stage, you’ve configured the database connection for the WordPress installation. Next, you need to click the Run the Installation button to set up your WordPress site.
Next, you’ll be prompted to input the details of your website, create an administrator account and set a password.
Select the name of your website and choose an administrator username. It is recommended not to use a generic username such as “admin” or “administrator”. A strong password will be generated automatically. Type in your email address and choose whether you want search engines to index your site or not.
Once you’ve filled up everything and ready, click the Install WordPress button. On successful installation, you will be prompted to log in.
Log in using the username and password you just created in the installation wizard. You’ll then see your very own WordPress website’s admin dashboard.
Creating and configuring SSL certificates
At this stage, you should have successfully installed WordPress on your web server using one of the most powerful server packages. Next, we can obtain and install SSL certificates to add a security layer between your website server and your audience.
If you have already used Certbot to obtain SSL certificates for your OpenLiteSpeed server, you can use the Certbot client that has already been installed. In that case, you can skip the installation step here and go ahead to obtain certificates for your WordPress site.
If you do not yet have the Certbot installed, use the steps here to get the client.
First, update the packages installed on the server.
sudo apt update
Then, install the Certbot client using the following command.
sudo apt install certbot
Once you’ve installed the Certbot, go ahead and obtain the SSL certificates for your server using the command below. Note that before you can obtain SSL certificates, you need to have a domain name A record pointing to your OpenLiteSpeed server’s public IP address. You can find out more about how to create domain name records in its guide.
sudo certbot certonly --webroot
You will then be prompted to answer the following questions.
- Enter Email address: Type in your email address
- Accept the terms of service: A
- Share your Email Address with EFF: Type Y for yes and N for No.
- Enter Domain name: Type your FQDN (fully qualified domain name) here
- Input the Web root: /usr/local/lsws/Example/html/wordpress/
Once you have answered all the questions and validation process is complete, the certificate files will be saved in /etc/letsencrypt/live/<your-domain>/ directory.
Next, configure the WordPress site on your OpenLiteSpeed server to use the SSL certificate. Navigate to the Virtual Host configuration and open the SSL tab. Edit the SSL Private Key & Certificate.
Type the fields as follows:
Private Key File: /etc/letsencrypt/live/<your-domain>/privkey.pem Certificate File: /etc/letsencrypt/live/<your-domain>/fullchain.pem Chained Certificate: Yes CA Certificate Path: /etc/letsencrypt/live/<your-domain>/fullchain.pem CA Certificate File: /etc/letsencrypt/live/<your-domain>/fullchain.pem
Once completed, go to Listeners and add a new listener.
Fill in the fields as follows:
Listener Name: SSL IP Address: ANY Post: 443 Binding: Enable REUSEPORT: Not Set Secure: Yes
Once all set, apply the new settings by clicking the save icon on the right.
Next, view the SSL listener to configure the Virtual host mapping.
Add a row in Virtual Host Mappings.
Choose the virtual host and type in your domain name. Save the settings using the save button in the top right corner.
Once you’ve configured the SSL with your OpenLiteSpeed server, click the gracefully restart icon to apply the changes.
You should now be able to visit your website on https protocol as well.
Conclusion and next steps
Congratulations, you should now have a brand new WordPress site set up and secured with SSL certificates. WordPress runs lightning quick on the top of the OpenLiteSpeed web server with little left to be desired.
You can install the LiteSpeed Cache Plugin to enable server-optimized caching for your WordPress website.
You can also enable Memcached caching on your server with the following command.
sudo apt-get install memcached
Lastly, you might wish to install some of the must-have WordPress plugins and choose a WordPress Theme. To get started, head over to your WordPress dashboard.
steve
Great tutorial, however you have couple of of syntax error in some commands, for instance it should be GRANT ALL PRIVILEGES ON *.* TO ‘wordpress’@localhost IDENTIFIED BY ‘password’ ;
by default ubuntu 20.04 on digitalocean already had Apache2 installed, which causes conflict and had to be removed, phpmyadmin is very useful tool to manually change setting in the Database however it is for some reason not loading, the biggest issue I had is after installing the WP and selecting https the admin page and main site page doesn’t load anymore, I had to these 2 lines below to wp.config.php to get access again, however the settings for url in wp becomes dimmed.
define(‘WP_HOME’,’https://mydomain.com’);
define(‘WP_SITEURL’,’https://mydomain.com’);
any suggestion will be greatly appreciated
Janne Ruostemaa
Hi Steve, thanks for the comment. You are right that the MySQL commands should use keywords written in all capital letters, we’ve updated these. However, the syntax is correct and the commands should work just fine. As for Apache, it can bind the default ports and prevent OpenLiteSpeed from starting. The steps outlined in the guide are intended to work the best on a clean install on UpCloud which does not include web server software by default.
Tan Nguyen
Help,
php.ini upload_max_filesize is not working
You can guide me
Ronit
This doesn’t work after I followed your tutorial on how to install OLS(which works fine).
nusa
Hi, In part of Setting up the files ownership and permissions. Why we remove the ownership and group for wordpress folder ?
do you have clear reassons ?
im still new in vps setup.
thanks.
Janne Ruostemaa
Hi Tan, thanks for the comment. As configured in this guide, OpenLiteSpeed uses the lsphp PHP processor by default. The php.ini file can be found in slightly varying locations depending on your PHP version. For example, the php.ini for lsphp 7.4 is under /usr/local/lsws/lsphp74/etc/php/7.4/litespeed/php.ini
Change the upload_max_filesize in the php.ini for the PHP version your website is using and then restart your web host service.
Janne Ruostemaa
Hi there, thanks for the question. The OpenLiteSpeed web server uses the username “nobody” and “nogroup” by default so essentially removing the user permission restrictions is done to give the web server the necessary access to read and write to the WordPress directory.
Janne Ruostemaa
Hi Ronit, thanks for the comment. The steps in the tutorial should work though they are a little complicated. Try checking that the database password works and you are able to access the WordPress DB. Also check that the file permissions are set correctly for OpenLiteSpeed to be able to read and write to the WordPress directory.
wasim akram
For your kind information there is an error in this line please edit it.
sudo apt install lsphp74-common lsphp74-curl lsphp74-imap lsphp74-json
lsphp74-mysql lsphp74-opcache lsphp74-imagick lsphp74-memcached lsphp74-redis
Janne Ruostemaa
Hi Wasim, thanks for the comment. The install command works as expected and we can’t see any error in it. Note that the command is split on two lines for legibility and should be copied as one command.
Mukesh
Thanks for the article. Why do you suggest to use PHP7.4 instead of default? The default now is PHP8.0, is that not optimal to use for WordPress?
Thanks.
Janne Ruostemaa
Hi Mukesh, thanks for the question. Both OpenLiteSpeed and WordPress work well with PHP8.0 so you should be fine upgrading if you wish. Note though that some WordPress plugins might not have been updated for 8.0 so your mileage may vary.