Setting up the web part


Please note that this information is no longer up to date. The content of this site has moved to a new domain which is kept up to date. Apologies for the inconvienince.

How to install and configure a web-server that can handle dynamic web pages (based on PHP) and use a database (MySQL).

Note: I’m updating the setup of the MAMP part. I’m not using pre-compiled packages anymore and I’ve switched to provide compile instructions so you can build your own. Have a look at the new documentation here: ISP in a box 2.0.

As you might have read in my post on the 7th sept 2005 about getting a web-server running on my test Mac mini I’ve searched around for a decent package from which I can simply install the software without any compilation. During my search and evaluation I decided on the packages from Server Logistics. This is a web hosting company that is completely Mac based. So I thought that they should know how to setup a proper web-server environment and that I can stand on their shoulders when I use the packages they provide.

The setup is quite easy, download the packages and follow the installation procedure that accompanies it.

MySQL installation

Start with the MySQL package, download the latest version. There is a mentioning that it isn’t supported by 10.4 Tiger but I’ve got it running without any issue. Mount the downloaded image and run the installer. Just click through the installer with all the default settings but make sure you install it in the correct drive. A thing to note is that the installation will create a new system user under which MySQL will run, namely ‘mysql’. You can verify this with the ‘Netinfo Manager’ utility located in the ‘Applications/utilities’ folder. Please use the installation guide that is included in the package, the following info is just an extra.

Copy the preference pane that comes with the installation in ‘/System/Library/Preference Panes’ so that every users has access. If you don’t want this and just want yourself to be able to access this Preference to control the MySQL server copy it into ‘/Users/YourName/Library/PreferencePanes’.

As you are installing and not upgrading you need to initialise the MySQL server. To do this you need to select MySQL from System Preferences application and click on the initialise button. But only do this after installation and NOT after an upgrade. A terminal window will appear in which you will have to type your users password to give the initialisation program access to your configuration files.

When this is done you need to set the root password for your database administrator. You need to do this or your database server will be wide open for anyone to access and vandalise it. To do this click the ‘Start’ button in the MySQL System Preference window. When the status changes into running click on the ‘Set Root Password’ button in the same window.

If you want to use MySQL from the Terminal window you’ll haveto add the path to the executables to your PATH environment variable. Use an editor to edit the .profile file in your home directory and add the following line:

export PATH="$PATH:/Library/MySQL/bin"

In the next Terminal session you will be able to use MySQL from the commandline.

Now you’ve got a full database server running on your Mac mini and can start creating your own databases.

Apache2 installation

The follow with the Apache2 package, download and install it. I know that OS X comes with apache but that is a 1.x version and I want the advantage of using a 2.x version.

Please read the blog entry documenting the upgrade to 2.0.55 to solve some nasty bugs and security issues.

PHP installation

The last thing to do is to get the PHP package, download it and install it. I know it is still a 4.x version and not yet the latest 5.x version but there aren’t many PHP applications that really require it. This package includes Turck MMCache, a free open source PHP accelerator and optimiser. Turck MMCache typically reduces server load and can increase the speed of your PHP code by up to 10 times. This extension is disabled by default so if you want to use it change the configuration accordingly, edit the php.ini file located in /Library/PHP4/lib after installing. If you want to know what modules are included check this page.

Testing this installation can be done by copying the file test.php from the PHP4 installation into the htdocs directory of the Apache2 installation (/Library/Apache2/htdocs) and then point your browser to http://yourmacmininame/test.php or if you are working on the mini http://localhost/test.php. You should get a page that looks like:

(insert page picture here)

Configuration changes

The are some things to be changed to keep everything in line and prevent other components from this installation not functioning.

You need to change some items in the configuration file of the Apache web-server. Please edit the file httpd.conf in the directory /Library/Apache2/conf/. Find the following line:

DirectoryIndex index.html index.html.var

and change it into:

DirectoryIndex index.php index.html index.html.var

This will allow your php index pages to appear without any problems. Next change the following lines:

User nobody
Group #-1

and change them into:

User www
Group www

The last change is to allow the use of .htaccess files on your web-server. First find the lines:

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit

Edit the line below from:

AllowOverride None

and change it into:

AllowOverride All

This will run Apache as a proper user on your system, the www user hasn’t got many rights but enough to run a web-server. This makes the system more secure.

Next page ->, building a mail server.

2 Responses to “Setting up the web part”

  1. Ricky Says:

    How do you create databases? IS it like windows?

    >CREATE Database phpbb
    >Grant all on phpbb.* phpbb@localhost

    IS that right?

  2. Landon Says:

    Yeah it is the same. It doesn’t matter what operating system you are using, once you are logged into the MySQL terminal all the commands are exactly the same as you are now communicating with the MySQL server software and not the OS.