How To Install Linux, Apache, MariaDB, PHP (LAMP Stack) on CentOS 7 / RHEL 7
In CentOS, MySQL is now replaced by MariaDB as a default database.
Here is the article about Step by Step installation of CentOS 7 / RHEL 7. Now you have Linux, and the next is to install Apache, MySQL, and PHP on it.
Let’s install one by one.
Open up a terminal and switch to root user.
$ su -
yum install -y httpd
Start the Apache service by using the following command.
systemctl start httpd
To make the Apache web server to start automatically during every boot. Type the following on terminal and hit Enter.
systemctl enable httpd
Configure the firewall to allow HTTP requests.
firewall-cmd --permanent --add-port=80/tcp firewall-cmd --reload
To make sure everything installed correctly we will now test Apache to ensure it is working correctly. Open up any web browser and then enter the following into the web address:
You will get the web page saying “Testing 123”, this confirms that the Apache is working fine.
/var/www/htmlon CentOS, and the main configuration file is
/etc/httpd/conf/httpd.conf. Additional configurations for Apache are stored in the
Next is to install the MariaDB. Type the following command and then press enter.
yum install -y mariadb mariadb-server
Start the MariaDB service using the below command.
systemctl start mariadb
To make the MariaDB start during every boot. Type the following on terminal and hit enter.
systemctl enable mariadb
Nex is to make the MariaDB secure by using the mysql_secure_installation command.
This program enables you to improve the security of your MariaDB installation in the following ways:
- You can set a password for
- You can remove
rootaccounts that are accessible from outside the localhost.
- You can remove anonymous-user accounts.
- You can remove the
testdatabase (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with
By default Apache server supports the HTML language only, not PHP. Install the PHP package along with support for the MariaDB.
yum install -y php php-mysqlnd
You need to restart the server after the installation of the PHP, to do that type the following on the terminal.
systemctl restart httpd
Test LAMP Stack
To test PHP, place a .php file on to the default directory of the Apache.
In the terminal copy/paste the following line:
This will open up a file called
Copy/paste this line into the phpinfo file and save and then close the file.
Now open your web browser and type the following into the web address:
The page looks like below:
Scroll down the browser to the modules section to check the support for the MariaDB. You will get the screen like below.