Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS

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.

Installation of 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.

To install Apache, enter the following command from your terminal:

 

1
# yum install httpd -y

 

Start the Apache service and let it to start automatically on every reboot:

 

1
2
# service httpd start
# chkconfig httpd on

 

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,

 

1
# vi /etc/sysconfig/iptables

 

Add the following lines.

 

1
2
3
[…]
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEP
[…]

 

Restart iptables:

 

1
# service iptables restart

 

Test Apache:

Open your web browser and navigate to http://localhost/ or http://server-ip-address/.

Apache HTTP Server Test Page powered by CentOS - Mozilla Firefox_001

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.

To install MySQL, enter the following command:

 

1
# yum install mysql mysql-server -y

 

Start the MySQL service and make to start automatically on every reboot.

 

1
2
# service mysqld start
# chkconfig mysqld on

 

Setup MySQL root password

By default, mysql root user doesn’t has password. To secure mysql, we have to setup mysql root user password.

 

1
# mysql_secure_installation

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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):     <span style=”color: #ff0000;”>## Press Enter ##</span>
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]     <span style=”color: #ff0000;”>## Press Enter ##
</span>New password:                <span style=”color: #ff0000;”>## Enter new password ##
</span>Re-enter new password:       <span style=”color: #ff0000;”>## Re-enter new password ##
</span>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]     <span style=”color: #ff0000;”>## Press Enter ##
</span> … 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]     <span style=”color: #ff0000;”>## Press Enter ##</span>
… 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]     <span style=”color: #ff0000;”>## Press Enter ##
</span> – 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]     <span style=”color: #ff0000;”>## Press Enter ##
</span> … 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!

 

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.

Install PHP with following command:

 

1
# yum install php -y

 

Test PHP

Create a sample “testphp.php” file in Apache document root folder and append the lines as shown below:

 

1
# vi /var/www/html/testphp.php

 

Add the following lines.

 

1
2
3
<?php
phpinfo();
?>

 

Restart httpd service:

 

1
# service httpd restart

 

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*”

 

1
[root@server ~]# yum install php-mysql -y

 

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.

phpinfo() - Mozilla Firefox_002Install 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.

To install EPEL repository, follow the below link:

– Install EPEL Repository On RHEL/CentOS/Scientific Linux 6

Now install phpMyAdmin

 

1
# yum install phpmyadmin -y

 

Configure phpMyAdmin

Edit the phpmyadmin.conf file.

 

1
# vi /etc/httpd/conf.d/phpMyAdmin.conf

 

Find and comment the whole /<Directory> section as shown below:

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[…]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<span style=”color: #ff0000;”>#&lt;Directory /usr/share/phpMyAdmin/&gt;</span>
<span style=”color: #ff0000;”>#   &lt;IfModule mod_authz_core.c&gt;</span>
<span style=”color: #ff0000;”>#     # Apache 2.4</span>
<span style=”color: #ff0000;”>#     Require local</span>
<span style=”color: #ff0000;”>#   &lt;/IfModule&gt;</span>
<span style=”color: #ff0000;”>#   &lt;IfModule !mod_authz_core.c&gt;</span>
<span style=”color: #ff0000;”>#     # Apache 2.2</span>
<span style=”color: #ff0000;”>#     Order Deny,Allow</span>
<span style=”color: #ff0000;”>#     Deny from All</span>
<span style=”color: #ff0000;”>#     Allow from 127.0.0.1</span>
<span style=”color: #ff0000;”>#     Allow from ::1</span>
<span style=”color: #ff0000;”>#   &lt;/IfModule&gt;</span>
<span style=”color: #ff0000;”>#&lt;/Directory&gt;
[…]</span>

 

Open “config.inc.php” file and change from “cookie” to “http” to change the authentication in phpMyAdmin:

 

1
2
# cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php
# vi /usr/share/phpMyAdmin/config.inc.php

 

Change cookie to http.

 

1
2
3
4
[…]
/* Authentication type */
$cfg[‘Servers’][$i][‘auth_type’] = <span style=”color: #ff0000;”>’http'</span>;
[…]

 

Restart the Apache service:

 

1
# service httpd restart

 

Now you can access the phpmyadmin console by navigating to http://server-ip-address/phpmyadmin/ from your browser.

Enter your MySQL username and password which you have given in previous steps. In my case its “root” and “centos”.

phpMyAdmin - Mozilla Firefox_003Now you will be redirected to the phpmyadmin dashboard.page as shown below.

192.168.1.101 - localhost | phpMyAdmin 4.1.2 - Mozilla Firefox_004

Now you will able to manage your MariaDB databases from phpMyAdmin web interface.

16 thoughts on “Install LAMP Server (Apache, MySQL, PHP) On RHEL, CentOS

  • May 25, 2014 at 11:34 am
    Permalink

    rpm -ivh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/epel-release-6-8.noarch.rpm

    Step 2 » Now update repositories

    [root@localhost ~]# yum check-update

    Step 3 » After updating yum repositories , now you can install phpmyadmin package

    [root@localhost ~]# yum install phpMyAdmin

    This command will install phpmyadmin package along with dependencies . please type the package name exactly as phpMyAdmin ( ” M” and “A” –> Uppercase )

    Step 4 » Now restart httpd service

    [root@localhost ~]# service httpd restart

    Reply
  • Pingback: Fendi Outlet

  • Pingback: michael kors LUGGAGE

  • Pingback: Nagios installation step by step in centos/redhat or fedora part 1 | Eduguru - Good Blogging

  • March 28, 2015 at 1:50 am
    Permalink

    WOW јust what I was looking for. Came here by searchіng for grillage

    Reply
  • March 28, 2015 at 5:47 pm
    Permalink

    Ensure that your resume makes it easy for the readers to identify your capabilities and feel your enthusiasm to be a part of their
    workforce. When choosing furniture, you’ll be deciding on many different types of chairs
    to put into your home. In a new media driven world,
    people rely on search, their friends on social networks, and other online media channels to hear about things
    happening in the digital world.

    Reply
  • March 29, 2015 at 10:31 am
    Permalink

    You really make it appear really easy with your presentation but
    I in finding this topic to be really something which I believe
    I might by no means understand. It sort of feels too complicated and extremely huge
    for me. I’m having a look forward in your subsequent publish,
    I will attempt to get the cling of it!

    Reply
  • March 30, 2015 at 4:24 pm
    Permalink

    My partner and I absolutely love your blog and find many of your post’s to be exactly what I’m looking for.

    Do you offer guest writers to write content available for you?

    I wouldn’t mind creating a post or elaborating on a number of the subjects
    you write in relation to here. Again, awesome web
    log!

    Reply
  • March 30, 2015 at 5:17 pm
    Permalink

    It’s really very complicated in this active life to listen news on Television, so I
    just use internet for that reason, and take the latest
    information.

    Reply
  • March 31, 2015 at 12:54 am
    Permalink

    Excellent site you have here but I was wanting to know
    if you knew of any forums that cover the same topics talked about here?
    I’d really like to be a part of online community where I can get feed-back from other experienced individuals that share the same interest.
    If you have any recommendations, please let me know. Thanks!

    Reply
  • March 31, 2015 at 4:42 am
    Permalink

    I was suggested this web site by my cousin. I am now not sure whether or not this put up is written via him as no one else know such precise approximately
    my problem. You’re wonderful! Thanks!

    Reply
  • April 4, 2015 at 4:38 pm
    Permalink

    Simply desire to say your article is as astounding. The clarity in your
    post is simply cool and i can assume you are an expert
    on this subject. Fine with your permission allow me
    to grab your feed to keep updated with forthcoming post. Thanks a million and please carry on the gratifying work.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: