Install Apache, PHP and MySQL On CentOS

[Total: 8    Average: 4.9/5]

Today I’m going to show you how to install Apache, PHP and Mysql on CentOS server and all these are the open source application and it’s easily available for the installation. You can install all these application on CentOS server with the yum ( Yellowdog Updater, Modified ) utility.

Setup the Hostname

Check server hostname with following command.

hostname -f

Second command will Display the FQDN (Fully Qualified Domain Name) name of your server.

Update your system

Need to update your server packages with the stable and secure version. You can update it with below command.

yum update

Install Apache

Now install the httpd (Apache) service with yum command.

yum install httpd -y

Once it’s done. Edit Apache configuration file and update your required configuration value of StartServers, MinSpareServers, MaxClients ETC as per your server memory.

Create Document Root directory of your domain which will store your site content. Following command will create all the parents directory for the new directory.

mkdir -p /var/www/

And now change the ownership of newly created directed to user instead of root.

chown -R apache:apache /var/www/

And most important to make sure that everyone will be able to read our new files, So change the permission of that directory.

chmod 755 /var/www

Create one test page in your domain document root folder which you have just created and add following HTML code in index.html file

touch /var/www/


    <h1>Test page from CentOS server1</h1>

Now open your /etc/httpd/conf/httpd.conf file and update it with the below

   NameVirtualHost *:80
 # NOTE: NameVirtualHost cannot be used without a port specifier
 # (e.g. :80) if mod_ssl is being used, due to the nature of the
 # SSL protocol.

 # VirtualHost example:
 # Almost any Apache directive may go into a VirtualHost container.
 # The first VirtualHost section is used for requests without a known
 # server name.
 DocumentRoot /var/www/
 ErrorLog /var/www/
 CustomLog /var/www/

Restart the httpd service with following command.

/etc/init.d/httpd start

To check if Apache is installed, direct your browser to your server’s IP address, You can find your IP with following command.

ifconfig eth0 | grep inet | awk '{ print $2 }'

Install MySQL

MySQL is an open-source relational database management system (RDBMS) and it’s very powerful database management system. MySQL installation is very easy with te yum, Try to install it following couple of commands and you are ready to use mysql for databases

yum install mysql-server -y
service mysqld start

Once the installation is done, you can set a root MySQL password


Enter current password for root (enter for none):
OK, successfully used password, moving on...

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!

Install PHP

Php is also open source server scripting language, and a powerful tool for making dynamic and interactive Web pages

You can install php and other modules with the yum.

yum install php php-mysql -y

If you want to search useful libraries and modules which you want to add on your server, You can find out that with the folllwing command.

yum search php-


 php-twig-Twig.noarch : The flexible, fast, and secure template engine for PHP
 php-twig-ctwig.x86_64 : Extension to improve performance of Twig
 php-udan11-sql-parser.noarch : A validating SQL lexer and parser with a focus on MySQL dialect
 php-voms-admin.noarch : Web based interface to control VOMS parameters written in PHP
 php-webmozart-assert.noarch : Assertions to validate method input/output with nice error messages
 php-webmozart-path-util.noarch : Cross-platform utilities for file paths
 php-when.noarch : Date/Calendar recursion library for PHP
 php-whitehat101-apr1-md5.noarch : Apache's APR1-MD5 algorithm in pure PHP
 php-xapian.x86_64 : Files needed for developing PHP scripts which use Xapian
 php-xcache.x86_64 : Fast, stable PHP opcode cacher
 php-xml.x86_64 : A module for PHP applications which use XML
 php-xmlrpc.x86_64 : A module for PHP applications which use the XML-RPC protocol
 php-xmlseclibs.noarch : PHP library for XML Security
 php-zendframework-zendpdf.noarch : Zend Framework ZendPdf component
 php-zendframework-zendxml.noarch : Zend Framework ZendXml component
 php-zetacomponents-base.noarch : Zeta Base Component
 php-zetacomponents-console-tools.noarch : Zeta ConsoleTools Component
 php-zetacomponents-graph.noarch : Zeta Graph Component
 php-zetacomponents-unit-test.noarch : Zeta UnitTest Component
 php-zipstream.noarch : Streaming dynamic zip from PHP without writing to the disk
 php-zmq.x86_64 : ZeroMQ messaging
 php-znerol-php-stringprep.noarch : Implementation of RFC 3454 Preparation of Internationalized Strings
 php-zts.x86_64 : Thread-safe PHP interpreter for use with the Apache HTTP Server

If you want to install php modules you cam install it through YUM

yum install name-of-the-module
yum install php-xml php-pear php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml

Now create php info page in your domain public_html folder /var/www/

vi /var/www/

Restart httpd services and check your phpinfo page with your domainname (

service httpd restart