Here is how you can install Apache2 on Ubuntu. In particular on Vultr’s instance i.e. Ubuntu 16.04 / 18.10 and 18.04 LTS.
- Have an Ubuntu 16.04 x64 / 18.01 x64 / 18.10 x64 instance.
- Logged in as a root with sudo privileges.
To get started with the installation of Apache2, follow the steps below:
Install Apache2 on Ubuntu
Before to install Apache2 server, run the following commands first to update Ubuntu:
sudo apt update sudo apt upgrade
Next, install Apache web server:
sudo apt install apache2
This is it, Apache2 is installed and it starts automatically. You can check the Apache2 service status by using the following command:
sudo systemctl status apache2
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2019-04-16 00:35:04 UTC; 1h 30min ago Process: 1376 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS) Process: 1381 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 1396 (apache2) Tasks: 11 (limit: 502) Memory: 84.1M CGroup: /system.slice/apache2.service ├─1396 /usr/sbin/apache2 -k start ├─2159 /usr/sbin/apache2 -k start ├─2160 /usr/sbin/apache2 -k start ├─2161 /usr/sbin/apache2 -k start ├─2162 /usr/sbin/apache2 -k start ├─2163 /usr/sbin/apache2 -k start ├─2164 /usr/sbin/apache2 -k start ├─2165 /usr/sbin/apache2 -k start ├─2166 /usr/sbin/apache2 -k start ├─2167 /usr/sbin/apache2 -k start └─2198 /usr/sbin/apache2 -k start Apr 16 00:35:04 yourdomain.com systemd: Starting The Apache HTTP Server... Apr 16 00:35:04 yourdomain.com systemd: Started The Apache HTTP Server.
The other following commands used to stop, start and enable Apache2 service.
sudo systemctl stop apache2.service sudo systemctl start apache2.service sudo systemctl enable apache2.service
Verifying the Apache2 Installation
To verify that Apache2 working, open your browser, write your domain name or server IP address i.e.
http://YOUR_IP_OR_DOMAIN/and you will see the following default Ubuntu Apache welcome page.
Apache Configuration File’s Structure and Best Practices
- All Apache configuration files are located in the
apache2.confis the main configuration file. It puts the pieces together by including all remaining configuration files when starting up the web server.
/etc/apache2/ports.conf.is always included from the main configuration file. It is used to determine the listening ports for incoming connections, and this file can be customized anytime.
- Apache Virtual Hosts files are stored in
/etc/apache2/sites-availabledirectory. The configuration files found in this directory are not used by Apache unless they are linked to the
- They are activated by symlinking available configuration files from their respective
*-available/counterparts. These should be managed by using our helpers a2enmod, a2dismod, a2ensite, a2dissite, and a2enconf, a2disconf. See their respective man pages for detailed information.
- It is a good idea to follow a standard naming convention. For example, if your domain name is
yourdomain.comthen the virtual host configuration file should be named
- Files containing global configuration fragments are stored in the
/etc/apache2/conf-available/directory. Files in the
conf-availabledirectory can be enabled by creating a symlink to the
/etc/apache2/conf-enabled/with the a2enconf command and disabled with the a2disconf command.
- Apache log files (access.log and error.log) are located in the
/var/log/apache/directory. It is recommended to have different access and error log files for each vhost.
- The default Ubuntu document root is
/var/www/html. You can make your own virtual hosts under
You have learned how to install Apache2 on Ubuntu server. You can repeat the steps we outlined above and install Apache2 on additional new Ubuntu servers.