install apache2 ubuntu code example

Example 1: remove apache2 from ubuntu

#stop the apache2 service 
$ sudo systemctl stop apache2 

#remove apache2 packages
$ sudo apt-get purge apache2 apache2-utils apache2-bin apache2.2-common

# cleanup
$ sudo apt-get autoremove

# check if the apache has been removed:
#1- following command line should return a blank line
$ which apache2   
# 2- following command line should return apache2: Failed to start apache2.service: Unit apache2.service not found.
$ sudo systemctl start apache2

Example 2: start apache2 ubuntu

# Restart Apache 2 server on Linux/Unix
sudo service apache2 restart

# Start Apache 2 server on Linux/Unix
sudo service apache2 start

# Stop Apache 2 server on Linux/Unix
sudo service apache2 stop

# Reload Apache 2 server on Linux/Unix "No downtime!"
sudo service apache2 reload

Example 3: reinstal apache2 ubuntu

sudo apt-get --purge remove apache2
sudo apt-get autoremove
sudo apt-get install apache2
sudo /etc/init.d/apache2 restart

Example 4: ubuntu install apache2

sudo apt-get install apache2

Example 5: apache2 ubuntu install

sudo apt install apache2

Example 6: how to install apache server in ubuntu

sudo apt update
sudo apt install apache2