Apache, PHP, and MySQL

General Information

This guide will teach you how to set up a basic web server with Apache, PHP support, and MySQL for the database.

There are a couple of ways to do this, but this guide will use the easier method with the ports system.


  1. In order for public access to your website, you must have a valid domain name.
  2. A text editor (for this guide we will use Nano)


Section A — Apache

# cd /usr/ports/www/apache13
# make install clean

Apache now gets started on system boot from rc.conf so let’s add the respective entry:

# echo 'apache_enable="YES"' >> /etc/rc.conf

Note: For Apache2 users: Use the following instead.
# cd /usr/ports/www/apache2
# make install distclean
# echo 'apache2_enable="YES"' >> /etc/rc.conf

Section B — PHP

# cd /usr/ports/lang/php4
# make config

You will be prompted to add module support. At this time select the Apache support.

# make install distclean
# cd /usr/ports/lang/php4-extensions
# make install distclean

Select which options you would like compiled into PHP and select OK.

Section C — MySQL

# cd /usr/ports/databases/mysql41-server
# make install clean
# echo 'mysql_enable="YES"' >> /etc/rc.conf


Now we need to make sure Apache is configured for your website and that the PHP module is configured in the Apache config file.

# cd /usr/local/etc/apache
# nano httpd.conf

Make sure you see the following lines uncommented:

LoadModule php4_module     libexec/apache/libphp4.so

AddModule mod_php4.c

     DirectoryIndex index.php index.html index.htm

Add the following lines for virtual hosts:

ServerType standalone
ServerName domain.tld


     ServerName domain.tld
     ServerAlias www.domain.tld
     ServerAdmin admin@domain.tld
     DocumentRoot /path/to/website/files

Start the servers:

# /usr/local/etc/rc.d/mysql-server.sh start
# /usr/local/sbin/apachectl start

Enjoy your webserver!

Speak Your Mind