Apache-Webserver in CentOS 6.3 installieren
In diesem How-to-Tutorial zeige ich Ihnen, wie man Apache installiert und eine Beispiel-Website mit Apache hostet.
Szenario
In diesem How-to-Tutorial ist mein Test-Szenario wie folgt eingerichtet
Webserver-Details:
Operating System : CentOS 6.3 32bit server
Hostname : web.ostechnix.com
IP Address : 192.168.1.250Kundendetails:
Operating System : CentOS 6.3 32bit Desktop
Hostname : client.ostechnix.com
IP Address : 192.168.1.251Ich habe bereits einen DNS-Server in meiner Einrichtung und ich habe den DNS-Server sowohl mit Server- als auch mit Client-Details richtig konfiguriert.
Serverseitige Konfiguration
Voraussetzungen:
1. Legen Sie den Hostnamen des Webservers fest
[root@web ~]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=web.ostechnix.com2. Fügen Sie den Hostnamen des Webservers in die Datei 'etc/hosts' ein
[root@web ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.250 web.ostechnix.com
192.168.1.250 ostechnix.com3. Apache installieren
Überprüfen und entfernen Sie alle zuvor installierten Pakete
[root@web ~]# rpm -qa | grep httpdoder
[root@web ~]# yum list installed | grep httpd
Installieren Sie jetzt das 'httpd'-Paket
[root@web ~]# yum install httpd* -y4. Apache konfigurieren
[root@web ~]# vi /etc/httpd/conf/httpd.conf
## line no 262 - Set the server admin mail id which is used to receive mail generated by apache ##
ServerAdmin root@ostechnix.com
## line no 276 - Set the website name ##
ServerName ostechnix.com:80
## line no 292 - Set the web pages folder ##
DocumentRoot "/var/www/html"
## line no 402 - Sent the index or home page of the website ##
DirectoryIndex ostechnix.html5. Erstellen Sie eine Beispiel-Index- oder Startseite
Erstellen Sie die Index- oder Startseiten-html-Datei im Verzeichnis '/var/www/html/'
[root@web ~]# vi /var/www/html/ostechnix.html
<html>
<body bgcolor=blue>
<h1> Welcome to OSTECHNIX Website </h1>
</body>
</html>6. Erlaube Webserver durch die Firewall
[root@web ~]# vi /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT[root@web ~]# service iptables restart
iptables: Flushing firewall rules: [ OK ]
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]7. Apache-Webserver starten
[root@web ~]# service httpd start
Starting httpd: [ OK ]
[root@web ~]# chkconfig httpd onClientseitige Konfiguration
1. Fügen Sie die Webserver- und Client-IP-Adresse sowie den Hostnamen in die '/etc/hosts'-Datei ein
[root@client ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.251 client.ostechnix.com
192.168.1.250 ostechnix.com2. Überprüfen Sie den Apache-Webserver
Öffnen Sie Firefox im Client und geben Sie https://ostechnix.com in die Adressleiste ein. Die Indexseite der ostechnix-Website wird nun geöffnet.
Das ist es. Einen schönen Tag noch!!!
