Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5 - 6
Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5 - 6
4 | Unixmen
LAMP is a combination of operating system and open-source software stack. The acronym LAMP is
derived from first letters of Linux, Apache HTTP Server, MySQL database, and PHP/Perl/Python.
In this tutorial let us see how to setup LAMP server on RHEL/CentOS/Scientific Linux 6.x. Here x
stands for version such as 6.1, 6.2, 6.3, 6.4, 6.5 etc.
Install Apache
Apache is an open-source multi-platform web server. It provides a full range of web server features
including CGI, SSL and virtual domains.
Start the Apache service and let it to start automatically on every reboot:
Allow Apache server default port 80 through your firewall/router if you want to connect from remote
systems. To do that, edit file /etc/sysconfig/iptables,
# vi /etc/sysconfig/iptables
[...]
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEP
http://www.unixmen.com/install-lamp-server-in-centos-6-4-rhel-6-4/ 1/7
7/22/2014 Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5/6.4 | Unixmen
[...]
Restart iptables:
Test Apache:
Install MySQL
MySQL is an enterprise class, open source, world’s second most used database. MySQL is a popular
choice of database for use in web applications, and is a central component of the widely used LAMP
open source web application software stack.
Start the MySQL service and make to start automatically on every reboot.
http://www.unixmen.com/install-lamp-server-in-centos-6-4-rhel-6-4/ 2/7
7/22/2014 Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5/6.4 | Unixmen
By default, mysql root user doesn’t has password. To secure mysql, we have to setup mysql root
user password.
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): ## Press Enter ##
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Install PHP
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general
purpose scripting language that is especially suited for web development and can be embedded into
HTML.
Test PHP
Create a sample “testphp.php” file in Apache document root folder and append the lines as shown
below:
# vi /var/www/html/testphp.php
Navigate to http://server-ip-address/testphp.php. It will display all the details about php such as
version, build date and commands etc.
If you wanna to get MySQL support in your PHP, you should install “php-mysql” package. If you want
to install all php modules just you use the command “yum install php*”
http://www.unixmen.com/install-lamp-server-in-centos-6-4-rhel-6-4/ 4/7
7/22/2014 Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5/6.4 | Unixmen
Now open the phptest.php file in your browser using http://ip-address/testphp.php or http://domain-
name/testphp.php. Scroll down and you will see the mysql module will be presented there.
Install phpMyAdmin
phpMyAdmin is a free open source web interface tool, used to manage your MySQL databases. By
default phpMyAdmin is not found in CentOS official repositories. So let us install it using EPEL
repository.
Configure phpMyAdmin
# vi /etc/httpd/conf.d/phpMyAdmin.conf
http://www.unixmen.com/install-lamp-server-in-centos-6-4-rhel-6-4/ 5/7
7/22/2014 Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5/6.4 | Unixmen
[...]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
#<Directory /usr/share/phpMyAdmin/>
# <IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# </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>
[...]
Open “config.inc.php” file and change from “cookie” to “http” to change the authentication in
phpMyAdmin:
# cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php
# vi /usr/share/phpMyAdmin/config.inc.php
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
[...]
Enter your MySQL username and password which you have given in previous steps. In my case its
“root” and “centos”.
http://www.unixmen.com/install-lamp-server-in-centos-6-4-rhel-6-4/ 6/7
7/22/2014 Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS, Scientific Linux 6.5/6.4 | Unixmen
Now you will able to manage your MariaDB databases from phpMyAdmin web interface.
Cheers!
http://www.unixmen.com/install-lamp-server-in-centos-6-4-rhel-6-4/ 7/7