Department of
Computer & Electrical Engineering & Computer Science
California State University, Bakersfield

Local Test Environment for Web Development

Introduction

For courses in web, app, and database development, you may want to install software on your personal computer to create a local testing environment. The department uses the Apache-MySQL-PHP (AMP) stack. The name may include a prefix based on the operating system (e.g., MAMP for Windows). This guide provides basic instructions for installing an AMP stack on your computer, organized by operating system.

Test vs. Production

Often in software development, you will prototype your code on a test environment. Then, when you are confident in your code, you will submit the code to a production environment. In early web development classes, it is possible to use only a browser to test your work on plain HTML files. However, if you require PHP and MySQL, you will need to install additional web development tools match the software on the department server, to simulate an identical environment to properly test it.

Windows Operating System (WAMP)

Windows-Apache-MySQL-PHP (WAMP) is available from wampserver.com. Download and install it as an Administrator. The default install path is C:\wamp64, and web files are served from C:\wamp64\www. You may also need to install the Microsoft Visual C++ Redistributables listed on the download page. Test the setup by placing this PHP script in C:\wamp64\www:

<?php
phpinfo();
?>

Open a browser and go to http://localhost. If configured correctly, you should see a test page. If port 80 is in use (for example, by Skype), change the WAMP port to something else. Then access it using http://localhost:PORT (e.g., http://localhost:27015).

Security Hardening for Windows

By default, Apache listens on all network interfaces. For local testing only, restrict it to localhost. Open C:\wamp64\bin\apache\apache*\conf\httpd.conf in a text editor. Update these lines:

Listen 80
Listen 443

To this:

Listen 127.0.0.1:80
Listen 127.0.0.1:443

There may not be a line for Listen 443, if so ignore it. Now, find the start of a snippet beginning with <Directory "c:/wamp64/www/"> and replace Require all granted with Require local. Your final configuration file should look like this:

Listen 127.0.0.1:80
Listen 127.0.0.1:443
...
<Directory "c:/wamp64/www/">
Options Indexes FollowSymLinks
AllowOverride all
Require local
</Directory>

These changes restrict access to your local machine only.

Macintosh Operating System (MAMP)

Macintosh-Apache-MySQL-PHP (MAMP) is available from www.mamp.info. Open the .pkg file and follow the prompts. The default installation location is Applications/MAMP. Start the server by opening MAMP and clicking Start Servers.

Test the setup by navigating to /Applications/MAMP/htdocs and creating a folder mysite. Files will be served out of /Applications/MAMP/htdocs/mysite/. Place this PHP script in the folder:

<?php
phpinfo();
?>

Open a browser and go to http://localhost:8888/mysite. If configured correctly, you should see a test page.

Security Hardening for Macintosh

As with the Windows installation, Apache listens on all network interfaces. The scripting language used by Apache does not change from Windows to Mactintosh. However, the configuration file by default is located in /Applications/MAMP/conf/apache/httpd.conf on a Macintosh. Also, MAMP uses port 8888. Follow the directions in the Security Hardening for Windows section, except that you must update this line:

Listen 8888

To this:

Listen 127.0.0.1:8888

MAMP by default will not listen on ports 80 or 443.

Linux Operating System (LAMP)

This guide assumes you are using a Debian or Ubuntu-based system. Open a terminal and execute:

sudo apt update
sudo apt install apache2 php libapache2-mod-php mariadb-server

Start and enable the services:

sudo systemctl enable apache2
sudo systemctl start apache2

If everything installed correctly a default page will appear when you navigate a browser to http://localhost. The default web root is:

/var/www/html

Using a text editor create an index.php in the web root:

<?php
echo "LAMP is working";
?>

Security Hardening for Linux

This follow the same principles as the Security Hardening for Windows section. Except, the default site config is located at /etc/apache2/sites-available/000-default.conf, and you must execute the following command to restart the Apache server after modifying the configuration file:

sudo systemctl restart apache2