Technical Note - Personal Apache Server

Summary

This describes how to setup an apache server running php on our systems. NOTE: This is mainly intended for students doing team projects that have a shared team directory set up for them. It will work from a home directory but be aware of log files and such filling up your allowed disk quota.

Details

We have created an example configuration here /vol/projects/example/httpd

Copy the /vol/projects/example/httpd directory to where you want it. Make sure the top level directory name is httpd.

The example contains the minimum required changes to apaches configuration file (httpd.conf) to get it working on our system with php working

This is based on the example apache config file in /usr/pkg/share/examples/httpd/httpd.conf and the directory structure below.

Example Apache Directory structure.

  • Http directory tree:
    http-dir.jpeg

info.php file is used to test php and contains 1 line <?php phpinfo(); ?>

NOTE: We have configured the httpd.conf to use environmental variables to making configuring it easier. These are

APACHE_DIR = Path to where you copied the httpd directory to
APACHE_GROUP = group to run under. Yours will normally be "students"
USER = user name to run under. This is normally set up by default when you login as your username

In the top level of httpd directory there is script httpd.sh that sets these variables and starts/stops the server. All you should need to do to get the server running is edit the script and change the APACHE_DIR variable to point to where your httpd directory is.

Stopping/Starting the apache server.

Run httpd.sh with start/stop parameters

Eg ./httpd.sh start # This assumes you are in the httpd directory

Note all httpd.sh really does is set the variables above and runs /usr/pkg/sbin/apachectl which does all the work.

Example httpd.conf file is configured as below.

Relevant config lines to look at start with # below

  • Server is configured to run on localhost port 8585
    This means in a browser you need to add the port to the host name in the http address.
    Eg http://localhost:8585/
    You may need to change the port if some other program is using the port

    # Listen 0.0.0.0:8585 # should be a port above 5000

  • Top level directory where you will serve your documents from

    # DocumentRoot "${APACHE_DIR}/httpd/htdoc"

  • Log files

    # ErrorLog "${APACHE_DIR}/httpd/log/error_log"
    # CustomLog "${APACHE_DIR}/httpd/log/access_log" common

  • Apache temporary server files

    # LockFile ${APACHE_DIR}/httpd/run/accept.lock
    # PidFile ${APACHE_DIR}/httpd/run/httpd.pid

  • CGI script directory. Where you put any scripts to run

    # ScriptAlias /cgi-bin/ "${APACHE_DIR}/httpd/cgi-bin/"

You also need to know about the php configuration file php.ini.

If you want to access a database like mysql or pgs from php you must add their modules to be loaded in the php.ini file.
Eg. for mysql the line extension=mysql.so must be added to php.ini

You can see what php extensions are available in
/usr/pkg/lib/php/20140828/