Homework for students: How to install Apache2 webserver on Ubuntu?
This is pretty simple. It only takes a single line of commands to install Apache2 on Ubuntu servers. The difficult part is configuring it and there are many opinions of how to properly do it.
This simple tutorial is going to show students and anyone who wants to know how to install Apache2 on Ubuntu servers. It will also go into configuring it a bit.
If you’re reading this post, then you probably know a thing or two about Apache2 web server. If you don’t know, it is the most popular web server in use today. Many of the websites and blogs you read online today probably run on Apache2.
Apache2 is a big deal!
To get started installing and configuring Apache2, continue with the steps below:
Step 1: Installing Apache2 server
It only takes a single command line to install Apache2. The difficult portion is configuring it to run properly.
To install Apache2 on Ubuntu, run the commands below.
sudo apt-get -y install apache2
Step 2: Managing Apache2 server
After you install Apache2, it might be better to know simple commands to manage the server. The lines below show you how to stop, start, restart and reload Apache2 server.
— Stops the server:
sudo systemctl stop apache2
— Starts the server:
sudo systemctl start apache2
— Restarts the server:
sudo systemctl restart apache2
— Reload config changes no stops:
sudo systemctl reload apache2
Step 3: Configuring Apache2 Server
When Apache2 is installed on Ubuntu, by default its root directory is created at this location: /var/www/html
Any file you save in there that is probably configured with HTML standard ending in .html, apache2 will be able to serve to web clients. It is the root directory for the server.. This is the location the server looks to serve .html/htm documents.
The majority of Apache2 configuration files are stored in /etc/apache2 directory. In this directory is where you’ll fine server configuration settings, root directory controls and many of the different files that control Apache2 servers.
Two important locations that you’ll spend most of your time are /etc/apache2/sites-available and /etc/apache2/sites-enabled
The sites-available directory contains all the available sites. This is the location you create new sites in. and sites-enabled directory contains all sites that are enabled. By default, sites are not enabled until you run a commands to enable them.
The first default available site that’s also enabled is /etc/apache2/sites-available/000-default.conf
This file contains the basic Apache2 test settings configurations. You can keep the default site and continue to configure it or copy the default site into something new and work from there. Make sure to enable the new site though.
Steps 4: Enabling and Disabling Apache2 Sites
After you configure your sites, you must enable them before they become operational. The commands below show you how to enable and disable Apache2 sites.
— Enable site example.com
sudo a2ensite example.com
— Disable site example.com
sudo a2dissite example.com
Other modules can be enabled and disabled as well. Modules are codes/programs that are used to enhance Apache2 functionality or enable new features.
— Enable a module:
sudo a2enmod module_name
— Disballe a module:
sudo a2dismod module_name
This is the basic to Apache2. In the future, we’ll discuss more advanced stuff.
Because Apache2 is installed and the default site enabled, if you open your web browser and browse to the computer name or IP address, you’ll see Apache2 default test page.
This page shows because of a single index.html file in Apache2 root directory.
You may also like the post below: