No other Web server package is anywhere close to being as popular as Apache is. It’s currently estimated that just over half of all sites online serve from an Apache package. Ubuntu and Debian are popular Linux distributions for server systems, and both of them come with special server-only packages. This makes Apache and either Debian or Ubuntu a winning combination under a majority of configurations. While there are many other server packages to choose from, Apache is useful because of how many different routines are compatible with it.
While Debian and Ubuntu build the Apache packages in the same way, this differs from some other server structures. openSUSE and most of the commercial Linux distributions have their own ways of building it. If you’re familiar with the DEB package management scheme, then you might already be familiar with some of the techniques used to get this popular server architecture installed.
Installing and Configuring the Apache Packages
Ubuntu and Debian server technology often comes with no desktop environment loaded at all. You’ll more than likely be working with a pure Bash CLI interface, though you could install another command interpreter if you’d like. For this discussion, we’ll assume you’re working from a virtual console under a user account. You can switch between virtual consoles by holding down CTRL and pushing F1-F6. The CTRL+F7 key is reserved for an XFree86 server, which you more than likely don’t have under this configuration.
Start by logging into your account. Once you’ve reached the $ prompt you can begin installing Apache Web Server. Issue the following commands followed by pushing return:
sudo apt-get update
sudo apt-get install apache2
Depending on your installation you may receive either a ton of output or not much at all. If you get some warning about the packages already having been installed, then try issuing man apache2. If you get a proper man page, then it’s already installed. If it reads “No man entry for apache2,” then you will want to try installing again.
Once the packages get installed you’ll already be running a working Web server. Testing if Apache is running correctly requires a Web browser. Either access your VPS’ IP address by typing it into the address bar of an active graphical Web browser connected to the Internet on another machine or head to a CLI browser like Lynx and do the same.
You’ll get a very basic page that reads your domain name or your server’s IP address if it’s working properly. This means you have the server running, but you’ve added nothing to your page yet. Now you can begin configuration if so desired. Use the cd command to head to the Apache directory by typing and then type ls to get a directory listing. If your server doesn’t give you color output, then either use dir –color or ls –color to see which entries are plain text files and which directories. What’s in the listing will depend on which version of the Apache packages installed. Several places in the file structure are of particular importance:
– ports.conf: Virtual hosts listen to ports registered inside this file. Make sure that the information is up to date in order to support your SSL system. If you use SSL, then you’ll also want to try sudo nano conf.d to check SSl configuration and security defaults.
– apache2.conf: Most configuration options get set in this file, and the apache2 binary will always check this file first to see if a specific option got set. Type sudo nano apache2.conf when you’re in the directory to edit this file. You notice that this file features three separate sections. The first allows you to change Apache server processes on a global level. Default server settings are all placed in the second section, and virtual hosts are defined in the third. Debian-based distributions, including Ubuntu, require most configuration at the bottom by using the include directives. There are a number of include settings at the bottom of the file.
– sites-available & sites-enabled: These are both subdirectories inside of the directory. The first defines which content is served regardless of which configurations are active. The second defines virtual host definitions, and it mostly contains symlinks to files stored in the first.
You may receive an error during configuration that reads:
The program ‘nano is currently not installed. You can install it by typing:
sudo apt install e3
This means your Ubuntu or Debian server installation doesn’t actually include the nano text editor. You can install it by issuing the selected command, or replace the word nano with vi in most of your commands. Some form of vi or vim will generaly be included in your package. This is also a good idea if you prefer vi over nano.
When you’re looking over the include and other configuration lines, you may find a few major ones you’ll want to change. Apache sets a timeout parameter of 300, which means that your server has 300 seconds to serve each request. Most people like this under a minute. KeepAlive generally defaults to off, which forces each request to load a new connect. Turning it to on allows connections to stay open so clients can issue multiple requests. If you adjust this, then set a custom number in the MaxKeepAliveRequests section. This line tells Apache how many individual requests a connection handles before it dies off. Setting it to 0 will force Apache to serve unlimited requests to each connection. You can also kill off connections by setting a timeout threshold number in seconds on the KeepAliveTimeout line.
If you want to check which modules were compiled into your Apache package, then head back to the CLI prompt and issue this command:
You might see prefork.c, http_core.c, mod_so.c and many other options. The http_core.c code more than likely had to be included in order for your Apache package to work properly. Debian and Ubuntu packages installed via the apt system tend to have all of the necessary modules compiled in from when they were made.