LAMP stands for Linux, Apache, MySQL, PHP/Perl/Python and here we learn how to install LAMP on AlmaLinux 8. We recommend AlmaLinux 8 because it is a very popular free enterprise Linux distribution, a CentOS Linux alternative.
Summary
- Create a Scalable VPS with AlmaLinux 8
- Connect to your VPS Cloud Server via SSH
- Install Apache HTTP Server
- Then Install MySQL or MariaDB Server
- Finally Install PHP
- Test the LAMP stack
- Transfer files and start using your LAMP stack
Installing Apache HTTP Server
- Perform a system update first by using the following command. This ensures the system installed packages are in their latest state as well as rebuild the system repository cache:
dnf update
- To install Apache webserver in AlmaLinux 8, simply execute the following command:
dnf install httpd httpd-tools
- Once Apache webserver is installed, run the following command to start the Apache HTTP server
systemctl start httpd
- To ensure that Apache webserver will be started each time you restart your server, run this command:
systemctl enable httpd
- Finally, check the status of Apache webserver to ensure everything runs smoothly:
systemctl status httpd
- Now, you will need to make sure Apache webserver is accessible externally from the internet. Run this command to enable Port 80 (for http) on your firewall:
firewall-cmd --permanent --zone=public --add-service=http
- You will also need to enable Port 443 (for https) on your firewall:
firewall-cmd --permanent --zone=public --add-service=https
- Reload firewall for these changes to take effect:
firewall-cmd --reload
- Test Apache webserver by loading your website (http://expertvm-server-ip-address) to confirm that the following page can be seen:
Installing MySQL or MariaDB Server
- Depending on your preference, use either one of the following command lines:To install MySQL
dnf install mysql-server mysql
To install MariaDB
dnf install mariadb-server mariadb
- Use these commands to start the database servers and to ensure the service will be started automatically after a server reboot:For MySQL
systemctl start mysql systemctl enable mysql
For MariaDB
systemctl start mariadb systemctl enable mariadb
- Check the status of the database servers:For MySQL
systemctl status mysql
For MariaDB
systemctl status mariadb
- Secure MySQL or MariaDB database installation using the following command (it is the same regardless of your choice of database server):
mysql_secure_installation
- Follow through the on-screen instructions to complete the secure installation process.
Installing PHP on AlmaLinux 8
- Run the following command to check the PHP versions that are available
dnf module list php
- At the time of writing this blog, you may only be able to see PHP 7.x. If you wish to install PHP 8, run the following commands to include the Remi Repository, perform system update and then you will be able to see PHP 8 available this time:
dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm dnf update dnf module list php
- Run the following commands to set your preferred PHP version as the default one:
For PHP 7.4dnf module reset php dnf module enable php:7.4
For PHP 8.0
dnf module reset php dnf module enable php:remi-8.0
- Run the following command to enable the common PHP extensions
dnf install php php-common php-opcache php-cli php-gd php-curl php-mysqlnd
- For better performance, enable PHP-FPM (FastCGI Process Manager) using the below command:
systemctl start php-fpm systemctl enable php-fpm
- Restart Apache HTTP server:
systemctl restart httpd
Conclusions
This tutorial shows you how to install LAMP on AlmaLinux 8. Enjoy hosting your own website within your own server environment!