Installing LAMP Stack on CentOS7 Server

Installing & setting up LAMP stack on CentOS7 Linux Server, Here I'll be showing how to setup Apache, MySql and PHP in CentOS7 Linux Server.

You can install PHPMyAdmin in CenOS7. By using PHPMyAdmin, you can manage databases easily.

Follow these steps

1. Install Apache Web Server on CentOS7

To Install and Setup Apache Web Server in CentOS7, execute these commands in SSH terminal.​

​​yum install httpd
Linode SetUp server install apache httpd

​After executing above command, it will asks for confirmation about total download size and installed size, also about dependent packages.

Here the download size is 3MB, Installed size is 10MB and 4 dependent packages. To continue installing type y and hit Enter button.

Linode SetUp server install apache httpd

​After the Completion of Apache Web Server installation in CentOS7 Linux Server, you will see a message like this below.

Linode SetUp server install apache httpd

​After Installing Apache web server, start the apache server by using below command

systemctl start httpd​
Linode SetUp server install apache httpd

​To start apache web server on server restart, execute this command once.

systemctl enable httpd
Linode SetUp server install apache httpd

After completing above setp, type your server ip address in browser. You should see output like this below.

If you see the output, apache web server is installed in centos7 and ready to use.​

install lamp stack on centos7

2. ​Install MySQL (MariaDB) in CentOS7

MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that comes rich set of enhancements.

Follow these commands to install MySQL database in CentOS7.​

​yum install mariadb-server mariadb​
install lamp stack on centos7 mysql

Few seconds after executing above step, you will see information about download size and installed size, dependent packages. To continue installation type y and hit Enter button.

install lamp stack on centos7 mysql

After Completion of MySQL (MariaDB) Database installation, you will see message like this below.

install lamp stack on centos7 mysql

After installation, you need to start the database for that use start command. You need to setup database to server to start immediately on server restart for that use enable command.

​systemctl start mariadb
​​systemctl enable mariadb
install lamp stack on centos7 mysql

After that you need to secure the database configuration, for that we need to execute the below command.

​mysql_secure_installation​

After executing above command, you need to enter password. By default password is empty, just press enter.

install lamp stack on centos7 mysql secure

You will asked to set root password, press y and hit Enter button. Enter the desired password. This is the password we will use in future to connect to database.

install lamp stack on centos7 mysql secure

​Remove anonymous user, we don't need it.

install lamp stack on centos7 mysql secure

Disallow root login, this is used to database on this server from different server. We are not going to use and it's not secure, disable it.

install lamp stack on centos7 mysql secure

​We are not going to use test database, just remove it.

install lamp stack on centos7 mysql secure

​Reload the database privileges to update the newly configured settings.

install lamp stack on centos7 mysql secure

​Now you have configured you database to secure settings.

install lamp stack on centos7 mysql secure

3. Install PHP​​ in CentOS7 Server

To complete LAMP stack we need to install PHP & PHP-MySql modules. For installing those two modules follow the below commands.

yum install php php-mysql
install lamp stack on centos7 php

​You will see the information about download size, installed size, dependent packages. Type y and press Enter button to continue installation.

install lamp stack on centos7 php

​After Completion of installation, you will see a message like this below.

install lamp stack on centos7 php

​After installation, to change to take effect in web server. Restart the apache web server. Follow below command.

​systemctl restart httpd
install lamp stack on centos7 php

We need to check whether PHP & apache web server configured correctly or not. For that create a PHP file and add phpinfo function in that file. Follow these steps to create PHP file. 

nano /var/www/html/phpinfo.php​

​Put this below code in that file.

​<?php
phpinfo();
?>​

​Open this file in browser, http://your-ip-address/phpinfo.php

You should see output like this below.​

install lamp stack on centos7 php

4. Install PHPMyAdmin in CentOS7 Server

This is optional step to install PHPMyAdmin, PHPMyAdmin is used to manage databases in MySQL database. To install and setup PHPMyAdmin in CentOS7 Server, use these below commands.

yum install phpmyadmin​
install lamp stack on centos7 mysql phpmyadmin

​To continue installation type y and press Enter button.

install lamp stack on centos7 mysql phpmyadmin

​After completion of installation, you should see a message like this.

install lamp stack on centos7 mysql phpmyadmin

Next edit phpMyAdmin.conf file to access PHPMyAdmin from other computers using browser. By default it is set to access only from the same machine.

/etc/httpd/conf.d/phpMyAdmin.conf​
install lamp stack on centos7 mysql phpmyadmin

​Comment the lines indicated below, and also add few extra lines to access it.

​## Comment the following Section ##
#<Directory /usr/share/phpMyAdmin/>
# <IfModule mod_authz_core.c>
# # Apache 2.4
# <RequireAny>
# Require ip 127.0.0.1
# Require ip ::1
# </RequireAny>
# </IfModule>
# <IfModule !mod_authz_core.c>
# # Apache 2.2
# Order Deny,Allow
# Deny from All
# Allow from 127.0.0.1
# Allow from ::1
# </IfModule>
#</Directory>

## Add the following lines:

<Directory /usr/share/phpMyAdmin/>
Options none
AllowOverride Limit
Require all granted
</Directory>
install lamp stack on centos7 mysql phpmyadmin

​Edit config.inc.php file and set the auth_type to http instead of cookie.

​nano /etc/phpMyAdmin/config.inc.php
​/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
// Authentication method (config, http or cookie based)?
install lamp stack on centos7 mysql phpmyadmin

​Restart the apache server for changes to take effect.

​systemctl restart httpd

Open http://your-server-ip-address/phpmyadmin, it will asks for username and password. These are MySQL database username and password, which you updated in step no-2 while installing database. After login, you can access PHPMyAdmin and start creating databases, database users. 

install lamp stack on centos7 mysql phpmyadmin
install lamp stack on centos7 mysql phpmyadmin

I hope you have successfully installed LAMP Stack on CentOS7, if you have any problem while installing LAMP stack. Let me know using comment form below.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

x

Join My Facebook Group to Receive Coding Tutorial for Free

email-subsribe