Local Development Environment

This document will help you get set up with a local development environment, including an Apache Web Server, PHP 8.1, and a PostgresSQL database. We will be using a Docker container to (hopefully) provide easy cross-platform setup; hey, it even worked on my M2 Macbook Air!

Download Docker Dev Environment

Installation Guide

The following steps will guide you to install Docker and our environment.

  1. If you do not already have Docker installed from another class, download and install Docker Desktop from the Docker website.
  2. Next, download our pre-configured Docker container setup.
  3. Unzip our Docker container setup to a local directory of your choosing. This will be where all your local classwork will reside this semester.
  4. Open Docker Desktop and choose “Dev Environments” and then select “Create”. Follow the promts, name your development environment, for Choose source select “Local directory” and then select the folder you just unzipped. After clicking Continue, Docker will download, install, and run our development environment.
  5. Open your browser to http://localhost:8080 to see the test page displaying the PHP configuration settings. This is the URL you’ll use to view your site locally for the semester.
  6. Test the database by browsing to http://localhost:8080/postgres.php. If you see “Success connecting to the database” then everything should be set up correctly.

Managing the Local Servers

The local development environment runs when Docker is open. You should see the environment we created under “Dev Environments” in the Docker Desktop application. There are 3 independent containers: a main container for the application, db containing the Postgres database, and web running Apache and PHP.

Hovering over the environment will provide options to open the files, stop (or start) the environment and its containers, or delete the environment. The development environment should stop automatically when you exit Docker Desktop.

Working Locally

Once the local development environment is installed, you may use the editor of your choice. We’d recommend VSCode, Atom, or vim as potential editors, although you should pick one that you’re comfortable with. (See Homework 0 to get started).

Load the directory that you unzipped (our development environment) as a project into the editor of your choice. You may also edit the files directly from Finder or Explorer. Use the following directories to publish your code locally:

  • web/www - this is the directory that Apache serves. Any file in here will be available through Apache at http://localhost:8080/filename. You can see two files by default, index.php and postgres.php.
  • web/src - this directory is available to Apache (and your PHP code), but it is not served by Apache directly. Files in this directory are not directly available on http://localhost:8080 but may be included by files in the www directory. This is a great place for files containing passwords, user data, etc.

Connecting to Apache

By default, our environment is set to host the web server on port 8080. To view your website locally, navigate your browser to http://localhost:8080/. Initially, you should see the PHP Information page displaying all the configuration. You can modify or delete this page by editing the web/www/index.php file.

Connecting to PostgresSQL

PostgresSQL is running in a separate container and is available on port 5432. View the web/www/postgres.php file to see an example connection under PHP. You should also be able to connect to your local Postgres server using external tools such as pgAdmin.