WordPress Install – Part 3

Return to: Part 2

Apache2

The next step is to install the Apache2 web server. Apache2 is the name for the current Apache release – at this writing, version 2.4. Some operating systems such as the Macintosh OS have Apache2 already installed.

Apache2 is highly configurable – however few if any Apache2 options need to be set.

Be sure to do the APT updates described previously before installing Apache2.

When Apache2 is installed, it will create several configuration files – stored in multiple directories. Website files (including all of the WordPress files) will reside in what’s called the Apache2 “root directory.” On Debian distribution Linux systems, the Apache2 root will be created under the /var/ directory.

/var/

Using APT to install Apache2:

~$ sudo apt install apache2↵

The APT program will describe what is being requested to install, and ask you to confirm this before installing:

wp-ops@seebylooking:~ $ sudo apt install apache2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  apache2-bin apache2-data apache2-utils libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
Suggested packages:
  apache2-doc apache2-suexec-pristine | apache2-suexec-custom
  openssl-blacklist
The following NEW packages will be installed:
  apache2 apache2-bin apache2-data apache2-utils libapr1 libaprutil1
  libaprutil1-dbd-sqlite3 libaprutil1-ldap ssl-cert
0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,992 kB of archives.
After this operation, 6,229 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

It is important to review this screen when installing software with APT – and maybe even keeping a copy. It shows the additional software packages that are installed because they are required by the one you requested. And it may alert you to problems.

Some WordPress installation tutorials specify installing packages that may already be installed. If you’re unsure, it does no harm to reinstall them. And there are options of the APT command that list the packages already installed so it is possible to check them. But you may want to keep track as you are building your system.

The APT installation of Apache2 will create the Apache2 root directory. On Debian family Linux distributions, this is:

/var/www/html/

This directory will contain a single file:

/var/www/html/index.html

You can verify Apache2 is installed using the “apachectl” command with the “-v” option:

Last login: Thu Feb 20 17:45:26 2020
wp-ops@seebylooking:~$ apachectl -v↵
Server version: Apache/2.4.29 (Ubuntu)
Server built:   2019-09-16T12:58:48
wp-ops@seebylooking:~$ 

Note that this command reports that this Apache2 application is for Ubuntu – the Linux distribution on this particular computer.

Additionally, you can test your Apache2 installation by using the URL or IP address of your server host in your web browser. By default it will display the contents of the /var/www/html/index.html file and should display a screen similar to this.

You may want to pay attention to the center section of this display screen because it shows the location of your Apache2 configuration files:

When Apache2 is installed on other operating systems, the major difference is the specific directories used to store programs and data. Some of these things can be controlled by settings in the Apache2 configuration files. Some specific differences about Apache2 on the Macintosh are mentioned in the Technical Notes.

The Apache2 is a “service” on a Unix-like system. (In excruciating technical detail a “service” is described here.) This means Apache2 has file system ownership and privileges similar to a user account. The default configuration of the Apache2 file ownership user and group are both “www-data”.

To allow Apache2 to have full access to its root directory /var/www/html and all files and directories below, the “www-data” user and group must have “ownership” to these files and directories

This is accomplished using the “chown” command with the recursive option “-R”.

~$ sudo chown -R www-data:www-data /var/www/html/↵

As an option, adding wp-ops to the “www-data” group also gives wp-ops the same access to the Apache2 root directory files as Apache2 service. This provides the convenience of not having to use sudo to manipulate files in the Apache2 root file system. Add the wp-ops user to the group “www-data” with the “usermod” command.

~$ sudo usermod -aG www-data wp-ops↵

Again, after restarting your session, you can verify the groups a user belongs to with the “groups” command.

Last login: Thu Feb 20 18:01:04 2020
wp-ops@seebylooking:~$ groups↵
wp-ops sudo www-data
wp-ops@seebylooking:~$

Several tutorials and forum posts direct WordPress installers to make a change to a parameter in the /etc/apache2/apache2.conf file. This change is to correct a problem with WordPress permalinks. I’ve observed however that permalinks work OK without these changes – so I’ve omitted that step here.

If you find WordPress permalinks don’t work on your installation, you can find direction on modifying an Apache2 configuration file to resolve the problem here.

When Apache2 receives a URL of a domain only, or a domain including a directory, it’s default action is to display the directory listing of that directory. This presents a security risk.

For example, the default Apache2 action when a browser enters: “https://www.seebylooking.com/” is to display the contents of the Apache2 root directory. Similarly, the default action when a browser enters: “https://www.seebylooking.com/wp-contents” is to display the contents of the /wp-contents/ directory under the Apache root directory.

WordPress addresses this security risk by placing a file named “index.php” in every WordPress directory. With the exception of the Apache2 root directory, this index.php file simply prints a blank page. The index.php file in the Apache2 root directory contains the statements that start the WordPress web-site.

For this to function, there is an Apache2 configuration file that specifies what file to serve to the client browser when no file name is specified. This configuration file is called dir.conf and is stored here on a Debian Linux system:

/etc/apache2/mods-enabled/dir.conf

Its initial contents of dir.conf may be:

<IfModule mod_dir.c>
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml inde$
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

The “DirectoryIndex” line directs the order of files that Apache2 should look for when no file name is specified. The first filename is “index.html” and the forth file considered is “index.php”

Because WordPress always places a file called “index.php” in every directory, there is only a slight risk that this would present a problem. But to be sure, we can edit this file so that “index.php” is always the first file Apache2 will look for.

Using your system’s text editor (such as “nano” or “vi”) edit the dir.conf file so that “index.php” is the first file on the list.

An example of a change to accomplish that is:

<IfModule mod_dir.c>
        DirectoryIndex index.php index.cgi index.pl index.html index.xhtml inde$
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

If you change an Apache2 configuration file, it won’t take affect until Apache2 is restarted. This can be accomplished by rebooting your host, or using this command:

~$ sudo systemctl reload apache2↵

You should verify that Apache2 is back up and running by either using your web browser and using your host’s address as the URL, or with this command:

~$ systemctl status apache2↵

The result should be similar to:

To exit this display, press the letter “q”.

Go to: Part 4