How to Install LAMP Stack on Linux Mint

Installing Apache requires the installation of a complete LAMP package (Linux, Apache, MySQL and, PHP). To do development, users require a complete set of these open-source software and a locally set up machine before they can host their websites to test it out.  We will go through the complete installation of the LAMP stack on Linux Mint 20.

Updating the Linux mint 20 system

The first step is to update the OS by running the following command through the terminal window:

$ sudo apt-get update

The system will prompt to enter the password.

Now, check for the available apt updates and get them in the Linux system using:

$ sudo apt-get upgrade

Next, update the packages using the following command:

$ sudo apt-get dist-upgrade

This upgrade might take some time. Once done, you need to reboot the system to get the updates done using:

$ sudo reboot

Installation of the LAMP server

After that, install the LAMP server in the system. Type the command given below to start the process of installation:

$ sudo apt-get install lamp-server^

You need to end it with the caret (^). The system will prompt and ask for the permission of the user. Append Y and then press enter from the keyboard.

Testing the installation of Apache webserver

Apache is the webserver of the LAMP stack and once installed to confirm the installation type the following in the terminal window:

$ sudo systemctl status apache2

This command will tell whether Apache is running or not. If you see an output like this one then it means it is installed correctly.

We can also check the installation confirmation from the browser. Type http://localhost on the window of your browser. Once done, you will see an output like the one shown below. It will confirm that the Apache server is installed correctly. You can add more web pages. Apache2 web page runs in the path /var/www/html.

To update the content, make changes in the index.html page.

Testing the installation of PHP

PHP is the scripting language used in the LAMP stack. Now we need to verify the installation of PHP by creating a file info.php in /var/www/html path.

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

The nano text editor will open up an empty file info.php, type the following script in the file. and then press Ctl+O to save the file. To exit use Ctl+X.

<?php phpinfo(); ?>

Once done, restart the Apache2 server to ensure that the changes have been done.

Type http://localhost/info.php in the browser window. If PHP is installed correctly and output like this one will appear. This output will have the information about the Linyx environment and has configuration files.

Setting up MySQL root password

Go to the terminal and then log in to MySQL. Set up the password and then exit it.

Enter the command:

$ sudo mysql -u root

The terminal has now changed the prompt sign from $ to <. This means users have entered mysql and can make changes in the database.

Once updates have been done, type quit

Now, restart MySQL to save any changes made (like password) etc by using:

$ sudo systemctl restart mysql

Installing phpMyAdmin

MySQL command line is the tool for people who have hands-on experience of MySQL commands. On the other hand, PhpMyAdmin is GUI based method for the management of different databases. It is not part of our LAMP stack but is used to manage MySQL database. Return to the terminal window and use this command to install phpMyAdmin:

$ sudo apt-get install phpMyAdmin

Press the enter key when prompted. You need to press spacebar from the keyboard to select apache2.

Once you have selected the web server, the system will ask for your permission to configure the database. Press the enter key from the keyboard to choose Yes.

Users will then be prompted to provide phpMyAdmin password. Provide the password then confirm the password in the next dialogue box.

Once you have provided the password, you need to confirm it. Renter the password and then hit enter. The process of installation will continue.

Accessing PhpMyAdmin portal

To access PhpMyAdmin, type localhost/phpmyadmin. This will open up the login page. Provide the credentials and continue. The password is the one that was set earlier.

After you have logged in to phpmyadmin dashboard you can create and manage all databases.

Uninstalling Apache from the system

To uninstall Apache, simply type the following command in the system:

dpkg-l *apache* *mysql* phpmyadmin | grep ^ii | awk '{print $2 }' | xargs sudo apt-get -y purge --auto-remove

The uninstallation will begin similar to the one given below:

Conclusion

The tutorial covered the entire method of installation of the Apache web server. We tested the entire LAMP stack in the system and executed the testing for each of the steps. At last, we tested it on PhpMyAdmin and then went through the method of uninstallation of the system.