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

OpenLitespeed Tutorial

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:

  1. A VPS: A reliable VPS provider like Hosteons.
  2. Linux OS: Ubuntu 20.04 or Debian 11 (minor adjustments may be needed for other distributions).
  3. 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

  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 run at boot:
sudo systemctl start lsws
sudo systemctl enable lsws
  1. Access the OpenLiteSpeed WebAdmin interface at http://your_server_ip:7080. The default username is admin, 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:

  1. Install PHP and necessary extensions:
sudo apt install lsphp81 lsphp81-mysql -y
  1. 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.
  1. 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:

  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 a web browser. You should see the PHP information page.

Step 6: Secure Your Server

  1. Remove the PHP Info File: After testing, delete the PHP info file:
sudo rm /usr/local/lsws/Example/html/info.php
  1. 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
  1. 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.

How to Set Up Nginx, PHP, and MySQL on a VPS

If you’re looking to host a website or web application, setting up a reliable server stack is essential. Nginx, PHP, and MySQL provide a powerful combination for serving dynamic content efficiently. This guide will walk you through setting up Nginx, PHP, and MySQL on a Linux VPS from scratch.

Prerequisites

Before starting, ensure you have:

  1. A VPS: A reliable VPS provider like Hosteons.
  2. Linux OS: Ubuntu 20.04 or Debian 11 (other distributions may require slight adjustments).
  3. Root Access: Administrative privileges on your server.

Step 1: Update Your Server

To ensure you have the latest packages and security patches, update your system:

sudo apt update && sudo apt upgrade -y

Step 2: Install Nginx

Nginx is a lightweight, high-performance web server. Install it with the following command:

sudo apt install nginx -y

After installation, start and enable Nginx to run at boot:

sudo systemctl start nginx
sudo systemctl enable nginx

You can check if Nginx is running by visiting your server’s IP address in a web browser. You should see the default Nginx welcome page.

Step 3: Install MySQL

MySQL is a popular relational database management system used for storing application data. Install it using:

sudo apt install mysql-server -y

Once installed, secure the MySQL installation by running:

sudo mysql_secure_installation

Follow the prompts to set a root password, remove test databases, and disallow remote root logins for added security.

Step 4: Install PHP

PHP is a server-side scripting language used for dynamic web content. To install PHP along with necessary extensions, run:

sudo apt install php-fpm php-mysql -y

Step 5: Configure Nginx to Use PHP

By default, Nginx does not process PHP files. You need to configure Nginx to pass PHP requests to the PHP processor.

  1. Open the default Nginx server block configuration:
sudo nano /etc/nginx/sites-available/default
  1. Modify the file to include the following settings:
server {
    listen 80;
    server_name your_domain_or_IP;
    root /var/www/html;

    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}
  1. Save and exit the file, then test the Nginx configuration:
sudo nginx -t
  1. Reload Nginx to apply the changes:
sudo systemctl reload nginx

Step 6: Test PHP

Create a test PHP file to ensure everything is working:

sudo nano /var/www/html/info.php

Add the following content:

<?php
phpinfo();
?>

Save and exit the file. Visit http://your_server_ip/info.php in your web browser. If PHP is correctly configured, you will see a PHP information page.

Step 7: Secure Your Setup

  1. Remove the PHP Info File: Once you confirm PHP is working, delete the info.php file to prevent unauthorized access:
sudo rm /var/www/html/info.php
  1. Set Up a Firewall: Allow HTTP and HTTPS traffic while blocking unused ports:
sudo ufw allow 'Nginx Full'
sudo ufw enable
  1. Enable SSL: Secure your site with HTTPS using a tool like Let’s Encrypt:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d your_domain

Follow the prompts to set up SSL certificates.

Conclusion

You now have a fully functional server running Nginx, PHP, and MySQL, ready to host your website or application. This stack provides a robust, secure, and efficient foundation for your web hosting needs. If you’re using Hosteons’ VPS, you can take advantage of their reliable performance and support to ensure your setup runs smoothly.