CentOS comes with Apache v.2.2.3 and PHP v.5.1.6 and they are easily installed via the default CentOS Package Manager ‘yum’.
The advantage of using yum (as opposed to installing via source code) is that you will get any security updates (if and when distributed) and dependencies are automatically taken care of.
A basic Apache install is very easy:
sudo yum install httpd mod_ssl
Oddly, the server does not start automatically when you install it so you have to do this by hand:
sudo /etc/init.d/httpd start
The first thing you will see is this error:
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
As you can see, the address 127.0.0.1 is used as the ServerName by default. It’s a good idea to set the ServerName for the next time the server is started.
Open the main apache config:
sudo nano /etc/httpd/conf/httpd.conf
Towards the end of the file you will find a section that starts with ‘ServerName’ and gives the example:
All you need to do is enter your Slice hostname or a FQDN:
Note that my Slice hostname is ‘demo’.
sudo /etc/init.d/httpd reload
Now the warning has gone. Nice.
if you have problem when restarting apache, you must check port with this syntax in shell command:
sudo netstat -plnt
or using filtering port 80 like this
$ sudo netstat -plnt | grep ':80'
If you navigate to your Slice IP address:
You will see the default CentOS Apache welcome screen:
Now that we have Apache installed and working properly, we need to make sure that it’s set to start automatically if the slice is rebooted.
sudo /sbin/chkconfig httpd on
Let’s check our work to confirm:
sudo /sbin/chkconfig --li
st httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Disable Direcotory Browsing
You can write on httpd.conf file to do the same in a server which hasn’t a control panel. Do follow the steps:
Step I : Login to server as root user.
Step II : Edit the Apache configuration file.
Options ExecCGI FollowSymLinks IncludesNOEXEC Indexes SymLinksIfOwnerMatch Options Includes Indexes FollowSymLinks
Step III : Remove the word ‘Indexes‘ from options and save it and restart Apache.
Options Includes Indexes FollowSymLinks ---> Options Includes FollowSymLinks
# service httpd restart
Let’s move on to the PHP5 install. I’m not going to install all the modules available. Just a few common ones so you get the idea.
As before, due to using yum to install PHP5, any dependencies are taken care of:
sudo yum install php-common php-gd php-mcrypt php-pear php-pecl-memcache php-mhash php-mysql php-xml php-pgsql
Note : if httpd can not be connected, can try “sudo yum install php”
If you have problem with “yum”, can try :
# vi /etc/yum.repos.d/CentOS-Base.repo –> change value gpcheck=1 to 0
* save using :wq (‘ins’ button for type)
then next step :
# yum clean all
# rm -f /var/lib/rpm/__db*
# rpm –rebuilddb
Once done, do a quick Apache reload:
sudo /etc/init.d/httpd reload
Open security Postgres connection:
Open Linux CMD : setsebool -P httpd_can_network_connect 1
Combine using MySQL
First we’ll login to the MySQL server from the command line with the following command:
mysql -u root -p
In this case, I’ve specified the user root with the -u flag, and then used the -p flag so MySQL prompts for a password. Enter your current password to complete the login.
Now switch to the appropriate MySQL database with the following command:
Next we’ll update the password for all MySQL users with the name root. Be sure to replaceyour_new_password with the actual new password:
update user set password=PASSWORD('your_new_password') where User='root';
Finally, reload the privileges:
Now you’re all set to exit MySQL!
Stop MySQL Server
# /etc/init.d/mysqld stop
Start MySQL Server
# /etc/init.d/mysqld start
Restart MySQL Server
# /etc/init.d/mysqld restart
AutoStart Service & Check Service Status
Step 1 – Check to make sure the httpd(Apache) is installed
[root#] chkconfig --list|grep http
This looks for the httpd service in the list of services running on your machine. If Apache is installed properly then you should see
[root#] 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Step 2 – Set httpd to auto start
This is a pretty easy straight forward command that sets Apache to start on boot
[root#] chkconfig httpd on
Step 3 – Confirm the Apache is set to auto-start
Just to make sure that every took, lets check again to see that httpd is set to auto-start
[root#] chkconfig --list|grep httpd
and you should see something like: [root#] 0:off 1:off 2:on 3:on 4:on 5:on 6:off