Monday, 7 September 2015

Apache Web Server
Apache is actually "a PATCHy server". It was based on some existing code and a series of  "patch files" made to original NCSA server. For many people this name brings the same meaning / feeling / spirit of the Native American Indian tribe of Apache, well-known for their superior skills in warfare strategy and inexhaustible endurance. Apache is HTTP 1.1 Compliant, open-source web server that is widely used. 
Apache is probably the most popular Linux-based Web server application in use. Once you have DNS correctly setup and your server has access to the Internet, you'll need to configure Apache to accept surfers wanting to access your Web site.

Managing Apache's httpd daemon is easy to do, but the procedure differs between Linux distributions. Here are some things to keep in mind.
Firstly, different Linux distributions use different daemon management systems. Each system has its own set of commands to do similar operations. Secondly, the daemon name needs to be known.
General Configuration Steps
The configuration file used by Apache is /etc/httpd/conf/httpd.conf in Redhat / Fedora distributions and /etc/apache*/httpd.conf in Debian / Ubuntu distributions. As for most Linux applications, you must restart Apache before changes to this configuration file take effect. The file is divided into three main sections.
1. Global Environment
2. Main configuration
3. Virtual Host Configuration
In Section 1, only the directive Listen needs to be set. This tells the Apache server, on which IP and port to listen for HTTP requests.

Listen 80
or
Listen 192.168.1.254:80

We can also make it listen on any port other than 80. 
In Section 2, set the ServerName and DocumentRoot directives. ServerName would be the name which will be used generally to access your server, i.e. www.mydomain.com. Set DocumentRoot directive to the path where the web pages of your main website reside. Similarly your VirtualHost configurations in Section 3 will have the DocumentRoot directive set to the directories containing web content relating to respective sites.

ServerName www.mydomain.com
DocumentRoot /var/www/html
By default, Apache expects to find all its web page files in the /var/www/html/ directory with a generic DocumentRoot statement at the beginning of httpd.conf :

<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>

Try starting your web server now by:
/etc/rc.d/init.d/httpd start

File Permissions and Apache
Apache will display Web page files as long as they are world readable. You have to make sure you make all the files and subdirectories in your DocumentRoot have the correct permissions.
It is a good idea to have the files owned by a non privileged user so that Web developers can update the files using FTP or SCP without requiring the root password.
To do this:
1.     Create a user with a home directory of /home/www.
2.     Recursively change the file ownership permissions of the /home/www directory and all its subdirectories.
3.     Change the permissions on the /home/www directory to 755, which allows all users, including the Apache's httpd daemon, to read the files inside.
useradd -g users www
chown -R www:users /home/www
     chmod 755 /home/www
Now we test for the new ownership with the ll command.
ll /home/www/site1/index.*

Note: Be sure to FTP or SCP new files to your web server as this new user. This will make all the transferred files automatically have the correct ownership.
If you browse your Web site after configuring Apache and get a "403 Forbidden" permissions-related error on your screen, then your files or directories under your DocumentRoot most likely have incorrect permissions.
Now open your favorite web browser and type in the URL :
http://127.0.0.1
or
http://localhost
or
http://www.mydomain.com

You should be able to see a Apache web server Test Page. If you can see the Apache test web page that means you are all set to further configure your server. Now copy your web site related files in this directory /var/www/html make them Apache readable by setting appropriate ownership and permissions and  re-start the web server. You should be able to see your website related main web page.

Log Files
/var/log/httpd/access_log
/var/log/httpd/error_log
/var/log/messages

No comments:

Post a Comment