LAMP stack is a collection of open-source software installed together to enable a server to host and run modern web applications written in server-side languages like PHP. LAMP is an acronym for Linux, Apache, MySQL/MariaDB, and PHP that work together to serve dynamic web content hosted on a server.
In this article, you will install LAMP on a Rocky Linux server.
Prerequisites
- Deploy a new Rcs Rocky Linux instance
- Log in to the server with SSH
1. Install Apache
To install Apache, update the system, then install the httpd package.
Update the server.
# dnf updateInstall httpd.
# dnf install httpd -yNow, start Apache web server referenced by httpd and enable runtime at system boot.
# systemctl start httpd
    
# systemctl enable httpdNext, add new firewalld rules to allow http, https traffic, and open port 80 on your server.
# firewall-cmd --permanent --zone=public --add-service=http
    
# firewall-cmd --permanent --zone=public --add-service=https
    
# firewall-cmd --permanent --zone=public --add-port=80/tcpRestart firewall for rules to take effect
# firewall-cmd --reloadConfirm the new firewall rules
# firewall-cmd --permanent --list-allOutput
[root@example ~]# firewall-cmd --list-all
public
  target: default
 icmp-block-inversion: no
  interfaces: 
  sources: 
  services: cockpit dhcpv6-client http https ssh
  ports: 8080/tcp 80/tcp
  protocols: 
  forward: no
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: Test your Apache installation by visiting your Server IP address.
http://SERVER_IP_ADDRESS
2. Install MariaDB
MariaDB is a substitute for MySQL with the same table types, schema, and usage commands. MariaDB is available in Rocky Linux sources by default, so you can install it with the following command.
# dnf install mariadbStart MariaDB and enable it to run at system startup.
# systemctl start mysqld
# systemctl enable mysqldSecure MariaDB and set a new root password for the database server.
# mysql_secure_installationNow, run MariaDB and login as root with the set password.
# mysql -u rootOutput:
MariaDB [(none)]> Exit the console.
MariaDB [(none)]> EXIT3. Install PHP
Install PHP. You can change your intended version by specifying the version number after the php: module parameter. In this article, you will install PHP 7.4 as shown.
# dnf module install php:7.4Module packages including php-cli, php-common,php-fpm,php-mbstring will be automatically installed during the process
Install other commonly required PHP extensions, php-mysqlnd creates a connection to the database server.
# dnf install php-mysqlnd php-gd php-intlTest PHP functionality with Apache
First, open the default Apache welcome.conf file and comment out all lines in it using #.
# nano /etc/httpd/conf.d/welcome.confNext, create a simple test.php file at /var/www/html/.
# nano /var/www/html/test.phpAdd the following lines of code.
<?php
phpinfo();
?>Grant Apache ownership rights to the file.
# chown -R apache.apache /var/www/htmlAllow execution of files by httpd in the /var/www/html/ directory with an SE Linux policy exception.
# chcon -R -t httpd_sys_content_t html/In a web browser, visit your Server IP and load test.php.
http://SERVER_IP/test.php
Conclusion
In this article, you installed LAMP on a Rocky Linux server; once set, you can build dynamic websites or install a content management system (CMS) for production use.
