A Comprehensive Guide to Installing Apache Server on Ubuntu



Apache is mostly use web server to host web sites and web applications, in this article i shown you how to install apache server on ubuntu.

Step 1: Update the Package Repository

Before we start, first we need to update system's package repository. when we update system it will be updating need full resource of Linux environment.  first Open Linux terminal and execute the below command:

    sudo apt update    

This command refresh all the available packages and their versions.

Step 2: Install Apache

Installation of apache on ubuntu is very easy, through the apt package manager execute the below command to start the installation process.

    sudo apt install apache2   

after running this command, we need to give confirmation to start installation. type 'Y" and press enter to start, then apache will be  star downloading and installing

Step 3: Start and Enable Apache

after apache installation done, its important to start the service and configure it to start apache server when system boot. for this enter below command:

   sudo systemctl start apache2     

   sudo systemctl enable apache2  

first command is use for Apache service, and second command is use for configure it to launch server every time when we reboot server.

Step 4: Verify Apache Installation

to check apache is successfully installed and running. open any browser (chrome or Mozilla Firefox), now enter IP address. now you see default webpage in Brower

if you unable to locate your ip address, then enter below command to find it.

 ip a | grep inet 

Step 5: Configure the Firewall

Iif firewall is enabled. you need to allow all users to accesses web server or allow incoming HTTP traffic, run below command to give access to incoming users.

  sudo ufw allow 'Apache'   

Step 6: Test Apache

to checkout apache server work correctly, create simple HTML file in to web directly, replace default html file with below simple HTML file. this file located in /var/www/html this path. use text editor nano to create sample file, paste below code and save file.

    sudo nano /var/www/html/index.html     

paste below  sample HTML code into the file and save it. For example:

  <!DOCTYPE html>
  <html>
  <head>
      <meta charset="UTF-8">
      <title>My Apache Server</title>
  </head>
  <body>
      <h1>Welcome to my Apache server!</h1>
  </body>
  </html>

Step 7: Restart Apache

to apply all changes restart the apache server entering below command

   sudo systemctl restart apache2   

Step 8: Access Your Website

Finally, open your browser and enter ip address or domain name to accesses your website. now you can see the html page you can created.

Congratulation! You have successfully created your first Apache web server.


Frequently Asked Questions (FAQs)

  1. Q1: What is Apache?
    Ans: apache server is use for host websites and web applications.
  2. Q2: Why should I install Apache on Ubuntu?
    Ans: for hosting websites and web application appache server install on linux server.
  3. Q3: How do I update the package repository?
    Ans: Use command sudo apt update
  4. Q4: What's the command to install Apache on Ubuntu?
    Ans: command is sudo apt install apache2
  5. Q5: How do I start and enable Apache?
    Ans: run command sudo systemctl start apache2 and sudo systemctl enable apache2
  6. Q6: How can I verify if Apache is installed correctly?
    Ans: Open browser and enter IP address to see default Apache webpage.
  7. Q7: How do I configure the firewall for Apache?
    Ans: use command to Allow incoming HTTP traffic sudo ufw allow 'Apache'
  8. Q8: How can I test if Apache is working by creating a simple HTML file?
    Ans: Create sample HTML file on this path /var/www/html/index.html and then check web page on browser.
  9. Q9: What's the command to restart Apache after making changes?
    Ans: Use command sudo systemctl restart apache2
  10. Q10: How do I access my website after setting up Apache?
    Ans: Enter server IP address or domain name in the web browser to get view website page.

Post a Comment

Previous Post Next Post