Sunday, December 6, 2015
Build Working CentOS Server with Apache and PHP
This tutorial will show you all necessary steps and most common Unix commands to install and setup Apache and PHP on a server running CentOS distro. This tutorial is part of what you have to do to install LAMP stack, a collection of open source software used to get web servers up and running so you can host all your site’s files and databases in it.
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.
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 2 – Install Apache web server on CentOS. Issue following command:
1
yum install httpd
It looks something like this.
Next it will ask you to confirm. Simply type Y and hit Enter.
That’s it. Once installed it will display something like this:
Step 3 – How 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.
Once done, it will display the complete! message along with installed PHP 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 4 – How 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:
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:
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.
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:
1
#ServerName www.example.com:80
then add this right after that line:
1
ServerName localhost
So it will look like this:
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.
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:
Labels:
linux
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment