Install LAMP Server On RHEL 6, CentOS 6 and Fedora 18
LAMP
stands for (Linux, Apache, MySQL, PHP/Perl/Python) OS and open-source
software stack. In this tutorial, we will discuss the LAMP installation
on RHEL6.x, CentOS6.x and Fedora18 (x stands for versions).
My server hostname and IP address are server.linuxpathfinder.local and 192.168.1.111/24, respectively.
Install Apache HTTP Server:
The Apache HTTP Server is a web server
application notable for playing a key role in the initial growth of the
World Wide Web. It provides a full range of web server features
including CGI (Common Gateway Interface) defines a way for a web server
to interact with external content-generating programs, SSL (Secure
Sockets Layer) is an encryption mechanism over HTTP which allows you to
send sensitive or confidential information over the internet to a client
and vice versa and virtual domains which refers to the practice of
running more than one web site on a single machine.
To start the installation of Apache server, write on terminal as shown below:
# yum install httpd -y
After complete installation, start the Apache service and define to start automatically on every reboot:
# service httpd start
# chkconfig httpd on
In firewall/router file we need to allow
Apache server default port 80 to connect from remote systems. The
firewall file location, edit file /etc/sysconfig/iptables,
# vim /etc/sysconfig/iptables
Add the following lines.
[....]
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
[....]
After changes restart iptables service:
# service iptables restart
# netstat -tulpn | grep :80
tcp 0 0 :::80 :::* LISTEN 2438/httpd
Now Test Apache:
To verify web server open your web browser and navigate to http://localhost/ or http://server-ip-address/.
Install MySQL Server:
MySQL is a free Relational Database
Management System (RDBMS) that uses Structured Query Language (SQL),
world’s second most used database. MySQL is a mostly used for web
applications, and is a main component of mostly used LAMP open-source
web application.
Enter the following command to install MySQL server:
# yum install mysql mysql-server -y
After complete installation, start the MySQL service and define to start automatically on every reboot:
# service mysqld start
# chkconfig mysqld on
MySQL root password setup:
Mysql root user doesn’t has password initially. So, we have to setup mysql root user password to secure mysql.
# 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):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password: ## Enter new password ##
Re-enter new password: ## Re-enter new password ##
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
… Success!
Normally, root should only be allowed to connect from ‘localhost’. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
… Success!
By default, MySQL comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
… Success!
Cleaning up…
All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
PHP Installation:
PHP (Hypertext Preprocessor), an open source, server-side, HTML embedded scripting language used to create dynamic Web pages.
Install PHP with following command:
# yum install php -y
Now Test PHP
Create a sample “infophp.php” file in Apache document root folder and append following lines:
# vi /var/www/html/infophp.php
Add the following lines.
phpinfo();
?>
Restart httpd service:
# service httpd restart
Navigate to http://server-ip-address/infophp.php to see all details about php like (version, build date commands etc.)
If need MySQL support in PHP, must install “php-mysql” package. And if we need to install all php modules just we’ll use “yum install php*” command.
# yum install php-mysql -y
Open the infophp.php file in browser
using http://domain-name/infophp.php or http://ip-address/infophp.php.
Installed mysql module will be available there.
phpMyAdmin Installation:
phpMyAdmin is used to manage your
installed MySQL database (RDBMS). phpMyAdmin is a free open-source web
interface tool. For phpMyAdmin installation we need to install EPEL
repository coz of phpMyAdmin is not available in CentOS official
repositories.
How to install EPEL repository:
# wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm
Sample Output:
Preparing… ########################################### [100%]
package epel-release-6-8.noarch is already installed
Now install phpMyAdmin
# yum install phpmyadmin -y
phpMyAdmin Configuration:
Edit the phpmyadmin.conf file.
# vim /etc/httpd/conf.d/phpMyAdmin.conf
Find and comment the whole / section as shown below:
[...]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
#
#
# # Apache 2.4
#
# Require ip 127.0.0.1
# Require ip ::1
#
Open “config.inc.php” file and change from “cookie” to “http” to change the authentication in phpMyAdmin:
Change cookie to http.
Now access phpmyadmin console by navigating to http://server-ip/phpmyadmin/ from your browser.
In username and password prompt, you have to put your MySQL username and password. In my case its “root” and “passw0rd”.
Now you can manage MariaDB database from phpMyAdmin web interface.
Enjoy! Your LAMP server is up and ready to use.