Introduction
In this tutorial we will guide you to install Apache in CentOS 6. Apache web server is the most popular web server in the world with more than 50% market share.
Prerequisites
You will need:
- A VPS Tiger server, order at Pricing
- Getting Started with VPS Tiger Tutorial
- SSH with root access.
Update Packages
Update your packages using yum, it can take a while.
sudo yum -y update
Install Apache
Install Apache using yum command.
sudo yum -y install httpd
You will get output similar to:
... Installed: httpd.x86_64 0:2.2.15-60.el6.centos.6 Dependency Installed: apr.x86_64 0:1.3.9-5.el6_9.1 apr-util.x86_64 0:1.3.9-3.el6_0.1 apr-util-ldap.x86_64 0:1.3.9-3.el6_0.1 httpd-tools.x86_64 0:2.2.15-60.el6.centos.6 mailcap.noarch 0:2.1.31-2.el6 Complete!
Boot Configuration
Enable Apache to start on boot.
sudo chkconfig httpd on
Start Apache.
sudo service httpd start
Firewall Configuration
Run the following commands to allow web traffic.
For normal http traffic:
iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
For https (ssl) traffic:
iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
Save iptables configuration.
iptables-save
Accessing Web Page
Access web page by entering your public ip address at browser.
http://server_public_IP_address/
You will get default Apache page.
You can upload your web pages at following location:
/var/www/html/
Configure Virtual Hosts
To access your web page via domain name, you will need to create virtual host.
nano /etc/httpd/conf.d/myhost.conf
Add following lines and save the file using CTRL + X
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] ServerName yourdomain.com ServerAlias www.yourdomain.com DocumentRoot /var/www/html/yourdomain.com/public_html/ </VirtualHost>
If you want to add another domain add VirtualHost block. It will look like that:
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin [email protected] ServerName yourdomain.com ServerAlias www.yourdomain.com DocumentRoot /var/www/html/yourdomain.com/public_html/ </VirtualHost> <VirtualHost *:80> ServerAdmin [email protected] ServerName newdomain.com ServerAlias www.newdomain.com DocumentRoot /var/www/html/newdomain.com/public_html/ </VirtualHost>
Create the directories referenced above.
sudo mkdir -p /var/www/html/yourdomain.com/public_html
sudo mkdir -p /var/www/html/newdomain.com/public_html
Restart Apache for the above changes to take effect.
sudo service httpd restart
Conclusion
Your Apache (Web Server) setup is complete. Now you can upload your web pages and host website at your own server. Apache web server supports plain HTML document by default, you can install php modules and ssl modules to support them.