Home » DevOps » How To Install Linux, Apache, MySQL, PHP (LAMP) stack on Ubuntu 22.04

LAMP is a well-liked software stack for creating and distributing web applications. Linux, Apache, MySQL, and PHP are referred to as LAMP.

The operating system that forms the base of the stack is Linux. The web server application that runs on top of Linux and provides users with web pages is called Apache. MySQL is the open-source database software used for storing and managing data in the web application. The popular server-side programming language known as PHP is the last one used to create dynamic web pages and communicate with the MySQL database.

Because to its availability and versatility, the LAMP stack is frequently utilized. It offers a reliable framework for rapidly and effectively developing and delivering web applications.

Why set up the LAMP stack manually?

Setting up a LAMP (Linux, Apache, MySQL, PHP) stack manually is beneficial in a number of ways:

Customization: By manually configuring the LAMP stack, you have more control over the configuration of each stack component, enabling you to tailor it to your particular requirements.

Security: By carefully configuring each component of the LAMP stack, you can make sure that the necessary security safeguards, such as firewalls, access controls, and encryption, are in place to protect your website or application from online attacks.

Performance: A manual LAMP stack setup can assist you in optimizing the performance of individual component by configuring settings such as memory allocation, caching and load balancing. This leads to faster website or application performance, which improves the user experience.

Debugging: When you set up the LAMP stack manually, you gain a deeper grasp of how each component functions and interacts with the others. This may facilitate the diagnosis and debugging of any potential issues.

Compared to using pre-built solutions, manually configuring a LAMP stack can offer more flexibility, security, performance, and debugging options. Unfortunately, it takes more effort and technical know-how to set up and maintain.

Prerequisites

Before installing the LAMP stack on Ubuntu 22.04, you should have the following prerequisites:

  • A freshly installed Ubuntu 22.04 operating system with sudo privileges.
  • A stable internet connection to download and install the required software packages.
  • Update the system package repository by running the command sudo apt update in the terminal.
  • Install a text editor like Nano or Vim to edit configuration files.
  • Ensure that your firewall is configured to allow traffic on port 80 (HTTP) and 443 (HTTPS) if you plan to enable HTTPS on your website.

Once you have met these prerequisites, you can proceed with installing the LAMP stack on Ubuntu 22.04 by following a tutorial or guide.

Step 1 – Install Apache

Use the terminal to perform the following command to update the package repository:

sudo apt update

Run the following command to install Apache:

sudo apt install apache2

Run the following command to launch the Apache service when the installation is finished:

sudo systemctl start apache2

Use the following command to check the Apache service’s status:

sudo systemctl status apache2

You should receive a notification stating that the service is operational if Apache is up and running.

Enter your Ubuntu 22.04 computer’s IP address in the address bar of an open web browser. It is a good idea to have a backup plan in place in case the backup plan fails.

Step 2 – Installing MySQL

To install MySQL Server on Ubuntu 22.04, you can follow these steps:

Update the package repository by running the following command in the terminal:

sudo apt update

Run the following command to install MySQL Server:

sudo apt install mysql-server

Your choice of a root password for MySQL will be requested during installation. Choose a reliable password that you can remember for future usage.

Run the following command to launch the MySQL service when the installation is finished:

sudo systemctl start mysql

Use the command below to check the status of the MySQL service:

sudo systemctl status mysql

You should receive a notification stating that the service is operational if MySQL is up and functioning.

Run the following command to safeguard your MySQL setup:

sudo mysql_secure_installation

To create a root password, eliminate anonymous users, forbid remote root access, and eliminate test databases, simply follow the on-screen instructions.

That’s it! MySQL Server is now installed and ready for use on your Ubuntu 22.04 system. MySQL may now be used to store and manage data for your online applications.

Installing PHP 8.1

Follow these instructions to install PHP 8.1 on Ubuntu 22.04.

Run the following commands in the terminal to add the ondrej/php repository:

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Run the following command to install PHP 8.1 and the requisite PHP extensions:

sudo apt install php8.1 libapache2-mod-php8.1 php8.1-mysql php8.1-curl php8.1-json php8.1-cgi php8.1-gd php8.1-mbstring php8.1-xml php8.1-zip

When the installation is finished, use the following command to restart the Apache service:

sudo systemctl restart apache2

Create a phpinfo() file to ensure that PHP is installed and operating. Run the following command to create a file called info.php in the document root directory:

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

Add the following line to the file:

<?php phpinfo(); ?>

Save and close the file.

Open a web browser and navigate to http://your_server_IP_address/info.php. You should see a page with detailed information about your PHP installation.

That’s it! PHP 8.1 is now installed on your Ubuntu 22.04 machine and ready to be used for building dynamic web applications.

Installing phpmyadmin

The procedure to install phpMyAdmin on Ubuntu Server is pretty simple, and we’ll get started by first upgrading the package list.

# sudo apt-get update

All the packages specified in Ubuntu Server will be checked and updated by the preceding command. We will install phpMyAdmin using the command below after upgrading all of the packages.

# sudo apt-get install phpmyadmin

Running the aforementioned command will prompt the installer to select an Apache2 or Lighttpd web server for the automated default server setup. Select Apache2 and hit enter.

The installer will next ask you if you want to use the dbconfig-common tool to construct the database. After selecting Yes, hit Enter.

Enter a password, hit Enter, and then hit OK for phpMyAdmin to connect to the database.

Enter the same password when prompted, choose OK, and press Enter.

Your Ubuntu server has now been configured to use phpMyAdmin.

Create an Administrative MySQL User

Use the root user to access the MySQL shell.

# sudo mysql -u root -p

Create a new user with administrative privileges

mysql> CREATE USER 'admin'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
mysql> exit;

To change the username and password in the example above, simply swap out “admin” and “password.” The user can only access the database from the same computer that the MySQL server is operating on because it was built using the hostname “localhost.”

Conclusion

Congrats! You have now successfully installed LAMP stack on Ubuntu 22.04. It might have seen daunting in the beginning, but hopefully with this step-by-step guide, you were able to set it up manually.

Now that you have LAMP stack installed, the possibilities are endless. You can develop and deploy web applications, host websites, create databases, and more.

One key benefit of following this tutorial is that you don’t need to manually start any web server in your local system. The LAMP stack will automatically start when your system boots up, providing a seamless user experience.

Plus, you have complete control over your server and can customize it to suit your needs.

We hope this guide has been helpful to you in setting up LAMP stack on Ubuntu 22.04. We encourage you to take advantage of the flexibility and scalability that LAMP stack offers. Keep learning, keep experimenting, and keep building amazing things.

Pin It on Pinterest

Share This