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 update
Install httpd.
# dnf install httpd -y
Now, start Apache web server referenced by httpd
and enable runtime at system boot.
# systemctl start httpd
# systemctl enable httpd
Next, 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/tcp
Restart firewall for rules to take effect
# firewall-cmd --reload
Confirm the new firewall rules
# firewall-cmd --permanent --list-all
Output
[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 mariadb
Start MariaDB and enable it to run at system startup.
# systemctl start mysqld
# systemctl enable mysqld
Secure MariaDB and set a new root password for the database server.
# mysql_secure_installation
Now, run MariaDB and login as root with the set password.
# mysql -u root
Output:
MariaDB [(none)]>
Exit the console.
MariaDB [(none)]> EXIT
3. 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.4
Module 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-intl
Test 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.conf
Next, create a simple test.php
file at /var/www/html/
.
# nano /var/www/html/test.php
Add the following lines of code.
<?php
phpinfo();
?>
Grant Apache ownership rights to the file.
# chown -R apache.apache /var/www/html
Allow 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.