DEV Community

Cover image for Install Apache Webserver:
MuthuKumar
MuthuKumar

Posted on • Updated on

Install Apache Webserver:

To install the Apache web server on Ubuntu using the terminal, follow these steps:

  1. Open Terminal:
    You can press Ctrl + Alt + T to open a terminal window.

  2. Update Package List:
    Run the following command to update the package list before installing Apache:

   sudo apt update
Enter fullscreen mode Exit fullscreen mode
  1. Install Apache: Use the following command to install Apache:
   sudo apt install apache2
Enter fullscreen mode Exit fullscreen mode
  1. Start Apache Service: Once Apache is installed, start the Apache service:
   sudo systemctl start apache2
Enter fullscreen mode Exit fullscreen mode
  1. Enable Apache to Start at Boot: To ensure that Apache starts automatically when your system boots up, enable the Apache service:
   sudo systemctl enable apache2
Enter fullscreen mode Exit fullscreen mode
  1. Check Apache Status: You can verify whether Apache is running by checking its status:
   sudo systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

This command will display information about the Apache service's current status.

  1. Adjust Firewall (if needed): If you have a firewall enabled (like ufw), you might need to allow HTTP traffic. You can use the following command:
   sudo ufw allow 'Apache'
Enter fullscreen mode Exit fullscreen mode

Replace 'Apache' with 'WWW Full' if you're using the default UFW application profiles.

  1. Test Apache Installation: Open a web browser and enter your server's IP address or domain name. If Apache is installed correctly, you should see the default Apache2 Ubuntu Default Page.

That's it! You've successfully installed Apache on your Ubuntu system. You can now proceed to install other components of your LAMP stack, such as MySQL and PHP, to complete your web server setup.

Try it YourSelf:

Update Package List:

muthukumar@DevOpsEngineer:~$ sudo apt update
Get:1 http://packages.microsoft.com/repos/code stable InRelease [3,569 B]
Get:2 http://packages.microsoft.com/repos/code stable/main arm64 Packages [77.2 kB]
Hit:3 https://dl.google.com/linux/chrome/deb stable InRelease                  
Get:4 http://packages.microsoft.com/repos/code stable/main armhf Packages [77.7 kB]
Get:5 http://packages.microsoft.com/repos/code stable/main amd64 Packages [76.8 kB]
Hit:6 http://in.archive.ubuntu.com/ubuntu jammy InRelease                      
Get:7 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]      
Ign:8 https://pkg.jenkins.io/debian binary/ InRelease                          
Hit:9 https://pkg.jenkins.io/debian binary/ Release                            
Get:10 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB]    
Hit:12 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu jammy InRelease  
Hit:13 https://www.mediahuman.com/packages/ubuntu jammy InRelease              
Hit:14 https://ppa.launchpadcontent.net/obsproject/obs-studio/ubuntu jammy InRelease
Get:15 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease [109 kB]
Get:16 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 DEP-11 Metadata [101 kB]
Get:17 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 DEP-11 Metadata [278 kB]
Hit:18 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy InRelease      
Get:19 http://in.archive.ubuntu.com/ubuntu jammy-updates/multiverse amd64 DEP-11 Metadata [940 B]
Get:20 http://in.archive.ubuntu.com/ubuntu jammy-backports/main amd64 DEP-11 Metadata [4,932 B]
Get:21 http://in.archive.ubuntu.com/ubuntu jammy-backports/universe amd64 DEP-11 Metadata [15.5 kB]
Hit:22 https://ppa.launchpadcontent.net/umang/indicator-stickynotes/ubuntu jammy InRelease
Hit:23 https://ppa.launchpadcontent.net/wireshark-dev/stable/ubuntu jammy InRelease
Get:24 http://security.ubuntu.com/ubuntu jammy-security/main amd64 DEP-11 Metadata [42.8 kB]
Get:25 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 DEP-11 Metadata [39.9 kB]
Fetched 1,055 kB in 13s (83.3 kB/s)                                            
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
52 packages can be upgraded. Run 'apt list --upgradable' to see them.
W: https://www.mediahuman.com/packages/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Enter fullscreen mode Exit fullscreen mode

Install Apache:

muthukumar@DevOpsEngineer:~$ sudo apt install apache2
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  apache2-data apache2-utils
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom
The following NEW packages will be installed:
  apache2 apache2-data apache2-utils
0 upgraded, 3 newly installed, 0 to remove and 52 not upgraded.
Need to get 352 kB of archives.
After this operation, 1,828 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 apache2-data all 2.4.52-1ubuntu4.6 [165 kB]
Get:2 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 apache2-utils amd64 2.4.52-1ubuntu4.6 [89.1 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 apache2 amd64 2.4.52-1ubuntu4.6 [97.8 kB]
Fetched 352 kB in 2s (165 kB/s)   
Selecting previously unselected package apache2-data.
(Reading database ... 241699 files and directories currently installed.)
Preparing to unpack .../apache2-data_2.4.52-1ubuntu4.6_all.deb ...
Unpacking apache2-data (2.4.52-1ubuntu4.6) ...
Selecting previously unselected package apache2-utils.
Preparing to unpack .../apache2-utils_2.4.52-1ubuntu4.6_amd64.deb ...
Unpacking apache2-utils (2.4.52-1ubuntu4.6) ...
Selecting previously unselected package apache2.
Preparing to unpack .../apache2_2.4.52-1ubuntu4.6_amd64.deb ...
Unpacking apache2 (2.4.52-1ubuntu4.6) ...
Setting up apache2-data (2.4.52-1ubuntu4.6) ...
Setting up apache2-utils (2.4.52-1ubuntu4.6) ...
Setting up apache2 (2.4.52-1ubuntu4.6) ...
Enabling module mpm_event.
Enabling module authz_core.
Enabling module authz_host.
Enabling module authn_core.
Enabling module auth_basic.
Enabling module access_compat.
Enabling module authn_file.
Enabling module authz_user.
Enabling module alias.
Enabling module dir.
Enabling module autoindex.
Enabling module env.
Enabling module mime.
Enabling module negotiation.
Enabling module setenvif.
Enabling module filter.
Enabling module deflate.
Enabling module status.
Enabling module reqtimeout.
Enabling conf charset.
Enabling conf localized-error-pages.
Enabling conf other-vhosts-access-log.
Enabling conf security.
Enabling conf serve-cgi-bin.
Enabling site 000-default.
Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /l
ib/systemd/system/apache2.service.
Could not execute systemctl:  at /usr/bin/deb-systemd-invoke line 142.
Created symlink /etc/systemd/system/multi-user.target.wants/apache-htcacheclean.
service → /lib/systemd/system/apache-htcacheclean.service.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for ufw (0.36.1-4ubuntu0.1) ...

Enter fullscreen mode Exit fullscreen mode

Start Apache Service:

Step1:

muthukumar@DevOpsEngineer:~$ sudo systemctl start apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xeu apache2.service" for details.

Enter fullscreen mode Exit fullscreen mode

Step2:

muthukumar@DevOpsEngineer:~$ sudo systemctl enable apache2
Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable apache2

Enter fullscreen mode Exit fullscreen mode

Step3:

muthukumar@DevOpsEngineer:~$ sudo systemctl status apache2
× apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
     Active: failed (Result: exit-code) since Wed 2023-08-16 12:30:52 IST; 44s >
       Docs: https://httpd.apache.org/docs/2.4/
        CPU: 28ms

Aug 16 12:30:52 DevOpsEngineer apachectl[14686]: AH00558: apache2: Could not re>
Aug 16 12:30:52 DevOpsEngineer apachectl[14686]: (98)Address already in use: AH>
Aug 16 12:30:52 DevOpsEngineer apachectl[14686]: (98)Address already in use: AH>
Aug 16 12:30:52 DevOpsEngineer apachectl[14686]: no listening sockets available>
Aug 16 12:30:52 DevOpsEngineer apachectl[14686]: AH00015: Unable to open logs
Aug 16 12:30:52 DevOpsEngineer apachectl[14683]: Action 'start' failed.
Aug 16 12:30:52 DevOpsEngineer apachectl[14683]: The Apache error log may have >
Aug 16 12:30:52 DevOpsEngineer systemd[1]: apache2.service: Control process exi>
Aug 16 12:30:52 DevOpsEngineer systemd[1]: apache2.service: Failed with result >
Aug 16 12:30:52 DevOpsEngineer systemd[1]: Failed to start The Apache HTTP Serv>
lines 1-16/16 (END)

Enter fullscreen mode Exit fullscreen mode

Step4:

muthukumar@DevOpsEngineer:~$ sudo systemctl start apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xeu apache2.service" for details.

Enter fullscreen mode Exit fullscreen mode

Step5:

muthukumar@DevOpsEngineer:~$ sudo systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset:>
     Active: active (running) since Wed 2023-08-16 11:22:49 IST; 1h 9min ago
       Docs: man:nginx(8)
   Main PID: 906 (nginx)
      Tasks: 9 (limit: 9110)
     Memory: 19.4M
        CPU: 106ms
     CGroup: /system.slice/nginx.service
             ├─906 "nginx: master process /usr/sbin/nginx -g daemon on; master_>
             ├─907 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─910 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─911 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─912 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─913 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─914 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >
             ├─915 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >
             └─917 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" >

Aug 16 11:22:49 DevOpsEngineer systemd[1]: Starting A high performance web serv>
Aug 16 11:22:49 DevOpsEngineer systemd[1]: Started A high performance web serve>



Enter fullscreen mode Exit fullscreen mode

Step6:

muthukumar@DevOpsEngineer:~$ sudo systemctl stop nginx

Enter fullscreen mode Exit fullscreen mode

Step7:

muthukumar@DevOpsEngineer:~$ sudo systemctl start apache2
Enter fullscreen mode Exit fullscreen mode

Step8:

muthukumar@DevOpsEngineer:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor prese>
     Active: active (running) since Wed 2023-08-16 12:32:13 IST; 6s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 14827 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/S>
   Main PID: 14831 (apache2)
      Tasks: 55 (limit: 9110)
     Memory: 5.1M
        CPU: 52ms
     CGroup: /system.slice/apache2.service
             ├─14831 /usr/sbin/apache2 -k start
             ├─14832 /usr/sbin/apache2 -k start
             └─14833 /usr/sbin/apache2 -k start

Aug 16 12:32:13 DevOpsEngineer systemd[1]: Starting The Apache HTTP Server...
Aug 16 12:32:13 DevOpsEngineer apachectl[14830]: AH00558: apache2: Could not re>
Aug 16 12:32:13 DevOpsEngineer systemd[1]: Started The Apache HTTP Server.
lines 1-17/17 (END)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)