Install Apache, PHP And MySQL On CentOS 7

Spread the love


First ,need to install modules

rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY*
yum -y install epel-release

Installing MySQL


root@server1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

Enter current password for root (enter for none): <–ENTER
OK, successfully used password, moving on…

Set root password? [Y/n] 
New password: ” ”

Re-enter new password:  ” “
Password updated successfully!
Reloading privilege tables..
 … Success!

Installing Apache2

CentOS 7 ships with apache 2.4. Apache2 is directly available as a CentOS 7.0 package, therefore we can install it like this:

yum -y install httpd

 [root@server1 ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * updates:
Package httpd-2.4.6-17.el7.centos.1.x86_64 already installed and latest version
Nothing to do
[root@server1 ~]#


systemctl start httpd.service

systemctl enable httpd.service

Installing PHP5

We can install PHP5 and the Apache PHP5 module as follows:

yum -y install php

We must restart Apache afterwards:

 systemctl restart httpd.service


Testing PHP5 / Getting Details About Your PHP5 Installation

The document root of the default website is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version.

vi /var/www/html/info.php




Now we call that file in a browser (e.g.



yum -y install php-mysql

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

Now restart Apache2:

 systemctl restart httpd.service

phpMyAdmin installation

phpMyAdmin is a web interface through which you can manage your MySQL databases.
phpMyAdmin can now be installed as follows:

yum install phpMyAdmin

Now we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out the <Directory “/usr/share/phpmyadmin“> stanza):

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

[...]Alias /phpMyAdmin /usr/share/phpMyAdmin

Alias /phpmyadmin /usr/share/phpMyAdmin


#<Directory /usr/share/phpMyAdmin/>

#   <IfModule mod_authz_core.c>

#     # Apache 2.4

#     <RequireAny>

#       Require ip

#       Require ip ::1

#     </RequireAny>

#   </IfModule>

#   <IfModule !mod_authz_core.c>

#     # Apache 2.2

#     Order Deny,Allow

#     Deny from All

#     Allow from

#     Allow from ::1

#   </IfModule>




<Directory /usr/share/phpMyAdmin/>

        Options none

        AllowOverride Limit

        Require all granted



Next we change the authentication in phpMyAdmin from cookie to http:

vi /etc/phpMyAdmin/


$cfg['Servers'][$i]['auth_type']     = 'http';    // Authentication method (config, http or cookie based)?


Restart Apache:

systemctl restart  httpd.service

Afterwards, you can access phpMyAdmin under

Leave a Reply

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