The LAMP stack is a popular open-source software suite used to host dynamic web applications. The acronym stands for Linux, Apache, MySQL, and PHP. This guide will walk you through the process of installing and configuring the LAMP stack on an AlmaLinux 8.10 system.
Prerequisites
Before you begin, ensure you have:
- A running AlmaLinux 8.10 system
- A user account with sudo privileges
- Internet connectivity to download packages
Step 1: Update Your System
First, update your system to ensure all existing packages are up to date.
$ sudo dnf update -y
Step 2: Install and Configure Apache
Install Apache
Apache is a widely-used web server. Install it using the following command:
$ sudo dnf install httpd -y
Start and Enable Apache
Start and enable Apache to run at boot:
$ sudo systemctl start httpd
$ sudo systemctl enable httpd
Configure Firewall for Apache
Allow HTTP and HTTPS traffic through the firewall:
$ sudo firewall-cmd --permanent --add-service=http
$ sudo firewall-cmd --permanent --add-service=https
$ sudo firewall-cmd --reload
Verify Apache Installation
Open a web browser and navigate to your server’s IP address. You should see the Apache test page indicating that Apache is installed and running correctly.
Step 3: Install and Configure MySQL
Install MySQL
MySQL is a powerful database management system. Install it using the following command:
$ sudo dnf install mysql-server -y
Start and Enable MySQL
Start and enable MySQL to run at boot:
$ sudo systemctl start mysqld
$ sudo systemctl enable mysqld
Secure MySQL Installation
Run the security script to remove insecure default settings:
$ sudo mysql_secure_installation
Follow the prompts to set a root password, remove anonymous users, disallow root login remotely, remove the test database, and reload the privilege tables.
Verify MySQL Installation
Log into MySQL to verify it is working:
$ mysql -u root -p
You should see the MySQL prompt, indicating that the installation was successful.
Step 4: Install and Configure PHP
Install PHP
PHP is a server-side scripting language used for web development. Install PHP and the necessary modules:
$ sudo dnf install php php-mysqlnd php-fpm php-opcache php-gd php-xml php-mbstring php-json php-cli -y
Configure PHP
To ensure PHP works with Apache, you need to restart Apache:
$ sudo systemctl restart httpd
Test PHP Configuration
To test PHP, create a simple PHP file in the web root directory:
$ echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
Open a web browser and navigate to http://your_server_ip/info.php
. You should see the PHP info page, indicating that PHP is working correctly with Apache.
Step 5: Additional Configuration (Optional)
Configure Apache Virtual Hosts
To host multiple websites, configure Apache virtual hosts. Create a new configuration file for each site in /etc/httpd/conf.d/
.
$ sudo nano /etc/httpd/conf.d/yourdomain.conf
Add the following configuration:
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain
ErrorLog /var/log/httpd/yourdomain-error.log
CustomLog /var/log/httpd/yourdomain-access.log combined
</VirtualHost>
Create the document root directory and set permissions:
$ sudo mkdir -p /var/www/yourdomain
$ sudo chown -R apache:apache /var/www/yourdomain
Restart Apache to apply the changes:
$ sudo systemctl restart httpd
Create a MySQL Database
Log into MySQL and create a database and user for your web application:
$ mysql -u root -p
In the MySQL shell, execute the following commands:
CREATE DATABASE yourdatabase;
CREATE USER 'youruser'@'localhost' IDENTIFIED BY 'yourpassword';
GRANT ALL PRIVILEGES ON yourdatabase.* TO 'youruser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Conclusion
You have successfully installed and configured the LAMP stack on your AlmaLinux 8.10 system. Your server is now ready to host dynamic web applications using Apache, MySQL, and PHP. For more detailed configurations and optimizations, refer to the official documentation of each component:
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.