a2ensite is a command used to enable an Apache2 web server configuration file, known as a site, on an Ubuntu system. When you run the a2ensite command followed by the name of the site configuration file, the file is symlinked to the /etc/apache2/sites-enabled/ directory. This enables the web site defined in the configuration file, allowing it to be served by the Apache2 web server.
To use a2ensite, you must first have the Apache2 web server installed on your Ubuntu system. You can install Apache2 by running the following command:
$ sudo apt-get install apache2
Once Apache2 is installed, you can use a2ensite to enable a site configuration file. For example, to enable the site configuration file mysite.conf, you would run the following command:
$ sudo a2ensite mysite.conf
After running this command, the Apache2 web server will automatically reload its configuration and the web site defined in mysite.conf will be enabled and available to be served. It’s important to note that a2ensite only enables a site configuration file. It does not create the configuration file or define the content of the web site. To create a site configuration file and define the content of a web site, you will need to edit the file manually or use a tool like a2dissite to disable a site.
If you encounter the below error while running the a2ensite command:
a2ensite: command not found
you may try installing the below package as per your choice of distribution:
OS Distribution | Command |
---|---|
Debian | apt-get install apache2 |
Ubuntu | apt-get install apache2 |
Alpine | apk add apache2 |
Kali Linux | apt-get install apache2 |
Raspbian | apt-get install apache2 |
a2ensite Command Examples
1. Enable a virtual host:
$ sudo a2ensite {{virtual_host}}
2. Don’t show informative messages:
$ sudo a2ensite --quiet {{virtual_host}}
3. Enable multiple site configuration files at once:
$ sudo a2ensite mysite1.conf mysite2.conf mysite3.conf