How to Install Apache, MySQL, and PHP (LAMP) on AlmaLinux

The LAMP stack is a popular set of open-source software used to create a powerful web server. LAMP stands for Linux, Apache, MySQL/MariaDB, and PHP. This guide will walk you through the installation and configuration process of the LAMP stack on AlmaLinux.

Prerequisites

A user with sudo privileges.


Step 1: Update the System

Before installing any packages, update the system to the latest version.

# sudo dnf update -y

 

Step 2: Install Apache

# sudo dnf install httpd -y

Start and enable Apache to start on boot:

# sudo systemctl start httpd

# sudo systemctl enable httpd

To verify that Apache is running, open a web browser and navigate to your server’s IP address. You should see the Apache HTTP server test page.

 

Apache Log Files:For troubleshooting Apache, check the following log files:

Access log: /var/log/httpd/access_log

Error log: /var/log/httpd/error_log

 

Step 3: Install MySQL (MariaDB)

MariaDB is a drop-in replacement for MySQL and is the default database system in many Linux distributions, including AlmaLinux.

# sudo dnf install mariadb-server -y

Start and enable MariaDB to start on boot:

# sudo systemctl start mariadb

# sudo systemctl enable mariadb

Run the security script to improve the security of your MariaDB installation:

# sudo mysql_secure_installation

You will be prompted to set a root password and make several security choices. Follow the prompts to complete the setup.

 

MariaDB Log Files: For troubleshooting MariaDB, check the following log files:

General log: /var/log/mariadb/mariadb.log

Error log: /var/log/mariadb/mariadb.log

Slow query log: /var/log/mariadb/mariadb-slow.log (if enabled)

 

Step 4: Install PHP

PHP is a server-side scripting language used to create dynamic web pages.

Install PHP and some common PHP modules:

# sudo dnf install  php  php-mysqlnd  php-fpm  php-opcache  php-gd  php-xml  php-mbstring   -y

Restart Apache to load PHP:

# sudo systemctl restart httpd

 

PHP Log Files: For troubleshooting PHP, check the following log files:

PHP-FPM log: /var/log/php-fpm/error.log

PHP error log: This can be configured in your php.ini file, typically located at /etc/php.ini.

You can set the error_log directive to specify the path of the PHP error log file.

 

Step 5: Test PHP

To ensure PHP is working correctly with Apache, create a test PHP file:

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

Add the following PHP code:

~~~~~~~~~~~~~~~~~~~

php
Copy code

phpinfo();
?>

~~~~~~~~~~~~~~~~~~~~

Save and close the file.

Then, open a web browser and navigate to http://your_server_ip/info.php. You should see the PHP information page, confirming that PHP is installed and working correctly.

 

Step 6: Adjust Firewall Settings

If you have a firewall enabled, you'll need to allow traffic on HTTP (port 80) and HTTPS (port 443) to access your web server.

# sudo firewall-cmd --permanent --add-service=http

# sudo firewall-cmd --permanent --add-service=https

# sudo firewall-cmd --reload

By following this guide, you should have a fully functional LAMP stack on AlmaLinux, ready to host dynamic and database-driven websites.

 


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 1120