Nextpertise a journal of interesting technical ideas . . .

Simple Apache Setup on Linux

by Brent Stewart on Monday, Aug 30, 2021

I’ve been running the free version of ESXi 6.5 for a while, but the vulnerabilities kept piling up and I had issues upgrading it. I’ve been looking at ProxMox VE for a while and last week I decided to give it a chance. I want to get more experience with the server before I write about it, so I’ll start by detailing a simple process to get a local webserver running. Browsers keep trying to throw distracting junk in front of me for start pages when what I really want is to quickly get to the sites I need. I put together a simple page that organizes my personal and work links for this purpose.

I built this server on Ubuntu 21.04 Server and my instructions are written from that perspective. Notes around the firewall and restarting the service will vary by distribution and version, but I’ll leave translation as an exercise to the reader. Installing a webserver is straightfoward - there are a variety to choose from, but Apache is good for this purpose because it’s so well documented. Once the package is downloaded and the service started, you should be able to browse to http://127.0.0.1 and see the default Apache page. When I did this at home, Ubuntu 21.04 had the firewall up by default, so I needed to allow the Apache service.

sudo apt update
sudo apt install apache2
sudo ufw allow 'Apache'

You’ll need to put your files somewhere for serving. Apache puts content in /var/www by default so I created a directory for my site user at /var/www/stewart. With that done, the website needs to be defined for Apache. The Apache config files are found at /etc/apache2. To setup a new site I created a stewart.conf under /etc/apache2/sites-available. Below is a simple configuration file.

<VirtualHost *:80>
    ServerAdmin my@email
    ServerName www.stewart.local
    ServerAlias www.stewart.local
    DocumentRoot /var/www/stewart
    <Directory /var/www/stewart>
        Options Indexes FollowSymLinks Multiviews
        AllowOverride All
        Require all granted
        allow from all
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

The site then needs to be activated. Enabling the site is done with a2ensite and it can be disabled with a2dissite. This will create a link into the /etc/apache2/sites-enabled/ directory. The web service will need to be restarted at that point as well. When it restarts, it reads the conf files it finds in sites-enabled.

sudo a2ensite stewart.conf
sudo systemctl reload apache2

With that, you should be able to browse to the local server and see the site!



References:
  

Recent articles related to these tags: Linux Apache
Share this article:    Tweet