HOW TO BUILD WORKING CENTOS SERVER WITH APACHE AND PHP

 

LAMP is an acronym stands for Linux, Apache, MySQL and PHP. While the server is already running one of most favorite Linux distros, so the “Linux” part is taken care of while the rest are Apache, MySQL and PHP but we’ll talk about MySQL in a separate tutorial.

PREREQUISITE

  1. I assumed you already have either a VPS or Dedicated server running CentOS and you have access to it. In this tutorial I use CentOS 6.3 X32. See my Playground server.
  2. I also assumed you knew already how to use Putty or Terminal to SSH-ing a server.
  3. I believe you knew –at least part ofmost common Unix commands used to manage an unmanaged server.

HOW TO INSTALL APACHE AND PHP5

Step 1 – Login to your server and follow my previous guide about Basic setup for CentOS before you build a live web server. You may and may not follow that tutorial but if you followed, it will give you some basic security tweak to your server.

Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch as root.

Step 2Install Apache web server on CentOS. Issue following command:

1
yum install httpd

It looks something like this.

install apache centos

Next it will ask you to confirm. Simply type Y and hit Enter.

install apache

That’s it. Once installed it will display something like this:

apache installed

Step 3How To Install PHP5? The most basic command to install latest PHP version is following:

1
yum install php

But however as you gonna setup LAMP stack, so the most used command to install PHP5 and PHP5 MySQL module is:

1
yum install php php-mysql

Again, it will tell you total file size will be downloaded and ask you to confirm it. Simply type Y and hit Enter.

command to install php5 on centos

Once done, it will display the complete! message along with installed PHP module:

installed php5 module

That’s it. Now you have Apache and PHP5 installed. But wait, talking about PHP module, there are several most common modules available you may wish to install as well.

Step 4How to install PHP modules? Firstly you have to check all available libraries and modules by issuing this command:

1
yum search php-

It will then show you all libraries with “php-” prefix:

php modules

As you can see that next after each module’s name displayed short information about what the module is for. If you wish, you can also retrieve more detailed information about what each module does. Use this command:

1
yum info php-module-name

Of course you have to replace “php-module-name” above with actual name of the module. For instance:

php5 module info

Now you knew what each module does and the second thing you have to do is deciding which ones you will install. Once you did, issue this command to install it:

yum install php-module-name

Instead of installing each module one by one, you can simply install multiple libraries at once by separating the name of each module with a space. Here’s the example of command syntax used to install common modules:

1
yum install php-common php-cli php-devel php-fpm php-gd php-imap php-intl php-mysql php-process php-xml php-xmlrpc php-zts

Step 5 – Finally restart the Apache web server so it can reload appropriately:

1
service httpd restart

Don’t be panic when you see “Stopping httpd: FAILED” message it is normal as that you don’t start the Apache yet.

restart apache

So what about another error message? If what you mean is the message that says: “httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName”, so here’s the fix.

Issue this command syntax to edit Apache .conf file:

1
nano /etc/httpd/conf/httpd.conf

Next you have to find following line:

then add this right after that line:

1
ServerName localhost

So it will look like this:

servername

Once done hit Control+O to save then Control+X to exit Nano editor screen. That’s it. Next time you restart Apache it will simply display the OK message. Congratulation, you’ve been succeed getting rid of “httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName” error.

restart apache

Step 6 – This very last step is not a must but recommended: adding Apache to start up list. Each time you reboot your server PHP will start automatically but not with Apache. Issue command below to make it start each time whenever the server reboots:

1
chkconfig httpd on

Congratulation. What’s next? You can give it a test by accessing your server in your browser via its IP address. It will display something like this:

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s