Sunday, 17 May 2015

How To Install and Configure the Apache Web Server on Ubuntu



  • How to install apache server on ubuntu using terminal, the command is given bellow:

                sudo apt-get update
                sudo apt-get install apache2

  • Command for start, stop, restart and check the status of apache server
      sudo service apache2 start ---> For start the apache server
            
      sudo service apache2 stop ---> For stop the apache server

      sudo service apache2 resart ---> For restart the apache server

      sudo service apache2 status --> For check status of the apache server

After installing apache2 we can see the default page in the browser. For that, type the ip address of the machine where the apache server is installed. To find the ip address of the machine type the command "ifconfig" on the terminal. The example of default page is given bellow:



You can see the above page only when the apache server is running state.

How to host your website in apache2
      First we have to change the current directory to /var/www, then create a directory there. I created a directory named "myweb" there. Th screen shot is given bellow:


After create the directory "myweb", create the html files. I am going to create a simple html file named "index.html".


  • Configure apache server to serve files in the folder "myweb".

For configure apache server we have to change the current directory to "/etc/apache2/sites-available". In this folder there will be a file named "000-default.conf",and "default-ssl.conf" open that file in "vim" editor
 with "sudo" permission. In this file change the path of  "DocumentRoot" to
 "/var/www/myweb".

Before changing the "DocumentRoot".






After changing the "DocumentRoot".


After changing the apache configaration we have to restart the apache server using command "sudo service apache2 restart".

After that, in a browser type the ip address of the machine where the apache server is installed. There you can see the html page that we have created.



No comments:

Post a Comment