This guide demonstrates how to install LAMP Stack on CentOS 7.
1. Installing Apache Web Server
Apache web server is one of the most popular web servers in the world, there active community and detailed documentation over server eventually makes it a great choice for hosting a website.
Install Apache using ( Yellowdog Updater, Modified )
sudo (Super User DO) command allows you to run programs with the security privileges.
sudo yum update
sudo yum install httpd -y
Once the installation is completed, enable and start the Apache service.
sudo systemctl enable httpd
sudo systemctl start httpd
systemctl enable firewalld
systemctl start firewalld
Check the Status of Firewalld
systemctl status firewalld
If your server is protected by the firewall and you haven’t opened the
HTTPS ports. Enable them with the following command.
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
To verify that the change was applied, you can run:
sudo firewall-cmd --permanent --list-all
You’ll see output like this:
Output public target: default icmp-block-inversion: no interfaces: sources: services: cockpit dhcpv6-client http https ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
You’ll need to reload the firewall configuration so the changes take effect:
sudo firewall-cmd --reload
Now you can verify Apache installation. Every process in Apache is managed with the
systemctl command. Verify the installation of Apache with the following command.
sudo systemctl status httpd
httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset> Active: active (running) since Mon 2020-09-07 13:09:19 CST; 8min ago Docs: man:httpd.service(8) Main PID: 73176 (httpd) Status: "Total requests: 6; Idle/Busy workers 100/0;Requests/sec: 0.0116; Byt> Tasks: 213 (limit: 5045) Memory: 19.6M CGroup: /system.slice/httpd.service ├─73176 /usr/sbin/httpd -DFOREGROUND ├─73177 /usr/sbin/httpd -DFOREGROUND ├─73178 /usr/sbin/httpd -DFOREGROUND ├─73179 /usr/sbin/httpd -DFOREGROUND └─73180 /usr/sbin/httpd -DFOREGROUND Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ systemd: Starting The Apache HTTP Ser> Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ httpd: AH00558: httpd: Could not > Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ systemd: Started The Apache HTTP Serv> Sep 07 13:09:19 iZa2dc2w6sz7gbkh2kc8exZ httpd: Server configured, listeni>
You can check which IP address is accessible, by running the following command:
curl -4 icanhazip.com
Type the IP address that you receive in your web browser and it will take you to Apache’s default landing page:
2. Install MySQL/MariaDB Database
The third layer of the LAMP stack is MySQL or MariaDB. Both are open-source database management systems used for storing and managing data on your website.
sudo yum install mariadb-server mariadb -y
When the installation is complete, we need to start MariaDB with the following command:
sudo systemctl start mariadb
After completing the installation, enable the MySQL service to auto-start on the system start. Also start service manually for the first time.
sudo systemctl enable mariadb.service
sudo systemctl start mariadb.service
Then check the service current status using the following command:
sudo systemctl status mariadb.service
mariadb.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2020-10-06 14:31:53 CST; 15min ago Main PID: 26834 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─26834 /bin/sh /usr/bin/mysqld_safe --basedir=/usr └─26997 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysq... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mariadb-prepare-db-dir: MySQL ... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mariadb-prepare-db-dir: Please... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mariadb-prepare-db-dir: The la... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mariadb-prepare-db-dir: You ca... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mariadb-prepare-db-dir: http:/... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mariadb-prepare-db-dir: Consid... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mariadb-prepare-db-dir: https:... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mysqld_safe: 201006 14:31:51 m... Oct 06 14:31:51 iZa2dc2w6sz7gbkh2kc8exZ mysqld_safe: 201006 14:31:51 m... Oct 06 14:31:53 iZa2dc2w6sz7gbkh2kc8exZ systemd: Started MariaDB database ... Hint: Some lines were ellipsized, use -l to show in full.
The MySQL installation has been completed. Now you can connect the MySQL server without any password but we recommend securing the MySQL installation. The MySQL packages provide mysql_secure_installation command to apply the security. Just run the below command on terminal:
and follow the on-screen instructions. Below are the details which require user input.
- Press y|Y for Yes, any other key for No: y
- Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
- New password: [ENTER STRONG PASSWORD HERE]
- Re-enter new password: RE ENTER PASSWORD HERE
- Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
- Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
- Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
- Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
- Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
5: Install PHP
Finally you can install PHP, by default CentOS ships with PHP 7.2. So you can install PHP using the following command.
sudo yum install -y php php-mysql
After the installation is finished, you’ll need to restart the Apache web server in order to enable the PHP module:sudo systemctl restart httpd
6: Verify the LAMP setup
Create a new file with the name
sudo nano /var/www/html/info.php
Paste the following code in the editor and save the file.
CTRL + X followed by
Enter to save and exit the file.
Now open your browser and point it to your external IP address of your server followed by info.php in the URL.
You will see the PHP information which indicates you have installed and configured Apache, MariaDB and PHP on your CentOS 7 server.
Now that we have installed LAMP STACK, you can now host your website in the server. One of the popular thing you can do is install WordPress and design your own website or blog for your business.
To manage MySQL with GUI, we need to install phpMyAdmin. Operations such as the management of databases, tables, indexes, permissions, and so on are executed with the graphical user interface of phpMyAdmin.
Hope this tutorial is helpful and comment down if you have any query or issue.