Saturday, January 27, 2007

Setting Up a Local Server

I've always found it to be helpful to have a local server, duplicating the production server as close as possible, while developing. This saves you from having to upload changes every two seconds.

I've set up phpMyAdmin/PHP/MySQL/Apache on Windows a few times. And I'm just now getting to the point where I don't get stuck somewhere along the line.

I know what you're thinking — not another tutorial on installing PHP/MySQL/Apache. But I bet none of the ones out there were geared towards setting up a server for the Zend Framework.
  1. Apache
    I'm using version 2.0.58. Make sure to test that this works alone before moving on.
  2. MySQL
    I'm using version 5.0.21.
  3. PHP
    I'm using version 5.2.0. Use the zip package, not the installation program. The installer doesn't include certain extensions. Unzip it to C:\php\. You could choose another directory, but I have avoided the Program Files directory since spaces in paths have been known to cause problems with some programs.

    Add PHP to your Apache config file. In Apache 2 using PHP as a module, it's as follows, assuming you unzipped PHP into C:\php\.
    LoadModule php5_module "C:/php/php5apache2.dll"

    If you're using the Apache module for PHP, you can set the following in the Apache config file to specify the directory where the php.ini file is. This is better than having to place it in the Windows directory.
    PHPIniDir "C:/php"

    Using the framework, you also want to load the rewrite module so that all requests can be sent to a bootstrap file. So make sure to uncomment or include this.
    LoadModule rewrite_module modules/mod_rewrite.so

    Tell Apache to look for index.php, and not just index.html, when directories are requested. The index.html.var is only needed here if you're using content-negotiated documents. If you don't know what they are, you're probably not using them.
    DirectoryIndex index.html index.php index.html.var

    Set the MIME type for php files.
    AddType application/x-httpd-php .php

    Edit the php.ini file and make sure the extension directory is set to where your PHP extensions are located, usually C:\php\ext\.
    extension_dir = ".\ext"

    Uncomment the MySQL extension.
    extension=php_mysql.dll

    Also uncomment the multibyte string extension if you plan on using exotic character sets in your database. phpMyAdmin will cry if you don't enable this.
    extension=php_mbstring.dll

    For the Zend Framework, uncomment or add the following lines if not present. This enables the PHP Data Objects extension which Zend uses for accessing the database — in this case, MySQL.
    extension=php_pdo.dll
    extension=php_pdo_mysql.dll


    While you're editing php.ini, turn off register_globals and magic_quotes. Turning off register globals is for safety, and turning off magic quotes reduces complication later when inserting data into the database. I have seen a ZF tutorial that states that turning off magic_quotes is required, but I haven't tested this.
    register_globals = Off
    magic_quotes_gpc = Off


    Remember to restart Apache to make configuration changes take effect. If you're using PHP as an Apache module, php.ini is only loaded once on startup. So changes to php.ini will not take effect until Apache restarts.
  4. phpMyAdmin
    I'm using version 2.8.0.3. phpMyAdmin won't work out of the box. There's a documentation.html file that explains (under the Quick Install section) creating a config file.

...More details on all this later. (I know what you're thinking... yeah, right.)

No comments: