2 ways to install LAMP server on Ubuntu 22.04 | 20.04

Learn the easiest possible way to install the LAMP (Linux, Apache, MySQL & PHP) server on Ubuntu 22.04 LTS Jammy Jelly Fish or Ubuntu 20.04 Focal Fossa Linux using the command terminal.

Whenever it comes to having a web server for commercial purposes, the first name that comes forward is Apache. It is one of the best open-source web servers, easily available to install on any Linux system. However, many web applications require few other things apart from the Apache web servers to work properly such as WordPress – it is a PHP-based CMS. Hence, to use it on our Linux, we need a bunch of server applications.  For example to serve dynamic web pages – PHP language; for storing data MySQL/MariaDB. So, the stack of all these platforms is known as the LAMP server.

The software components are usually installed on physical or virtual servers. Static or dynamic web content can be provided with a LAMP system. Typical areas of application for LAMP-based servers are websites or online shops created with the help of content management systems (CMS).

The software components are freely available and minimize costs for the realization of the server environment. Since the software’s code is open-source, programmers can develop their extensions or make changes. LAMP servers offer a high degree of flexibility.

Variants and alternatives to LAMP

All LAMP components of the LAMP environment are replaceable. Operating systems, web servers, database management systems, and scripting languages ​​can be exchanged. Here are some alternatives of LAMP environments with OS support

WAMP (The Linux operating system has been replaced by Microsoft Windows but cannot be used for commercial purposes. Only for local development)

MAMP (The Linux operating system has been replaced by Apple’s macOS, not for commercial usage)

LAPP (The MySQL database management system has been replaced by PostgreSQL; can be used for commercial applications)

LEMP (The Apache web server is replaced by the webserver Nginx)

Steps to install LAMP server on Ubuntu 22.04 | 20.04 LTS

The commands given here can be used for other similar operating systems and versions of Ubuntu such as 18.04 including Debian.

1. Requirements

• Ubuntu 20.04 or 22.04 Linux
• At least a non-root user with sudo access
• Command Terminal
• Internet Connection

Note: Please choose the second method – Tasksel does not provide LAMP server installation anymore…

2. Install Tasksel on Ubuntu

Well, Tasksel is a program on Ubuntu available through the system repository to install Server application stacks, easily with the help of command. Hence, install it first on your Ubuntu 22.04 or 20.04 LTS system.

sudo apt install tasksel

3. Install the LAMP server on Ubuntu 22.04 or 20.04

Next, we can use the “Tasksel” command tool to easily install Apache, MySQL, and PHP. This will also start and enable all the required services. We don’t need to set up individual components of LAMP manually. Therefore, go for the given command:

sudo tasksel install lamp-server

or

To get an intuitive interface, use:

sudo tasksel

Select LAMP Server from the Intuitive Text Wizard.

Use your arrow key and select “Lamp-server” After that press the Tab key to select the OK button and then hit the Enter key.

Install LAMP server on Ubuntu 22.04 or 20.04

Wait for a few minutes and the LAMP server will be on your Ubuntu Linux.


Well, the best way is to use the APT package manager to install LAMP server components individually one by one. And also we need to enable the services manually.

4. Install Apache Webserver

As we have discussed at the beginning of the tutorial, the packages to install the Apache webserver are already available through the default system repository. Hence, running a single command can do the job.

sudo apt install apache2

Once the installation is completed, we can enable and start the webserver services.

To start and enable Apache:

sudo systemctl start apache2

And for enabling it, so that the service can run with system boot.

sudo systemctl enable apache2

To check the status of the service

sudo systemctl status apache2

5. Install MySQL/MariaDB Database Server

Using Tasksel we will get MySQL Database instead of MariaDB automatically. Hence, if you want a MariaDB Database then use the manual installation method given here.

For MySQL

sudo apt install mysql-server

To start and enable the service:

sudo systemctl enable --now mysqld

To status:

sudo systemctl status mysqld

or

For MariaDB:

For those who want MariaDB instead of MySQL, the command will be:

sudo apt install mariadb-server

Enable and Start the service:

sudo systemctl enable --now mariadb

6. Setup PHP on Ubuntu 22.04 | 20.04

The final component of the LAMP stack environment is PHP. It is a popular server-side scripting language required to run PHP-based web applications.

The given command will install the latest available PHP version in your Ubuntu operating system repository.

sudo apt install php libapache2-mod-php

Install a few common PHP extensions:

sudo apt install php-{curl,intl,zip,soap,xml,gd,mbstring,bcmath,common,mysqli}

Enable rewrite module:

sudo a2enmod rewrite

Restart Apache webserver:

sudo systemctl restart apache2

Conclusion:

So these were a few common methods to install and start working with the LAMP environment on Ubuntu 22.04 or 20.04 Linux systems using the command terminal. After setting up LAMP, you can start setting up various web applications such as Joomla, WordPress, or CRMs. Well, this guide is just meant for setting up LAMP, but there are other things as well such as setting up a virtual host, web directory, and more… that we can learn while setting up some web applications.

Other Tutorials:

How to Install LAMP on Rocky Linux 8 Server
Enable OpenSSH server on Ubuntu 22.04
How to install KDE Plasma on Debian 11 Bullseye Linux
Install Apache, MySQL, and PHP on AlmaLinux 8

5 thoughts on “2 ways to install LAMP server on Ubuntu 22.04 | 20.04”

  1. 1, No Lamp server Option with tasksel only webserver
    2. after installing mysql
    sudo systemctl enable –now mysqld
    Failed to enable unit: Unit file mysqld.service does not exist.

    Reply
  2. tasksel is “broken” in 20.04 and 22.04, it only presents a few (useless) options. I had to go to ubuntu packages and manually download tasksel and tasksel-data for focal, and then dpkg install them to avoid getting the one in the channel. It seems to work.

    It’s a big loss, since tasksel is a very usefull tool for setting up ubuntu servers.

    Reply

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.