Friday, April 6, 2012

Configure Web Server in Ubuntu...

HTTP - Apache2 Web Server
=========================
1.Check the Installation
=> dpkg -s apache2
=> pgrep apache2
=> info apache2   

2. Remove Old version
If you currently have apache removed improperly, reinstall it by “sudo apt-get install apache2″ before to use the following command to remove apache2 completely :

=> apt-get remove --purge apache2 apche2-utils

3. Now Install fresh copy of Apache2
a)    =>sudo apt-get install apache2
b)    =>apt-getinstall libapache2-mod-php5
    Enable this module by doing
        => sudo a2enmod php5
c) Test the Apache2 is running
    => pgrep apache2

d) Open browser and type the following
http://localhost (It Works! message will be displayed)

If apache2 installation work properly forward to following:

4. Configure main file
=>sudo nano /etc/apache2/apache2.conf
Search the following lines and uncomment these if commented with #)
    ServerRoot "/etc/apache2"
    Include /etc/apache2/httpd.conf
    Include /etc/apache2/ports.conf
    Include /etc/apache2/sites-enabled/
Save and exit (ctrl+O enter, ctrl + X)

5. Configure port number  
=>sudo nano /etc/apache2/ports.conf
change the port number if necessary then save and exit...

6. Configure Virtual Host (One apache server can be configured for multiple domain names, this is called virtual hosting, single IP but Multiple Domain name service)
=> nano /etc/apache2/sites-available/default
Example:
    <VirtaulHost *>
    ServerAdmin webmaster@localhost
    ServerName www.domain.com
    DocumentRoot /var/www/domain
    </VirtualHost>

6.i. Configure virtual host for mysite domain
<VirtualHost *:80>
       ServerAdmin eng_mukul@yahoo.com
       DocumentRoot /var/www/mysite
       ServerName www.mysite.com
</VirtualHost>

7. Configure domain name
Open any one of the following two file
=>sudo nano /etc/apache2/apache2.conf
=>sudo nano /etc/apache2/httpd.conf

Add the following line somewhere:

ServerName mysite (mysite may replace with your domain name)

8: Place the web site want to host
8.a: Create domain directory
=>cd /var/www/
=> mkdir mysite

8.b: Change permission of the directory
=> ls -ld mysite/
=> chmod 777 mysite/
8.c: Copy & paste website directory in mysite directory
=> cp -r /home/mukul/Desktop/doc/mysite/* /var/www/mysite/

8.d: Make the mysite directory writable by webserber
In order to make a directory writable by the webserver we have to set the directory’s owner or group to Apache’s owner or group and enable the write permission for it. Usually, we set the directory to belong to the Apache group (apache or `www-data or whatever user is used to launch the child processes) and enable the write permission for the group.

8.d.(i): Check the version of apache
=> ps -ef | grep apache | grep -v grep

8.d.(ii): Give write permission to www-datea (default user of apache2)
=> chgrp www-data /var/www/mysite/
=> chmod g+w /var/www/mysite/
=> chmod 777 -R /var/www/mysite/

9. Restart the apache service
=>sudo /etc/init.d/apache2 restart

10. Open browser and type the following
To test apache2 setup
http://localhost

To check your website
http://localhost/mysite

11. Add security
a. Create a password file
=>sudo touch /etc/apache2/password_file
=>sudo chmod 777 /etc/apache2/password_file
=>sudo htpasswd -c /etc/apache2/password_file mukul

=>sudo  nano /etc/apache2/sites-available/default
for domain myyahoo (no need to add this domain, mysite domain will give support virtually)

<VirtualHost *:80>
       ServerAdmin eng_mukul@yahoo.com
       DocumentRoot /var/www/myyahoo
       ServerName www.myyahoo.com

       <Directory /var/www/myyahoo/>
               AuthType basic
               AuthType "Password require to open"
               AuthUserFile /etc/apache2/password_file
               Require user mukul
       </Directory>
</VirtualHost>

Save and exit
=> /etc/init.d/apache2 restart

=> set file permission with its all the contents
chmod o+rwx /var/www/mysite/* -R

End..............
.. arahman.iit@gmail.com

No comments:

Post a Comment