The A in LAMP

Cody Lake
intro2codee
Published in
5 min readDec 16, 2020

Reload, restart, and enable Apache with confidence to use the Internet’s #1 HTTP server

In this article, we move from a full LAMP stack installation to navigating Apache basics. Follow along to learn commands for Apache, the A in LAMP. As a bonus, learn some core open-source community principles and history.

Please be patient and aware that errors during installation may be due to differences in environment. This article outlines usage on a single machine running a Linux distribution, specifically Ubuntu 18.04.

You may be surprised to learn that many major corporations and governments make use of the Linux operating system (OS) but less than five per cent of computer users have Linux as their desktop environment.

Before my own experience in a web development boot camp, I, too, was part of the super majority of non-Linux users.

Linux, in its many flavors, is found in everything from industrial controls, supercomputers, cars, and cable boxes, to a majority of global smartphones. It feels gratifying to learn a little bit about how the OS functions.

The kernel is at Linux’s heart. The kernel provides hooks for all measures of software to dig into. In the scope of this article, we run several commands to install LAMP and explore our Apache server configuration. These commands, entered into the command line, are really programs.

Linux combined with straightforward programs, allows us to engage in the flexibility and usability of this mainly free and open-source software. We can thank Linus Torvalds for the first release of Linux in 1991. Proving then, that the nineties was good for something other than grunge-glam and Kurt Cobain.

Without Linux, and open-source more broadly, us web developers (hobbyists and professionals), would be stuck in the binding of licensing restrictions. No fun.

Restricting open-source would be like forcing computer programmers into Adobe Creative Cloud subscriptions. In practice, community driven development springs up in a variety of industries and arts.

Let’s get started!

LAMP stands for Linux, Apache, MySQL, PHP. This stack of technology is quite popular and has matured a lot over time.

With Ubuntu, we can install the entire stack with one command in our terminal.

sudo apt install lamp-server^

At the prompt, enter your password of choice for the MySQL root user.

I also encourage you to get familiar with the file system names used by Linux. At first, it can seem like a bit of alphabet soup. That’s okay.

After install is complete, take a look at your very own localhost by typing localhost into the address bar of your browser. The term localhost has significance in computer networking. For now, just remember that localhost is the hostname that refers to the current computer used to access it.

If you see something like this. It works!

Apache on Ubuntu

All of our web applications will have a default path of /var/www, which the Apache web server creates. Type the following command into your terminal to view files and check privileges. We are looking for the www directory result.

ls -l /var

By default, the root (superuser) has ownership. Use the following command to allow yourself ownership. Replace username and usergroup with your machine’s user name. That is, the one you log onto your machine with.

sudo chown username:usergroup -fR /var/www

See the results by running a command for your file lists again.

ls -l

Any virtual host (VHOST) files are stored by Apache on Debian based systems in the sites-available directory. Move into the directory with the following commands and list the file types. Again, these commands are entered into your terminal.

cd /etc/apache2/sites-available

ls

Our terminal shows us two files, which are important. We’ll enter Apache’s default configuration and make a couple changes with either of the following commands.

sudo vim 000-default.conf

I prefer to edit text in nano instead of old-school vim, so, I would use:

sudo nano 000-default.conf

In this file, Apache stores our default settings in the form of directives. Remember the default page from our browser? We will now scroll down to about line 12 in our conf to update it. So, Apache will serve our www directory instead. Update your DocumentRoot so it reads as the following:

DocumentRoot /var/www

Save, close the file and now we take four steps in our terminal to disable the old site config, reload Apache, enable our new site config, and tell Apache to reload the configuration.

sudo a2dissite 0* && sudo service apache2 reload && sudo a2ensite 0* && sudo service apache2 reload

That is a lot of direction in just one line of code. Neat!

Navigating in the browser to http://localhost now shows a directory listing with a link to the html directory. As you complete projects served by Apache, localhost will be your trove of directories where you access these projects in the browser.

Now, we will work with our other default file to extend the Apache web server and allow it to work with Transit Layer Security connections, commonly referred to as SSL.

In your terminal, enter the following commands.

cd /etc/apache2/sites-available

sudo nano default-ssl.conf

Just like before, scroll to your DocumentRoot directive and change it to the following.

DocumentRoot /var/www

Save and close your document and now we will enable the SSL module from the command line.

sudo a2enmod ssl

Then use the following concatenated command to restart Apache after we load the new configuration.

sudo a2dissite d* && sudo service apache2 reload && sudo a2ensite d* && sudo service apache2 restart

Navigate to https://localhost (notice the ‘s’) and proceed past the insecure site warning. Yes, defy the browser’s suggestion.

We did just enable the SSL module but this is actually a snake oil certificate. It offers encryption without certificate authority verification. It is invalid SSL certification but it functions just fine for testing SSL connection.

At the bottom of your https://localhost window, you will see that Apache is being served over port 443, which is the default for https on the Internet.

At this point, we have installed our LAMP stack and learned how to use a2dissite and a2ensite to reload our Apache configuration. We now know how to use Apache web server directives to restart the Apache web server and also how to enable Apache modules. To boot, we know how to force a site to use SSL.

--

--

Cody Lake
intro2codee

Intoo.Studio creator and director. First-time experience and bouts of wisdom guaranteed.