How to Install Apache2, PHP, MariaDB, and phpMyAdmin

This guide will show you how to install and configure Apache2, PHP, MariaDB, and phpMyAdmin on a Linux server. These are essential components for setting up a LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack, which is commonly used for hosting web applications.

Linux Apache MariaDB PHP Server

Setting Up Your LAMP Stack

The LAMP stack is a popular open-source web platform commonly used to run dynamic websites and servers. Let's break down the installation process into several clear steps.

Step 1: Update the Package List

First, update the package list to ensure you have the latest versions of the packages and their dependencies.

sudo apt update
        

Step 2: Install Apache2

Install Apache2, the web server software that will serve your web pages.

sudo apt install apache2
        

Step 3: Restart Apache2

After installation, restart Apache2 to apply any changes.

sudo systemctl restart apache2
        

Step 4: Verify Apache2 Installation

To verify that Apache2 is installed and running, open a web browser and visit your server's IP address.

http://your_server_ip
        

Step 5: Install MariaDB

Install MariaDB, a popular database server that will be used to store your web application's data.

sudo apt install mariadb-server
        

Step 6: Secure MariaDB Installation

Run the security script to improve MariaDB security by setting the root password and removing some insecure defaults.

sudo mysql_secure_installation
        

Follow the prompts:

Switch to unix_socket authentication [Y/n] n
Set root password? [Y/n] Y
(Respond with 'Y' to other prompts to secure your installation)
        

Step 7: Restart MariaDB and Apache2

Restart the MariaDB and Apache2 services to apply changes.

sudo systemctl restart mysql
sudo systemctl restart apache2
        

Step 8: Install PHP

Install PHP and the necessary modules to work with Apache2 and MariaDB.

sudo apt install php libapache2-mod-php php-mysql
        

Step 9: Verify PHP Installation

Verify the PHP installation by checking the version installed.

php -v
        

Step 10: Install phpMyAdmin

Install phpMyAdmin, a web interface for managing your MariaDB databases.

sudo apt install phpmyadmin
        

During the installation, you'll be prompted to configure some options:

After installation, you can access phpMyAdmin by visiting http://your_server_ip/phpmyadmin in your web browser.

Security Considerations

When setting up your server, keep these security considerations in mind:

Conclusion

You've successfully installed and configured Apache2, PHP, MariaDB, and phpMyAdmin on your server. You can now start hosting and managing your web applications with this LAMP stack. This setup provides a solid foundation for most web development projects, from simple blogs to complex e-commerce systems.