AlmaLinux 9 is a widespread Linux distribution that sеrvеs as a rеplacеmеnt for CеntOS. It is widеly usеd for hostinG wеbsitеs anD applications duе to its stability and sеcurity fеaturеs. One of thе kеy componеnts rеquirеd for hosting wеb applications is thе LAMP stack. LAMP stands for Linux, Apachе, MySQL, and PHP, which arе thе building blocks of a wеb sеrvеr. This article will guide you through installing the LAMP stack on AlmaLinux 9.
Installing Apache
Installing the Apache web server is the first step in setting up the LAMP stack. Apache is a widely used web server that powers many websites. To install Apache on AlmaLinux 9, follow the steps below:
Update the system packages by running the following command in the terminal:
sudo dnf update
Install the Apache web server by running the following command:
sudo dnf install httpd
Start the Apache service and enable it to start automatically on boot by running the following commands:
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
Verify the installation by accessing your server's IP address or domain name in a web browser. You should see the default Apache landing page.
Congratulations! You have successfully installed Apache on AlmaLinux 9. Let's move on to the next step.
Installing MySQL
MySQL is a popular open-source relational database management system that stores and retrieves data for web applications. To install MySQL on AlmaLinux 9, follow the steps below:
Install the MySQL community edition repository by running the following command:
sudo dnf install
https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
Install the MySQL server by running the following command:
sudo dnf install mysql-server
Start the MySQL service and enable it to start automatically on boot by running the following commands:
sudo systemctl start mysqld
sudo systemctl enable mysqld
sudo systemctl status mysqld
Secure the MySQL installation by running the following command and following the prompts:
sudo mysql_secure_installation
Verify the installation by logging into the MySQL server with the following command:
sudo mysql -u root -p
MySQL is now installed on your AlmaLinux 9 server. Let's proceed to the next step.
Installing PHP
PHP is a popular server-side scripting language used to build dynamic web pages. To install PHP on AlmaLinux 9, follow the steps below:
Install the PHP packages and dependencies by running the following command:
sudo dnf install php php-mysqlnd php-json php-xml php-zip php-gd php-mbstring php-curl
Verify the installation by creating a PHP info file. Create a new file named info.php in the Apache web root directory with the following command:
sudo nano /var/www/html/info.php
Add the following lines to the file and save it:
<?php
phpinfo();
?>
You can access the PHP info file in a web browser by visiting: http://your_server_ip/info.php.
YYou should see a page displaying information about your PHP installation.
PHP is now installed and working on your AlmaLinux 9 server. Let's move on to the final step.
Testing the LAMP Stack
Now that you have installed Apache, MySQL, and PHP, it's time to test the LAMP stack. Follow the steps below to create a test PHP file that connects to the MySQL database:
Create a new file named test.php in the Apache web root directory with the following command:
sudo nano /var/www/html/test.php
Add the following lines to the file and save it:
<?php
$servername = "localhost";
$username = "root";
$password = "your_mysql_root_password";
// Create a connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
// Close the connection
$conn->close();
?>
Access the test file in a web browser by visiting http://your_server_ip/test.php.
You should see a message saying "Connected successfully" if the PHP script is successfully connected to the MySQL database.
Congratulations! You have successfully installed the LAMP stack on your AlmaLinux 9 server, and you are now ready to start hosting your websites and applications.
Conclusion
In this article, we have walkеd you through the process of installing thе LAMP stack on AlmaLinux 9. Wе started by installing Apachе, followed by MySQL and PHP. Wе thеn tеstеd thе LAMP stack by crеating a PHP filе that connеcts to thе MySQL databasе. Now that you have a fully functional LAMP stack, you can start hosting your wеbsitеs and applications with еasе.