Install Apache, MySQL and PHP on CentOS


Installing Apache, MySQL and PHP on CentOS is straight-forward with the yum command. Yellow dog Updater, Modified (yum) is the default package manager used in CentOS ( all versions ). It is used to install and update packages from CentOS and 3rd party repositories.

1. Install the Nano Editor

# yum install nano

Alternatively use the default vi editor that comes with CentOS and skip this installation.

2. Install Apache web server

# yum install httpd
# service httpd start
# nano /var/www/html/index.html

Enter the following text and save the file:

<html>
<head><title>Test</title></head><body><p>This is a test page for httpd</p></body>
</html>

Browse to http://virtual-machine-hostname-or-ip/, and if all goes well, it show load the test page index.html. If firewall is turned on (default), then use the text base browser lynx to confirm installation of httpd or turn off firewall.

To use lynx, first you need to install it, then issue the second command to load the default web page created by httpd:

# yum install lynx
# lynx localhost

Alternatively, turn off firewall, and browse to the test page you created above. To turn off the firewall:

# chkconfig iptables off

Set httpd service to auto start on server reboot:

# chkconfig httpd on

Reboot the server:

# reboot

Then browse the test page, i.e. open up a web browse in the host, and browse to the web address:

http://virtual-machine-hostname-or-ip/

You should see the content you created above.

3. Install MySQL server

# yum install mysql mysql-server

Restart the mysqld service
# service mysqld start

Secure MySQL server, including setting the mysql admin passsword
# /usr/bin/mysql_secure_installation

You will be prompted to enter the password for MySQL root. Press Enter.

Next you will see the following prompts:

  • Set root password? [Y/n]
  • Remove anonymous users? [Y/n]
  • Disallow root login remotely? [Y/n]
  • Remove test database and access to it? [Y/n]
  • Reload privilege tables now? [Y/n]

All done! If you’ve completed all of the above steps, your MySQL installation should now be secure.

4. Install PHP

# yum install php php-mysql
# nano /var/www/html/info.php

Enter the following text and save:
< ?php phpinfo(); ?>

Restart the web server httpd

# service httpd restart

Then browse to http://virtual-machine-hostname-or-ip/info.php, and you will see the PHP configurations information displayed.

5. Automate service start-up on server reboot

Set mysqld to run automatically when the server boots (php will run automatically once httpd starts):

# chkconfig mysqld on

Congratulations! You have now installed httpd, MySQL and PHP on CentOS 6.4.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s