CentOS 6 - Install Apache Server
[1]Install httpd + php
Very importantly, you should disable SELinux by editing the /etc/sysconfig/selinux configuration file. By default, it will have a line that saysSELINUX=enforcing. Change that to read SELINUX=disabled. You can’t get PHP talking to an Oracle database without doing this. Reboot to make the change take effect.
Finally, the commands you want to install the relevant Apache/PHP software bits and pieces are:
yum -y install httpd php nano unzip make
yum -y install gcc wget openssh php-devel php-pear libaio
The ‘httpd’ bit is the name for the Apache package itself; the other bits and pieces allow Apache to serve up something useful later on!
Configuring the Server
You first need to start the Apache service:
service httpd start
[2]Configure httpd.
# line 44: change
ServerTokens Prod
# line 76: change to ON
KeepAlive On
# line 262: Admin's address
ServerAdmin root@server.world
# line 276: change to your server's name
ServerName www.server.world:80
# line 331: change (enable CGI and disable Indexes)
Options FollowSymLinks ExecCGI
# line 338: change
AllowOverride All
# line 402: add file name that it can access only with directory's name
DirectoryIndex index.html index.cgi index.php
# line 536: change
ServerSignature Off
# line 759: make it comment
#AddDefaultCharset UTF-8
# line 796: uncomment and add file-type that apache looks them CGI
AddHandler cgi-script .cgi .pl
save the configuration file and restart httpd, the command is:
service httpd restart
To make the Apache bits start automatically at every reboot, issue this command:
chkconfig httpd on
By default, despite having done all of the above, you won’t be able to connect to your new server from a remote browser: Centos/Scientific slap a firewall on that blocks access. You can completely disable the firewall with the command:
service iptables stop
That only works per re-boot, though, so to switch the firewall off completely, use this:
chkconfig iptables off
The more subtle approach, of course, would be to reconfigure the firewall to allow http traffic through
vi /etc/sysconfig/iptables
-A INPUT -i eth0 -p tcp --sport 1024:65535 -d server_ip --dport 80 -j ACCEPT
-A OUTPUT -o eth0 -p tcp ! --syn -s 192.168.0.103 --sport 80 -d any/0 --dport 1024:65535 -j ACCEPT
-A INPUT -i eth0 -p tcp --sport 1024:65535 -d server_ip --dport 443 -j ACCEPT
-A OUTPUT -o eth0 -p tcp ! --syn -s server_ip --sport 443 -d any/0 --dport 1024:65535 -j ACCEPT
[3]Create a HTML test page and access to it with web browser. It's OK if following page is shown.
[root@www ~]# vi /var/www/html/index.html
<html>
<body>
<div style="width: 100%; font-size: 40px; font-weight: bold; text-align: center;">
Test Page
</div>
</body>
</html>
[4]Create a CGI test page and access to it with web browser. It's OK if following page is shown.
[root@www ~]# vi /var/www/html/index.cgi
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n";
print "CGI Test Page";
print "\n</div>\n";
print "</body>\n</html>\n";

[root@www ~]# chmod 705 /var/www/html/index.cgi

[5] You’ll also need to check that PHP is working OK, and for that I suggest you create a file called phpdata.php in the /var/www/html directory containing the following:
<?php
phpinfo();
?>


