Development

From NeoWiki

I will attempt to outline all of the steps required to set up a local development environment for use with the Neoturbine Seti project. This page should serve as a reference for all developers involved, current and prospective. Please contact me (Stiv2k) if any information presented here is unclear, vague, or otherwise inaccurate.

Contents

[edit] Subversion (SVN)

We allow anonymous checkout on our server, however you must have an authenticated username and password to commit changes; ask in the IRC channel for access.

[edit] Client software

There are many Subversion clients available depending on your operating system. Here are the most popular ones:

[edit] WebDAV

WebDAV allows us to use SVN over HTTP. Using your favorite Subversion client (or even your web browser), you can access our Seti project repository online at http://websvn.neoturbine.net/dav/seti. The "stable", production copy of the code resides at http://websvn.neoturbine.net/dav/seti/trunk and the development branch is at http://websvn.neoturbine.net/dav/seti/branches/devel. I recommend that you only check out the devel branch and nothing else. This will allow the more experienced developers take care of merging, trunking, and dealing with the CakePHP core libraries.

An example for checking out using the command line client looks like this:

svn checkout http://websvn.neoturbine.net/dav/seti/branches/devel

[edit] Documentation

The Subversion Book: http://svnbook.red-bean.com

[edit] HTTP Server

In order to view your development copy locally, you must set up an HTTP server. In order for it to work properly, you must have PHP parsing available and the PHP MySQL extensions enabled. You must also have Apache's DocumentRoot pointing at the top-most directory of your local copy (/). The next few steps in this section will explain how to do just that.

[edit] Can I use LigHTTPd?

Unfortunately I have not had success in using this HTTP server, due to its lack of support for mod_rewrite functions, which are of paramount importance in CakePHP. It has been rumored on other websites however, that it is still in fact possible: http://bakery.cakephp.org/articles/view/lighttpd-and-cakephp-setup-in-subdirectories

[edit] Setting up Apache

First, download the newest version of Apache HTTP server from http://httpd.apache.org/

I recommend the MSI installer without SSL (though the package which includes SSL will work too, but has a larger file size).

When the installer runs, hit next until you see a window which resembles the following figure:

Figure 1: Keep clicking "Next" until you reach this screen.
Figure 1: Keep clicking "Next" until you reach this screen.

The values you enter for Network Domain, Server Name, and Administrator's Email address do not really matter, as your HTTP server is going to be local only, you can fill them in with any values you want. What is most important though, is that you choose to install Apache only for the current user, so that it is not always running in the background even when you don't want it to (LAPTOP USERS MAKE SURE YOU READ THIS!)

After this screen you should select a typical install and let the installer do the rest of the work. From here on out your Apache server should be installed properly and all that is left to do is some tweaking of httpd.conf

[edit] httpd.conf

First we need to enable mod_rewrite as it is an essential part of CakePHP. To do so, find this line and uncomment it (remove the hash at the front)

#LoadModule rewrite_module modules/mod_rewrite.so

It should look like this:

LoadModule rewrite_module modules/mod_rewrite.so

Next, the DocumentRoot directive needs to be pointing to where the root of your SVN repository is (right above /app).

DocumentRoot "C:/Documents and Settings/Steve/Desktop/devel/seti"

The <Directory> directive needs to have the same path as DocumentRoot. Also remember to change AllowOverride from None to All.

# This should be changed to whatever you set DocumentRoot to.
<Directory "C:/Documents and Settings/Steve/Desktop/devel/seti">
    # Leave this as default.
    Options Indexes FollowSymLinks

    # CakePHP needs .htaccess to work, so we need to allow overrides.
    AllowOverride All

    # Leave this as default as well.
    Order allow,deny
    Allow from all
</Directory>

Now we need to tell Apache to treat index.php files as directory indeces. We do this by appending index.php to the DirectoryIndex line:

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

Next, look for a directive called <IfModule mime_module>, we will need to add a couple of lines inside of it:

<IfModule mime_module>
    # Leave this alone
    TypesConfig conf/mime.types

    # Leave these alone too
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz

    # These are the two lines you need to add
    AddType application/x-httpd-php .php .phtml
    AddType application/x-httpd-php-source .phps
</IfModule>

And that is ALMOST everything for Apache's httpd.conf. Keep this file open as we will have to return to it to make one last edit to finalize the PHP parsing support.

[edit] Setting up PHP: Hypertext Preprocessor

There are essentially two ways to install PHP on your machine: using a standalone version or MSI installer. For all practical purposes the MSI installer should be easier to use since it requires no configuration.

[edit] Standalone version

Download the Win32 standalone archive of PHP from http://www.php.net/downloads.php

Extract the archive anywhere. This will be where your PHP installation will reside. Some people choose C:\php but ideally you can put this anywhere.

Navigate to your PHP folder in windows explorer. You should see a php.ini-recommended file. Rename this to php.ini. Now open it, because we have to make a couple of edits.

First, we need to tell PHP where to look for extensions. Find this line:

extension_dir = "./"

Change it to the absolute path of the extensions dir in your standalone PHP installation, on my system it looks like this:

extension_dir = "C:\Documents and Settings\Steve\Desktop\devel\php-5.2.8-Win32\ext\"

Next we need to enable the MySQL extension. Scroll down and find this line:

;extension=php_mysql.dll

Uncomment it (remove the semicolon) so it looks like this:

extension=php_mysql.dll

[edit] MSI installer

Work in progress

[edit] Back to Apache!

Okay, now that we have PHP setup, there is one last thing we have to do. Remember when I said to leave your httpd.conf open because we needed to go back? Now is the time.

Anywhere in your httpd.conf, preferrably at the very bottom, you need to add two lines to tell Apache to load the PHP5 module and tell it where your php.ini is:

LoadModule php5_module "C:/Documents and Settings/Steve/Desktop/devel/php-5.2.8-Win32/php5apache2_2.dll"
PHPIniDir "C:/Documents and Settings/Steve/Desktop/devel/php-5.2.8-Win32/"

Notice these paths should reflect your PHP installation and could vary from system to system depending on where you chose to install PHP.

[edit] MySQL Database

If you get Apache working, good, you're almost there, but your mirror still isn't functional without a database.

[edit] Setting up a MySQLd

You shouldn't have to do this, but you can if you really want to. Since I do not do it and have no reason to, I will not cover this here.

[edit] Tunneling MySQL over SSH

This option is the easiest way to get a database up and running for your local copy of the website. The only catch is that it requires you to have a shell account on either one of two servers, as there exists a dummy database called seti-devel on both galatea.neoturbine.net and rickb.net.

[edit] Creating an SSH tunnel with PuTTy

Download PuTTy from here http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe

Open the program and create a new session as shown in the figure:

Figure 1: Here I created a session called "neoturbine.net" and clicked "save".
Figure 1: Here I created a session called "neoturbine.net" and clicked "save".

Next we want to create tunnels for this new session, so highlight your newly created session and click "load" to load it into PuTTy.

Click on "Tunnels" on the left under SSH. Here we are going to forward the remote port 3306 to your local machine (3306 is the standard port used by the MySQL protocol).

Figure 2: Click "Add" after typing in the data
Figure 2: Click "Add" after typing in the data

Your screen should look like this when finished... also remember to check local ports accept connections from other hosts though I am not entirely sure if this is neccessaary.

Figure 3: Done creating the SSH tunnel.
Figure 3: Done creating the SSH tunnel.

All that is left to do is save these changes to your session so that the tunnel gets created every time you open it. To do this simply go back to the Sessions category on the left of the PuTTy screen, highlight your session and click "save". Your SSH session is now tunnel ready and you can test it out by logging in via SSH and probing 127.0.0.1:3306 via telnet or any other network utility.

[edit] CakePHP configuration

If you have properly set up your local Apache and MySQL servers, assuming you are a competent web developer, you should be nearly ready to begin. The only thing that is left is a little configuration on CakePHP's behalf. First, we need to create local copies of config/core.php and config/database.php:

cd repo/app/config

[edit] Configuring core.php

Make a copy of core.php.default and name it core.php, then open the file and locate this line:

Configure::write('debug', 0);

Change it to this:

Configure::write('debug', 2);

[edit] Configuring database.php

Make a copy of database.php.default and name it database.php, then open the file and look for the var $default variable:

var $default = array('driver' => 'mysql',
			'connect' => 'mysql_connect',
			'host' => 'localhost',
			'login' => 'user',
			'password' => 'password',
			'database' => 'project_name',
			'prefix' => '');

Configure the information for the database you are using. This may vary depending on your setup.

[edit] Troubleshooting

[edit] Windows

You should be able to get parts of the website running under a Windows host operating system, however there are known issues of the OpenID logins not working among other various things. We are aware of this and are working to address these issues.