Categories: LinuxUbuntu

How do I Install LOMP Stack on Ubuntu

The LOMP stack, also known as Linux, OpenLiteSpeed, MariaDB and PHP, is an open source software stack that allows you to host high-performance websites. It provides the LSPHP (LiteSpeed PHP) interpreter to serve dynamic PHP pages via its proprietary LS-API. OpenLiteSpeed is known for its fast performance and is the best option to host PHP-based applications with dynamic content.

In this article, we will show you how to install the LOMP stack on Ubuntu 22.04.

Requirements

  • A server running Ubuntu 22.04.
  • A valid domain name that points to the IP of your server.
  • A root password is configured on the server.

First steps

Before you get started, you should update and upgrade all software packages to the latest version. You can update all packages by executing the following command:

apt update -y
apt upgrade -y

Once all packages are updated, you can proceed to the next step.

Configure the UFW firewall

If the UFW firewall is installed and running on your system, you must allow OpenLiteSpeed ports for external access.

You can allow all ports with the following command:

ufw allow 7080/tcp
ufw allow 80/tcp
ufw allow 443
ufw allow 8088/tcp

Now you can check the added rules with the following command:

ufw status

You should see the following output:

Status: active

To                                Action      From
--                                ------      ----
OpenSSH                           ALLOW       Anywhere
80,443,7080,8088/tcp              ALLOW       Anywhere
OpenSSH (v6)                      ALLOW       Anywhere (v6)
80,443,7080,8088/tcp (v6)         ALLOW       Anywhere (v6)

Once you are done, you can proceed to the next step.

Install OpenLiteSpeed

By default, the OpenLiteSpeed package is not included in the Ubuntu default repository. Therefore, you need to add the OpenLiteSpeed repository to your system. You can add it by running the following script:

wget -O - http://rpms.litespeedtech.com/debian/enable_lst_debian_repo.sh | bash

Once the OpenLiteSpeed repository is added, you can install it with the following command:

apt install openlitespeed -y

Once OpenLiteSpeed is installed, you can check the status of OpenLiteSpeed with the following command:

systemctl status lsws

You should see the following output:

? lshttpd.service - OpenLiteSpeed HTTP Server
     Loaded: loaded (/etc/systemd/system/lshttpd.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2022-11-12 14:43:04 UTC; 15s ago
    Process: 29721 ExecStart=/usr/local/lsws/bin/lswsctrl start (code=exited, status=0/SUCCESS)
   Main PID: 29750 (litespeed)
     CGroup: /system.slice/lshttpd.service
             ??29750 "openlitespeed (lshttpd - main)"
             ??29759 "openlitespeed (lscgid)"
             ??29788 "openlitespeed (lshttpd - #01)"
             ??29789 "openlitespeed (lshttpd - #02)"
             ??29790 lsphp "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Nov 12 14:43:01 ubuntu22041 systemd[1]: Starting OpenLiteSpeed HTTP Server...
Nov 12 14:43:02 ubuntu22041 lswsctrl[29721]: [OK] litespeed: pid=29750.
Nov 12 14:43:04 ubuntu22041 systemd[1]: Started OpenLiteSpeed HTTP Server.

You can now access the OpenLiteSpeed default page via the URL http://your-server-ip:8088 . You should see the following screen:

When you're done, you can proceed to the next step.

Install MariaDB Server

MariaDB is an open source database management system that you can use to store, retrieve and manage data for your website and application. You can install the MariaDB server with the following command:

apt install mariadb-server -y

After installation, start the MariaDB service and activate it so that it starts when the system restarts:

systemctl start mariadb
systemctl enable mariadb

Next, you must also set a MariaDB root password and save the installation. You can do this with the following command:

mysql_secure_installation

Answer all the questions as shown below:

Enter current password for root (enter for none):
Set root password? [Y/n]: N
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]:  Y
Reload privilege tables now? [Y/n]:  Y

When you're done with that, you can proceed to the next step.

Install PHP 8.1

By default, the OpenLiteSpeed web server is delivered with version PHP 7.4. You can check this at the URL http://your-server-ip:8088/phpinfo.php. You should see the following page:

OpenLiteSpeed also allows you to install a specific PHP version on your system. You can use the following command to search all available PHP versions:

apt-cache search lsphp

You should see all PHP versions in the following output:

lsphp80-pspell - pspell module for PHP
lsphp80-redis - PHP extension for interfacing with Redis
lsphp80-snmp - SNMP module for PHP
lsphp80-sqlite3 - SQLite3 module for PHP
lsphp80-sybase - Sybase module for PHP
lsphp80-tidy - tidy module for PHP
lsphp81 - server-side, HTML-embedded scripting language (LSAPI binary)
lsphp81-apcu - APC User Cache for PHP
lsphp81-common - Common files for packages built from the PHP source
lsphp81-curl - CURL module for PHP
lsphp81-dbg - Debug symbols for LSPHP70
lsphp81-dev - Files for PHP70 module development
lsphp81-igbinary - igbinary PHP serializer
lsphp81-imagick - Provides a wrapper to the ImageMagick library
lsphp81-imap - IMAP module for PHP
lsphp81-intl - Internationalisation module for PHP
lsphp81-ldap - LDAP module for PHP
lsphp81-memcached - memcached extension module for PHP, uses libmemcached
lsphp81-modules-source - PHP 70 modules source package
lsphp81-msgpack - PHP extension for interfacing with MessagePack
lsphp81-mysql - MySQL module for PHP
lsphp81-opcache - Zend OpCache module for PHP
lsphp81-pear - Provides PHP PEAR package
lsphp81-pgsql - PostgreSQL module for PHP
lsphp81-pspell - pspell module for PHP
lsphp81-redis - PHP extension for interfacing with Redis
lsphp81-snmp - SNMP module for PHP
lsphp81-sqlite3 - SQLite3 module for PHP
lsphp81-sybase - Sybase module for PHP
lsphp81-tidy - tidy module for PHP

Now install the PHP 8.1 version with other extensions using the following command:

apt install lsphp81 lsphp81-common lsphp81-mysql -y

Once the PHP 8.1 version is installed, you can proceed to the next step.

Set OpenLiteSpeed admin password

By default, the OpenLiteSpeed administration interface is not secured with user-based authentication. Therefore, it is advisable to set the admin user and password. You can set them with the following command:

/usr/local/lsws/admin/misc/admpass.sh

Set your admin username and password as shown below:

Please specify the user name of administrator.
This is the user name required to login the administration Web interface.

User name [admin]: 

Please specify the administrator's password.
This is the password required to login the administration Web interface.

Password: 
Retype password: 
Administrator's username/password is updated successfully!

Configure OpenLiteSpeed to use PHP8.1

By default, OpenLiteSpeed is configured to use the PHP 7.4 version. Therefore, you need to configure OpenLiteSpeed to use PHP 8.1 as the default version.

First, access the OpenLiteSpeed administration interface via the URL http://your-server-ip:7080. You should see the OpenLiteSpeed login page:

Enter your admin username and password and click the Login button. On the following page, you should see the OpenLiteSpeed dashboard:

Next, click on Server Configuration => External App. You should see the following page:

Click on the " Edit " button in the " Actions " column. You should see the following page:

Scroll down to the Command field and change the value from lsphp74/bin/lsphp to lsphp81/bin/lsphp. Then click on the Save button on the right-hand side to save the changes. Then click on the green Graceful Restart button at the top right to restart the web server.

Now open your web browser and check the new PHP version at the URL http://your-server-ip:8088/phpinfo.php. You should see PHP 8.1 on the following page:

Conclusion

Congratulations! You have successfully installed the LOMP stack on the Ubuntu 22.04 server. You can now start creating and deploying fast and powerful web applications on the LOMP stack. If you have any questions, please feel free to contact me.

Vitux Staff

Recent Posts

How to Install Magento 2 on AlmaLinux

Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…

1 year ago

How to Install ISPConfig Hosting Control Panel with Apache Web Server on Ubuntu 24.04

ISPConfig is an open-source control panel that allows users to manage multiple servers from a…

1 year ago

How to Test your Email Server (SMTP) Using the Telnet Command

As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…

1 year ago

Managing Network Interfaces and Settings on Ubuntu 24.04 with nmcli

Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…

2 years ago

Using Restic Backup on Ubuntu 24.04

Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…

2 years ago

Installing phpMyAdmin on Rocky Linux 9 and Securing it with Let’s Encrypt SSL

phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…

2 years ago