Installing a LOMP (Linux, OpenLiteSpeed, MySQL/MariaDB, and PHP) stack on your Debian 12 server can provide you with a powerful and efficient platform to host your websites and applications. In this comprehensive guide, we will walk you through the step-by-step process of setting up and configuring each component of the LOMP stack. By the end of this tutorial, you will have a fully functional server that is ready to serve dynamic PHP content.
Prerequisites
Before getting started, make sure you have the following prerequisites in place:
- A server running Debian 12.
- A non-root user with sudo privileges.
- A fully qualified domain name (FQDN) pointing to your server.
- SELinux is not required to be disabled or configured for OpenLiteSpeed to work.
Step 1: Configure Firewall
The first step in setting up your LOMP stack is to configure the firewall on your Debian 12 server. By default, Debian comes with ufw (Uncomplicated Firewall).
Check if the firewall is running:
sudo ufw status
If the firewall is inactive, enable it and allow SSH, HTTP, and HTTPS ports:
sudo ufw allow OpenSSH sudo ufw allow http sudo ufw allow https
Next, open ports related to OpenLiteSpeed:
sudo ufw allow7080/tcp
Finally, enable the firewall:
sudo ufw enable
Step 2: Install OpenLiteSpeed
OpenLiteSpeed is a lightweight and open-source version of the LiteSpeed Server developed by LiteSpeed Technologies. It supports Apache Rewrite rules, HTTP/2, and HTTP/3, along with TLS v1.3 and QUIC protocols. It also comes with a WebGUI-based Administration panel, making it easier to manage.
To install OpenLiteSpeed, we will build it from the source code:
- Download the OpenLiteSpeed source code file from the official downloads page:
wget https://openlitespeed.org/packages/openlitespeed-1.7.18.src.tgz
- Extract the source code file:
tar-zxf openlitespeed-*.tgz
- Switch to the extracted directory:
cd openlitespeed-1.7.18
- Build the server package:
sudo ./build.sh
- Edit the
ols.conf
file:
sudo nano ols.conf
- Update the following settings in the
ols.conf
file:
SERVERROOT=/usr/local/lsws OPENLSWS_USER=nobody OPENLSWS_GROUP=nobody OPENLSWS_ADMIN=[your-email] OPENLSWS_ADMINSSL=yes OPENLSWS_ADMINPORT=7080 USE_LSPHP7=yes DEFAULT_TMP_DIR=/tmp/lshttpd PID_FILE=/tmp/lshttpd/lshttpd.pid OPENLSWS_EXAMPLEPORT=8088
Save the file and exit the editor.
- Install OpenLiteSpeed:
sudo ./install.sh
- Start the OpenLiteSpeed server:
sudo systemctl start lsws
- Check the status of the service:
sudo systemctl status lsws
- Verify the version of the server installed:
/usr/local/lsws/bin/lshttpd-v
Congratulations! You have successfully installed OpenLiteSpeed on your Debian 12 server.
Step 3: Install MariaDB
Debian 12 no longer ships with MySQL server. Instead, we will be using MariaDB, a MySQL drop-in replacement.
To install MariaDB, follow these steps:
- Update the LiteSpeed repository:
sudo nano/etc/apt/sources.list.d/lst_debian_repo.list
- Add the following line to the file:
deb http://rpms.litespeedtech.com/debian/ bullseye main
Save the file and exit the editor.
- Install the MariaDB server:
sudo apt install mariadb-server
- Check the status of the service:
sudo systemctl status mariadb
- Run the MariaDB security script:
sudo mariadb-secure-installation
Follow the prompts to set the root password, remove anonymous users, disallow remote root logins, remove the test database, and reload the privilege tables.
- Exit the MySQL shell:
exit
Congratulations! You have successfully installed MariaDB on your Debian 12 server.
Step 4: Install PHP
In this step, we will install PHP, a server-side scripting language that is widely used for web development.
- Install the build tools:
sudo apt install build-essential autoconf libtool bison re2c pkg-config
- Install the packages required by the PHP build process:
sudo apt install libssl-dev libsqlite3-dev zlib1g-dev libcurl4-openssl-dev libonig-dev libzip-dev libmemcached-dev libreadline-dev libgmp-dev libpng-dev libjpeg-dev libwebp-dev libxpm-dev libicu-dev libfreetype6-dev libxslt-dev libldb-dev libtidy-dev libvips-dev libsodium-dev libavif-dev libldap2-dev libxml2-dev libkrb5-dev libc-client2007e-dev libpq-dev libargon2-0 libargon2-dev libbz2-dev libffi-dev libc-client-dev libpspell-dev flex libgmp3-dev libmcrypt-dev libmhash-dev freetds-dev libmariadb-dev libmariadb-dev-compat libncurses5-dev libpcre3-dev libaspell-dev librecode-dev libsnmp-dev
- Download the PHP source code:
cd ~ wget https://www.php.net/distributions/php-8.2.11.tar.gz
- Extract the source code:
tar -xzf php-8.2.11.tar.gz
- Switch to the downloaded directory:
cd php-8.2.11
- Configure the PHP build:
sudo ./configure --prefix=/usr/local/lsws/lsphp82 --enable-bcmath --enable-calendar --enable-exif --enable-ftp --enable-gd --enable-intl --enable-mbregex --enable-mbstring --enable-mysqlnd --enable-opcache --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --with-avif --with-curl --with-ffi --with-freetype --with-gettext --with-gmp --with-imap --with-imap-ssl --with-jpeg --with-kerberos --with-libxml --with-ldap --with-mysqli --with-mysql-sock=/run/mysqld/mysqld.sock --with-openssl --with-password-argon2 --with-pdo-mysql=mysqlnd --with-pdo-pgsql=/usr/bin/pg_config --with-pear --with-pspell --with-readline --with-sodium --with-tidy --with-webp --with-xpm --with-xsl --with-zip --with-zlib --enable-litespeed
- Compile the source:
sudo make -j $(nproc)
- Install PHP:
sudo make install
- Copy the
php.ini
file:
sudo cp php.ini-production /usr/local/lsws/lsphp82/lib/php.ini
- Edit the
php.ini
file:
sudo nano /usr/local/lsws/lsphp82/lib/php.ini
- Update the
include_path
variable:
include_path = /usr/local/lsws/lsphp82/lib/php
- Save the file and exit the editor.
Congratulations! You have successfully installed PHP on your Debian 12 server.
Step 5: Configure OpenLiteSpeed to Work with PHP
Now that you have installed both OpenLiteSpeed and PHP, it’s time to configure OpenLiteSpeed to work with PHP.
- Open the OpenLiteSpeed administration panel in your browser:
http://<YOUR_SERVER_IP>:7080
- Log in using the administrator credentials you set during the installation.
- Go to the Server Configuration section on the left-hand side and click on the External App tab.
- Click on the Edit button next to the LiteSpeed App for PHP.
- Update the settings as follows:
- Name: lsphp
- Address: uds://tmp/lshttpd/lsphp.sock
- Max Connections: 35
- Environment: PHPLSAPIMAXREQUESTS=500 PHPLSAPICHILDREN=35 LSAPIAVOID_FORK=200M
- Initial Request Timeout (secs): 60
- Retry Timeout: 0
- Persistent Connection: Yes
- Response Buffering: No
- Start By Server: Yes (Through CGI Daemon)
- Command: lsphp82/bin/lsphp
- Back Log: 100
- Instances: 1
- Priority: 0
- Memory Soft Limit (bytes): 2047M
- Memory Hard Limit (bytes): 2047M
- Process Soft Limit: 1400
- Process Hard Limit: 1500
- Click Save to apply the changes.
- Restart the server by clicking on the Graceful restart button in the top right corner of the administration panel.
Congratulations! OpenLiteSpeed is now configured to work with PHP.
Step 6: Create a Virtual Host
To host your websites and applications, you need to create a virtual host in OpenLiteSpeed.
- Create directories for your virtual host:
sudo mkdir /usr/local/lsws/example.com/{html,logs} -p
The html
directory will hold your website’s public files, and the logs
directory will contain server logs.
- Open the OpenLiteSpeed administration panel.
- Go to the Virtual Hosts section on the left-hand side and click on the Add button.
- Fill in the following values:
- Virtual Host Name: example.com
- Virtual Host Root: $SERVER_ROOT/example.com/
- Config File: $SERVERROOT/conf/vhosts/$VHNAME/vhconf.conf
- Follow Symbolic Link: Yes
- Enable Scripts/ExtApps: Yes
- Restrained: Yes
- External App Set UID Mode: Server UID
- Click Save to create the virtual host.
- Go to the Virtual Hosts section and choose your virtual host (example.com).
- Modify the configuration as follows:
- Document Root: $VH_ROOT/html/
- Domain Name: example.com
- Enable GZIP Compression: Yes
- Enable Brotli Compression: Yes
- Click Save to apply the changes.
- Set up index files by clicking the Edit button next to Index Files.
- Use the following settings:
- Use Server Index Files: No
- Index files: index.php, index.html, index.htm
- Auto Index: No
- Click Save to apply the changes.
- Configure Log files by clicking the Edit button next to Virtual Host Log.
- Use the following settings:
- Use Server’s Log: Yes
- File Name: $VH_ROOT/logs/error.log
- Log Level: ERROR
- Rolling Size (bytes): 10M
- Keep Days: 30
- Compress Archive: Not Set
- Click Save to apply the changes.
- Configure Access Log by clicking the plus sign in the Access Log section.
- Use the following settings:
- Log Control: Own Log File
- File Name: $VH_ROOT/logs/access.log
- Piped Logger: Not Set
- Log Format: Not Set
- Log Headers: Not Set
- Rolling Size (bytes): 10M
- Keep Days: 30
- Compress Archive: Not Set
- Bytes log: Not Set
- Click Save to apply the changes.
- Configure Access Control under the Security section.
- Use the following settings:
- Allowed List: *
- Denied List: Not Set
- Click Save to apply the changes.
- Configure Script Handler Definition by clicking the plus sign in the Script Handler Definition section.
- Use the following settings:
- Suffixes: php
- Handler Type: LiteSpeed SAPI
- Handler Name: [Server Level]: lsphp
- Click Save to apply the changes.
- Configure Rewrite Control under the Rewrite section.
- Use the following settings:
- Enable Rewrite: Yes
- Auto Load from .htaccess: Yes
- Log Level: Not Set
- Click Save to apply the changes.
- Configure Listeners by going to the Listeners section and clicking on the View button next to the Default Listener.
- Add a new Virtual Host Mapping under the SSL Listener by clicking on the Add button.
- Use the following settings:
- Virtual Host: example.com
- Domains: example.com
- Click Save to apply the changes.
- Restart the server by clicking on the Graceful restart button in the top right corner of the administration panel.
Congratulations! You have successfully created a virtual host in OpenLiteSpeed.
Step 7: Install SSL Certificate
To secure your website, you need to install an SSL certificate. We will install both a self-signed certificate for the overall server and a Let’s Encrypt certificate for the specific site.
- Create a Self-Signed Certificate for the overall server:
cd~ openssl req -x509 -days365 -newkey rsa:4096 -keyout key.pem -out cert.pem -nodes
- Create the directory for the self-signed certificates:
sudo mkdir /usr/local/lsws/certs
- Move the certificate files to the certs directory:
sudo mv key.pem cert.pem /usr/local/lsws/certs
- Install Certbot:
sudo snap install classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot
- Generate an SSL certificate using Certbot:
sudo certbot certonly --webroot -w /usr/local/lsws/example.com/html/ --agree-tos --no-eff-email --staple-ocsp --preferred-challenges http -m name@example.com -d example.com
- Generate a Diffie-Hellman group certificate:
sudo openssl dhparam -dsaparam -out /etc/ssl/certs/dhparam.pem 4096
- Check the Certbot renewal scheduler service:
sudo systemctl list-timers
- Perform a dry run of the SSL renewal process:
sudo certbot renew --dry-run
Congratulations! You have successfully installed SSL certificates on your Debian 12 server.
Step 8: Test Your Site
To test your site, create a test file in the HTML directory of your virtual host:
sudo nano /usr/local/lsws/example.com/html/index.php
Paste the following code into the file:
<html> <head> <h2>OpenLiteSpeed Server Install Test</h2> </head> <body> <?php echo '<p>Hello,</p>'; // Define PHP variables for the MySQL connection. $servername = "localhost"; $username = "testuser"; $password = "Your_Password123"; // Create a MySQL connection. $conn = mysqli_connect($servername, $username, $password); // Report if the connection fails or is successful. if (!$conn) { exit('<p>Your connection has failed.<p>' . mysqli_connect_error()); } echo '<p>You have connected successfully.</p>'; ?> </body> </html>
Save the file and exit the editor.
Now, open your browser and visit https://example.com
to see the test page. If everything is configured correctly, you should see the message “Hello, You have connected successfully.”
Congratulations! Your LOMP stack is now fully functional.
Conclusion
In this comprehensive guide, we have walked you through the step-by-step process of installing a LOMP stack on your Debian 12 server. By following these instructions, you have successfully set up OpenLiteSpeed, MariaDB, and PHP, as well as configured virtual hosts and SSL certificates. You are now well-equipped to host your websites and applications with improved performance and security.
If you need further assistance or want to explore more advanced hosting options, consider Shape.host’s SSD Linux VPS services. Shape.host offers scalable and secure cloud hosting solutions that can meet the demands of your growing business. With their reliable services and expert support, you can focus on what matters most: your online presence.
Start your journey to a high-performance LOMP stack today with Shape.host’s SSD Linux VPS services!