How to Install LAMP Stack on CentOS 7 Without a Control Panel
When you want to set up a web hosting environment on a CentOS 7 server without using a control panel. This article explains how to install and configure the LAMP stack (Linux, Apache, MariaDB, and PHP).
Overview
The LAMP stack is the base set of applications that most websites running on a Linux server are served from and is commonly referred to as “LAMP”.
L - Linux
A - Apache
M - MariaDB
P - PHP
To ensure ease of installation, we’ll use the root user to install the services. You can use an alternate system user if you choose, but you will need to prepend sudo to the following commands in order for them to install or interact with the software.
Installing LAMP:
L - Linux
The first part of the stack is Linux. You need to select the operating system as CentOS 7 when purchasing the VPS/Dedicated server. On doing so, CentOs 7 will be pre-installed and there is no need to worry about installing it or make any modifications.
Pre-launch Steps:
To check which Linux distribution you are running, use this command:
[root@lampsetup~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
It’s now time to verify that our yum environment is clean and up to date, we’ll do this by cleaning all of the yum cache, and update yum using:
[root@lampsetup ~]# yum clean all
[root@lampsetup ~]# yum update
A - Apache
Install the Apache httpd service binary package provided form official repositories using the following command.
[root@lampsetup ~]# yum install httpd -y
After yum manager finishes installation, use the following commands to manage Apache daemon, since RHEL and CentOS 7.0 both migrated their init scripts from SysV to systemd – you can also use SysV and Apache scripts the same time to manage the service.
[root@lampsetup ~]# systemctl start httpd.service
If you need Apache service to be automatically started after reboot issue the following commands to enable them system-wide.
[root@lampsetup ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@lampsetup ~]# systemctl reload httpd
Check if port 80 is open:
https://www.yougetsignal.com/tools/open-ports/
If the port is not open yet, run the below commands to open port 80
[root@lampsetup ~]# firewall-cmd --permanent --add-service=http
success
[root@lampsetup ~]# systemctl restart firewalld
[root@lampsetup ~]#
Verify if port 80 is now open:
https://www.yougetsignal.com/tools/open-ports/
To verify Apache functionality open a remote browser and type your server IP Address using HTTP protocol on URL (http://server_IP), and a default page should appear like in the screenshot below.

For now, Apache DocumentRoot path it’s set to /var/www/html system path, which by default doesn’t provide any index file. You can tweak the apache configuration file /etc/httpd/conf/httpd.conf to change the document root as required.
After making any required changes to the configuration file, restart Apache service to reflect changes and reload your browser page to see the final result.
[root@lampsetup ~]# systemctl restart httpd
M - MariaDB
Red Hat Enterprise Linux/CentOS 7.0 switched from MySQL to MariaDB for its default database management system. To install MariaDB database use the following command.
[root@lampsetup ~]# yum install mariadb-server mariadb -y
[root@lampsetup ~]# systemctl start mariadb
If you need MariaDB service to be automatically started after reboot issue the following commands to enable them system-wide.
[root@lampsetup ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
After the MariaDB package is installed, start database daemon and use mysql_secure_installation script to secure database (set root password, disable remotely logon from root, remove test database and remove anonymous users).
[root@lampsetup ~]# mysql_secure_installation
Press ENTER below
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] Y
... Success!
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
P - PHP
First of all, you need to enable Remi and EPEL yum repositories on your system. The EPEL repo should be preinstalled on your system. If not, use the following command to install it:
[root@lampsetup ~]# yum install epel-release
Also, install the REMI repository using the following command:
[root@lampsetup ~]# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
Your system is prepared for the PHP installation from yum repositories. Use one of the following commands to install PHP 7.4 or PHP 7.3 or PHP 7.2 or PHP 7.1 on your system based on your requirements.
## Install PHP 7.4
[root@lampsetup ~]# yum --enablerepo=remi-php74 install php
## Install PHP 7.3
[root@lampsetup ~]# yum --enablerepo=remi-php73 install php
Check if PHP has been installed correctly.
[root@lampsetup ~]# php -v
PHP 7.4.2 (cli) (built: Jan 21 2020 11:35:20) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
You may also need to install additional PHP modules based on your application requirements. The below command will install some more useful PHP modules.
### For PHP 7.4
[root@lampsetup ~]# yum --enablerepo=remi-php74 install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json
In the above command, you can change the PHP version as per your requirements.
Now, Create a info.php file to check if PHP is functional:
[root@lampsetup ~]# echo "<?php phpinfo(); ?>" > /var/www/html/info.php
[root@lampsetup ~]# systemctl restart httpd
