Acting as a web server is a common task for a Linux system. Find out how to install the popular Apache web server package.
- [Instructor] Web technologies allow a huge range of information sharing and application functionality. The Apache http server is a very commonly used package for both internally and externally focused web servers. To configure a Linux system to act as a web server, I'll install the Apache Two package. I'll write apt install apache2. (fingers tapping keyboard) Without any configuration this will set up a basic http website serving content from the var www html directory.
In fact, I can open up a browser here and take a look at "Local Host", and see the place holder page that Apache provides me. Apache and Ubuntu has a few different configuration files and it's worth taking a moment to learn about them. On wn drive systems we use a series of configurations and symlinks to configure what sites and configurations are available at any given time. The primary configuration file etc apache2 apache2.conf brings these together and sets global options for the web servers.
Let's take a look in there. Right up here at the top is on overview of how the configuration files work together. And a little further down are the various global options and some advanced setting for different modes of operation. Below that there's some definitions of different paths and their access permissions. As you start working with Apache you'll become familiar with these definition blocks. In this case we have four directories. For the root directory we're denying access. For usr share and var www we're allowing the web server to show the contents if requested.
And the same for the srv directory, but that block is commented out. A little further down we can see that the server will look in each directory it's serving for a dot ht access file for more specific configurations. Then there's some options about logging formats, and down here at the bottom we see where the server is bringing in other configurations and other sites. To make changes to individual sites that our server provides, rather than make changes in this file, we modify a configuration file in the sites available folder, and then link it into the sites enabled folder when we want to make it active.
This gives us the flexibility of managing individual sites fairly easily while keeping things organized and modular. Let's take a look inside the sites available folder and see how it's set up. I'll write ls etc apache2 sites available. This zero zero zero dash default dot conf file is our primary, or default site. The number at the beginning allows us to set a precedence of sites because Apache will process these configuration files numerically.
That's a clever hack you'll see in all kinds of different places on linux to allow easy control of the order of things. Let's open up that file and take a look at it. I'll write nano etc apache2 sites available and the file name. This is a declaration of a Virtual Host. Inside it we see a directive that gives an e-mail address for the administrator of the site and also the document root.
Or, the path where this particular site is served from. This site route needs to be located within the scope we saw in the Apache2.conf file. Somewhere under the directories where the web server is allowed to serve content from. We can set where a particular log file for this site goes as well. I'm not going to make any changes here right now because this is the minimal set of things we need to define a site. And this site works. I could add files into the var www html folder if I wanted to make a static http site. Though to add more support for other things like php, I'd need to add more modules.
I can see which modules are currently loaded using the apache ctl dash M command. I can enable or disable modules using a2enmod or a2dismod. If you want to see the modules available to install you can use the command apt list libapache2 mod with a star.
So install support for php I'd use apt install libapache2 mod php. Running apache ctl dash m again I can see that the php module is available. The installer enabled it for me. To disable it, I write a2dismod php7.0 and I'm reminded to restart the web server so this change can take affect. This isn't a web design course, so we won't get into building web pages here, but if you're so inclined you can put together a basic html page called index to use for your server instead of the default page provided.
- Service management
- Accessing systems remotely with SSH
- Configuring web servers
- Configuring a database
- Configuring remote logging