OpenLiteSpeed is a high-performance, lightweight web server ideal for hosting websites and applications. Together with PHP and MySQL, it forms a robust and efficient stack for dynamic content delivery. This guide explains how to set up OpenLiteSpeed, PHP, and MySQL on your VPS step by step.
Prerequisites
To follow this tutorial, you need:
-
A VPS: Hosteons provides reliable VPS services suitable for this setup.
-
Linux OS: Ubuntu 20.04 or Debian 11 (adjustments may be needed for other distributions).
-
Root Access: Administrative privileges on your server.
Step 1: Update Your Server
Ensure your system is updated to avoid issues with outdated packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install OpenLiteSpeed
-
Add the OpenLiteSpeed repository:
sudo wget -O - https://repo.litespeed.sh | sudo bash
-
Install OpenLiteSpeed:
sudo apt install openlitespeed -y
-
Start OpenLiteSpeed and enable it to start on boot:
sudo systemctl start lsws
sudo systemctl enable lsws
-
Access the OpenLiteSpeed WebAdmin interface at
http://your_server_ip:7080
. Set the WebAdmin password with:
sudo /usr/local/lsws/admin/misc/admpass.sh
Step 3: Install MySQL
Install MySQL to manage databases:
sudo apt install mysql-server -y
Secure the MySQL installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and apply recommended security settings.
Step 4: Install PHP
OpenLiteSpeed integrates seamlessly with PHP. To install and configure PHP:
-
Install PHP and extensions:
sudo apt install lsphp81 lsphp81-mysql -y
-
Configure PHP in OpenLiteSpeed:
-
Log in to the WebAdmin panel (
http://your_server_ip:7080
). -
Go to Server Configuration > External App.
-
Click Add to create a new external application with these settings:
-
Name: lsphp81
-
Address: uds://tmp/lshttpd/lsphp81.sock
-
Max Connections: 35
-
Environment: PHP_LSAPI_CHILDREN=35
-
Command:
/usr/local/lsws/lsphp81/bin/lsphp
-
-
Save the changes.
-
-
Map the application to your virtual host:
-
Navigate to Virtual Hosts > Context.
-
Add a new context with these settings:
-
Type: CGI
-
URI:
/*
-
Handler Name: lsphp81
-
-
Save and restart OpenLiteSpeed.
-
Step 5: Test PHP
Verify that PHP is correctly configured:
-
Create a test PHP file:
echo '<?php phpinfo(); ?>' | sudo tee /usr/local/lsws/Example/html/info.php
-
Visit
http://your_server_ip/info.php
in your web browser. You should see a PHP information page.
Step 6: Secure Your Server
-
Remove the PHP Info File: Once tested, delete the file:
sudo rm /usr/local/lsws/Example/html/info.php
-
Set Up a Firewall: Allow only essential ports:
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 7080
sudo ufw enable
-
Enable SSL: Secure your server with Let’s Encrypt:
sudo apt install certbot
sudo certbot certonly --webroot -w /usr/local/lsws/Example/html -d your_domain
Configure SSL in the WebAdmin panel under Listeners > SSL.
Conclusion
By completing this guide, you now have a fully functional OpenLiteSpeed, PHP, and MySQL stack ready to host websites and applications. Hosteons' reliable VPS solutions are ideal for deploying this stack, ensuring high performance and reliable support for your hosting needs.