How to manage Apache Web Server

How to manage apache web server ?

Below are some basic apache web server management path and files which we should know to work smoothly.

Default Directory : /var/www/html/ By default apache served on this directory . While this can be changed by changing apache configuration file

Apache Configuratio Directory : /etc/apache2/ All apache configuration files resides here in this directory

Apache Mail configuration file : /etc/apache2/apache2.conf . The main apache configuration file

Apache listening ports file : /etc/apache2/ports.conf Having list of ports which apache will listen ( 80 and 443)

Virtual host stored file : /etc/apache2/sites-available/ Apache will not use this file unless its linked with sites-enabled directory

Enabled Virtual Host stored file : /etc/apache2/sites-enabled/ enabled per site virtual host directory. a2ensite links sites-available directory with sites-enabled directory

/etc/apache2/conf-available//etc/apache2/conf-enabled/: These directories have the same relationship as the sites-available and sites-enabled directories, but are used to store configuration fragments that do not belong in a virtual host. Files in the conf-available directory can be enabled with the a2enconf command and disabled with the a2disconf command.

/etc/apache2/mods-available//etc/apache2/mods-enabled/: These directories contain the available and enabled modules, respectively. Files ending in .load contain fragments to load specific modules, while files ending in .conf contain the configuration for those modules. Modules can be enabled and disabled using the a2enmod and a2dismod command.

/var/log/apache2/access.log: By default, every request to your web server is recorded in this log file unless Apache is configured to do otherwise.

/var/log/apache2/error.log: By default, all errors are recorded in this file. The LogLevel directive in the Apache configuration specifies how much detail the error logs will contain.


* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.

How to setup virtual host on apache web server in ubuntu

How to setup virtual host on apache web server in ubuntu.

To encapsulate configuration details we can use virtual host feature. We can host more than 1 website also on ubuntu server.

Apache on ubuntu has a server block enabled by default and default folder is /var/www/html

if we need to host a single website then above path is okay and we can continue our development on default folder.

But in case we need to host multiple website then we should follow virtual host feature

Step 1 : So lets create directory for our domain name

sudo mkdir /var/www/domainname

Step 2 : Lets assign the ownership of the directory with the $user environment variable

sudo chown -R $USER:$USER /var/www/your_domain

The permissions of your web roots needs to be correct if you haven’t modified your umask value, which sets default file permissions. To ensure that your permissions are correct and allow the owner to read, write, and execute the files while granting only read and execute permissions to groups and others, run below command

sudo chmod -R 755 /var/www/your_domain

Step 3 : Create a web page on above domain

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

enter some html into this file and save and close it

Step 4 : Now Apache need to host this page . it’s necessary to create a virtual host file with the correct directives.

Instead of modifying the default configuration file located at /etc/apache2/sites-available/000-default.conf

directly, let’s make a new one at /etc/apache2/sites-available/your_domain.conf

Step 5 : enter below data into file

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName domainname
    ServerAlias www.domainname
    DocumentRoot /var/www/domainname
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

updated  DocumentRoot to our new directory

updated ServerAdmin to an email that the domainname site administrator can access.

Added two directives: ServerName, which establishes the base domain that should match for this virtual host definition,

ServerAlias, which defines further names that should match as if they were the base name.

Save and close the file

Step 6 : Lets enable the file with a2ensite tool 

sudo a2ensite your_domain.conf

Disable the default site defined in 000-default.conf:

sudo a2dissite 000-default.conf

Lets test for configuration errors

sudo apache2ctl configtest

Output should be “syntax ok”

restart apache to implement changes

sudo systemctl restart apache2

Apache should now working for new hosted domainname


* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.

how to install apache on ubuntu

How to install apache on ubuntu ?

The Apache HTTP server is the most widely-used web server in the world. It is having vast features at control level. You will see all features with time

Let us go step by step on  how to install an Apache on Ubuntu  20.04 server.

Step 1 : We should have the root credentials for server .

Step 2 : Create the new user with below command as we should not login from root credential

adduser <username>

This will add user and will ask for password . Set a strong password for user

Some information is not mandatory here so you can skip that by pressing enter only

Step 3 : Grant Admin Previleges

Add user to sudo group by below command

usermod -aG sudo <username>

Now <username> has right to perform all admin activities but with sudo keyword

Step 4 : Firewall Setting

Ubuntu UFW firewall just allow few services to run

Step 5 : run below command to see available applications

ufw app list

Step 6 : allow ssh connection so that user can log back

ufw allow OpenSSH

Output will be

Rules Updated

Rules Updated ( V6)

Step 7 : Enable the firewall

ufw enable

Now firewall is allowing only SSH connections. So whenever we are going to install any additional service then we need to set firewall setting.

Step 8  check the firewall Status

ufw status

Step 9 : just check user access on new terminal by running following command

ssh <username>@serverip

step 10 : just check the latest package index by below command

sudo apt update

Step 11 : Apache is available in ubutu repository so by below command we can install apache on ubuntu server

sudo apt install apache2

Accept the installation and Apache will be installed with all dependencies

Step 12 : We need to set some firewall settings so that public user can access the port .

Fetch the list of UFW application by below command

sudo ufw app list

In my case i got below list

Available applications:
  Apache Full
  Apache Secure

As indicated by the output, there are three profiles available for Apache:

  • Apache: This profile opens only port 80 (normal, unencrypted web traffic)
  • Apache Full: This profile opens both port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
  • Apache Secure: This profile opens only port 443 (TLS/SSL encrypted traffic)

Step 13 : So we need to enable most safe and restrictive profile. So lets do this by below command

sudo ufw allow ‘Apache’

Step 14 : Lets verify the change

sudo ufw status

Here in output you can see we have anywhere access of apache and apache(v6)

Step 15: Lets test the apache web server

sudo systemctl status apache2

Step 16. Lets see some basic command on apache

How to stop apache process

sudo systemctl stop apache2

How to start apache process

sudo systemctl start apache2

How to restart apache process

sudo systemctl restart apache2

In case of activation of only config changes you may need to reload apache so that connection should not drop

sudo systemctl reload apache2

By Default Apache services started automatically on reboot but if you want to disable it

sudo systemctl disable apache2

To enable apache service on startup

sudo systemctl enable apache2


* The Content stated above is for informational purpose only. Expert Software Team is not responsible if any part of content found meaningless in any manner or condition.