How to Set Up OpenLiteSpeed, PHP, and MySQL on Your VPS Print

  • openlitespeed, litespeed, vps, php, mysql, linux
  • 0

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:

  1. A VPS: Hosteons provides reliable VPS services suitable for this setup.

  2. Linux OS: Ubuntu 20.04 or Debian 11 (adjustments may be needed for other distributions).

  3. 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

  1. Add the OpenLiteSpeed repository:

sudo wget -O - https://repo.litespeed.sh | sudo bash
  1. Install OpenLiteSpeed:

sudo apt install openlitespeed -y
  1. Start OpenLiteSpeed and enable it to start on boot:

sudo systemctl start lsws
sudo systemctl enable lsws
  1. 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:

  1. Install PHP and extensions:

sudo apt install lsphp81 lsphp81-mysql -y
  1. 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.

  2. 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:

  1. Create a test PHP file:

echo '<?php phpinfo(); ?>' | sudo tee /usr/local/lsws/Example/html/info.php
  1. Visit http://your_server_ip/info.php in your web browser. You should see a PHP information page.


Step 6: Secure Your Server

  1. Remove the PHP Info File: Once tested, delete the file:

sudo rm /usr/local/lsws/Example/html/info.php
  1. Set Up a Firewall: Allow only essential ports:

sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 7080
sudo ufw enable
  1. 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.


Was this answer helpful?

« Back