OpenLiteSpeed is a high-performance, lightweight web server that’s perfect for hosting websites or applications. Combined with PHP and MySQL, it provides an efficient and reliable stack for serving dynamic content. This guide will walk you through setting up OpenLiteSpeed, PHP, and MySQL on your VPS.
Prerequisites
Before starting, ensure you have:
- A VPS: A reliable VPS provider like Hosteons.
- Linux OS: Ubuntu 20.04 or Debian 11 (minor adjustments may be needed for other distributions).
- Root Access: Administrative privileges on your VPS.
Step 1: Update Your Server
Begin by updating your system to ensure all software is up-to-date:
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 run at boot:
sudo systemctl start lsws
sudo systemctl enable lsws
- Access the OpenLiteSpeed WebAdmin interface at
http://your_server_ip:7080
. The default username isadmin
, and the password can be set with:
sudo /usr/local/lsws/admin/misc/admpass.sh
Step 3: Install MySQL
MySQL is required for managing databases. Install it with:
sudo apt install mysql-server -y
Secure the installation:
sudo mysql_secure_installation
Follow the prompts to set a root password and enhance security settings.
Step 4: Install PHP
OpenLiteSpeed works seamlessly with PHP. To install and configure PHP:
- Install PHP and necessary extensions:
sudo apt install lsphp81 lsphp81-mysql -y
- Configure OpenLiteSpeed to use PHP:
- Log in to the WebAdmin panel (
http://your_server_ip:7080
). - Navigate to Server Configuration > External App.
- Click Add to create a new external application with the following 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 external application to your virtual host:
- Go to Virtual Hosts > Context.
- Add a new context:
- Type: CGI
- URI:
/*
- Handler Name: lsphp81
- Save and restart OpenLiteSpeed.
Step 5: Test PHP
To confirm 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 a web browser. You should see the PHP information page.
Step 6: Secure Your Server
- Remove the PHP Info File: After testing, delete the PHP info file:
sudo rm /usr/local/lsws/Example/html/info.php
- Set Up a Firewall: Allow only necessary ports (HTTP, HTTPS, and OpenLiteSpeed WebAdmin):
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 7080
sudo ufw enable
- Enable SSL: Secure your site 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
You now have a fully functional OpenLiteSpeed, PHP, and MySQL stack set up on your VPS. This setup provides a fast and efficient environment for hosting websites or applications. Hosteons’ reliable VPS solutions are perfect for deploying this powerful combination, ensuring optimal performance and support for your hosting needs.