Our Development Environment
In this activity, we’ll familiarize ourselves with the course development environment and begin to experience new languages.
Before you begin
If you have not yet set up your development environment, please do so before proceeding. Information about getting started is on this site.
About Our Environment
The provided Docker environment contains two Docker containers: one includes the PostgresSQL database server (named db_2025
) and the other (named web_2025
) contains the Apache Web Server with PHP, Perl, and configuration for our cgi_bin
. Today, we will primarily consider the web container.
Apache Web Server
We will be using the Apache Web Server, which has a long history dating back to NCSA’s HTTPd server. Review the linked Wikipedia article for more information and history.
While the Docker container hides the bulk of the Apache configuration, it is important to understand how the server is configured and works. At a high level, Apache listens on specified ports—such as 80 for HTTP or 443 for HTTPS—and when HTTP requests are received, if it has the host and resource the user requested, then it will process the request and respond.
Apache provides the ability to define virtual hosts using the VirtualHost
directive, as seen below:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName www.example.com
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This virtual host will be match any incoming HTTP requests on port 80 (to any IP address or network card on the system) that are looking for host www.example.com
. The DocumentRoot
directive then defines where, in the filesystem, the files for this virtual host live. These are the files that Apache has access to provide in the HTTP response.
The DocumentRoot
directory is also separately defined in Apache’s configuration to define permissions on access, as seen below:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>
<Directory /var/www/html>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Typically the root directory of the filesystem (/
for Linux/Unix) will be defined and explicitly deny permission. Then, the directories for which Apache should have access—and serve to the user—are defined separately allowing access (i.e., Require all granted
above).
In the default configuration, Apache serves content from the /var/www/html
directory to any host that makes an HTTP request on port 80.
There’s more to learn about Apache configuration, but this is where we’ll stop for now.
Docker and Directories
Our Docker configuration maps Apache’s default port and directories to slight variations on our host machines.
In the unzipped development directory, you will see the following:
docker-compose.yml
- the configuration file which includes the port and directory mappings. Of important note is that port 80 is mapped to port 8080 on our laptops.web/www
- this is the directory that Apache serves, i.e., it is mapped to/var/www/html
as mentioned above. Any file in here will be available through Apache athttp://localhost:8080/filename
. You can see two files by default,index.php
andpostgres.php
.web/src
- this directory is available to Apache (and your PHP code), but it is not served by Apache directly. That is, it is outside the/var/www/html
, and therefore the configuration denies Apache access to serve it. Files in this directory are not directly available onhttp://localhost:8080
but they may be included by files in thewww
directory. This is a great place for files containing passwords, user data, etc. Inside the Docker container, the full path to files in this directory is mapped to/opt/src
.
Trace Execution
Begin by starting your Docker environment and containers, if you haven’t already. For PHP code, you will always need to access it using Apache (i.e., you will not likely be able to run it directly by double-clicking on the .php
file).
Next, browse to the following link: http://localhost:8080/example/?command=show&today=Monday
Answer the following questions on Gradescope in today’s Activity assignment:
- Which file does Apache first load through PHP?
- What file(s) are accessed/processed by PHP?
- PHP is similar to Python: it starts at the top of the first script. However, class definitions may be included and then objects instantiated.
- What file contains the HTML displayed in the output to the browser?
- Does a different
command
change the output? - Where is the JavaScript code that changes the text color?