Tuesday, December 14, 2010

XAMPP, NetBeans and Symfony Install

Today I'm going to detail how I set up my development environment and even run down to the beginnings of my MMO.

Keep in mind that this is written with Windows in mind. However, there are certain things, such a Symfony's directories in PHP, which require slashes in a certain direction. Please make sure you follow the direction of slashes on windows, on Mac and Linux, they will always be /.

To start off with, I always try to line up all my downloads first, so that I'm not missing anything. Here is my current list of software

So now that we have our initial setup downloaded lets get started. Feel free to install everything all at once, just be sure to remember where each program installs to.

Web Server Setup

Here we are going to start with the install of XAMPP. It is very straight forward. In fact the directions for setting it up are provided on the XAMPP download page below the list of links. The windows version is found here. Make note of where you installed XAMPP, the default is c:\xampp. For the remainder of this document I will call it [XAMPPInstallDir].

Once you have XAMPP setup, there are a few things I do to mirror my host's setup. XAMPP starts you with a directory called htdocs. My server uses a directory called public_html. To facilitate this difference you need to make the following changes:


  1. go to [XAMPPInstallDir]\apache\conf and open up httpd.conf.
  2. Find the line: DocumentRoot "[XAMPPInstallDir]\htdocs" and I update this to DocumentRoot "[XAMPPInstallDir]\public_html"
  3. Next find the line <Directory "[XAMPPInstallDir]\htdocs"> and update it to <Directory "[XAMPPInstallDir]\public_html">
  4. Go to the [XAMPPInstallDir] and rename the folder htdocs to public_html

Now make sure you restart apache as these changes won't be picked up until you do. For XAMPP open the control panel from the start bar and hit stop, wait for the running to disappear and then hit start and wait for running to reappear. While you are here, make sure MySQL is also running.

Again, this is specific to my host provider. Your mileage may vary.

System Environment Variables

Because we installed XAMPP, now we need to add the path to PHP. That means we need to modify our path variable. Be careful because you want to keep the current path and just add to it the location of PHP. To do this:

You will want to modify the System Variable called Path and add to the end of it ;[XAMPPInstallDir]\php

NetBeans and Java

Next up is Java. Java's default install directory is C:\Program Files\Java\jdk1.6.0_21. Be sure to install both the JDK and the JRE. I follow the typical install with nothing special.

Now for NetBeans. I use the All bundle because we will be working with both PHP and Java projects. NetBeans generally installs to C:\Program Files\Netbeans 6.9.1. I follow the typical install with nothing special.

Symfony and our PHP Project

So now we have NetBeans, Java, and our server. Next on the list is Symfony and our game's web application.

Symfony isn't your typical "install". Instead it is an add on to our PHP web application. So to start things off:

  1. Create a new NetBeans PHP Project. Hit Next. 
  2. My game is titled AegisBorn. (Image differs because my project is already created.)
  3. Make sure your source folder points to a new folder under [XAMPPInstallDir]. This is important for later. Hit Next.
  4. Here you can change what web page loads when you run this project. I leave this the default. Hit Next.
  5. Do not add any frameworks. This uses NetBeans' built-in version of Symfony or Zend. We won't be using these. Hit Finish.
PHP Application
Project Setup



This now has us set up for our new project. Now open up an explorer to [XAMPPInstallDir]\[GameName] and you should see the single folder nbproject. Create a new folder called lib and under that create another folder called vendor.

Go into the vendor folder and you should have a path that looks like \lib\vendor. This is where you want to extract the Symfony zip file. After you have extracted the folder structure, make sure you rename your symfony-1.4.8 folder to symfony.

Next open a run window Start -> Run or WINDOWKEY-R for those so inclined and type cmd. (terminal for everyone else)

cd [XAMPPInstallDir]\[GameName] and type the following commands:

  1. php lib/vendor/symfony/data/bin/symfony generate:project [GameName]
  2. copy lib\vendor\symfony\data\bin\symfony.bat .  **Don't forget the '.' at the end, it is important.
  3. symfony generate:app frontend
This will create the project files you will need for your Web Application. If you look in your explorer you will now see a bunch of new folders, things like apps, cache, logs, and the important one - web. Up above we renamed our folder to public_html. The easiest way to work with this is to do the following in the command window:
  1. cd [XAMPPInstallDir]\public_html
  2. mkdir [GameName]
  3. cd [XAMPPInstallDir]\[GameName]
  4. mkdir public_html
  5. cd public_html
  6. MKLINK /J [GameName] [XAMPPInstallDir]/public_html/[GameName]
This will make a directory in your application that points to the visible part of your web server. Otherwise you end up having to copy everything manually any time you make a change.

Next we want to go ahead and copy the contents of the 'web' folder into the 'public_html\' folder. Then go ahead and delete the web folder.

Go ahead and close the command window now.

In the explorer you want to go to [XAMPPInstallDir]\[GameName]\lib\vendor\symfony\data\web and copy the sf directory into [XAMPPInstallDir]\[GameName]\public_html\

Open up NetBeans and go to your project. You should see all of your folders and everything listed in your project. Now, open up config\ProjectConfiguration.class.php and update the require_once line
  1. require_once dirname(__FILE__).'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php'; **Note the / instead of \
in the public function setup() add:
  1. $this->setWebDir($this->getRootDir().'/public_html/');
in public_html\ open up index.php and frontend_dev.php and update the require_once line to:
  1. require_once(dirname(__FILE__).'/../../[GameName]/config/ProjectConfiguration.class.php');
Now, go into a browser and open up http:\\localhost\[GameName]and you should see something about Symfony being set up correctly.

Great! You can now follow the JoBeet tutorial from Symfony located here and you can skip day 1.






13 comments:

Anonymous said...

php lib/vendor/symfony/data/bin/symfony generate:project

gave an error "not enough arguments". I had to place my game name after :project to get it going... Is this correct? do you need to update the tut?

Thanks for these. Can't wait to get going with this!

Anonymous said...

One last comment. This line-

require_once dirname(__FILE__).'/../lib/vendor/symfony-1.4.8/lib/autoload/sfCoreAutoload.class.php';

Tried to change it to "symfony-1.4.8", but you earlier in the tutorial tell us to change our symfony directory to just "symfony"... A typo?

Anonymous said...

one last last last comment. When i went to localhost/[GameName], I got the "symfony installed" message, but there was no style and the images were broken. Turns out the images and styles were located in \lib\vendor\symfony\data\web, so I copied them.. Am I going to run into issues later because of this? Or is it just cosmetic?

Unknown said...

It is fine if you copied the files. It won't hurt anything. The reason I didn't say to copy them is because we change the routing in another tutorial and those pages are no longer visible.

Unknown said...

Yes, the symfony-1.4.8 is a typo. It is updated now.

Unknown said...

The "not enough arguments" is because I missed changing <GameName> to [GameName] and Blogger thought it was a tag and so it removed it. Updated.

Anonymous said...

When i open localhost/[GameName]


i get an fatal error that it cant find the file ProjectConfiguration.clas.php

Unknown said...

When you get a fatal error on missing the project configuration file that means you need to check where you put the web code vs the symfony code.

my structure looks like this:

xampp
+--AegisBorn
| +--config
| +--ProjectConfiguration.class.php
+--public_html
+--AegisBorn
+--index.php

if your symfony code isn't in the xampp directory, you will need to put it there or modify the index.php so that the path from the index.php file to the symfony code is correct.

Anonymous said...

The File is there.. my structure is the same as yours, did you perhapse change the include path in php.ini

Unknown said...

I manually modified the index.php. My path in that file says /../../AegisBorn/config/ProjectConfiguration.class.php

if you don't have it in the folder AegisBorn, you will need to modify that path to point to your specific game name. Thats the only reason I can think of for why it cannot find that file.

Anonymous said...

Yea thats what ive done ^^

The Error -

C:\xampp\public_html/../../TheMMO/config/ProjectConfiguration.class.php


and my file is on c:\xampp\public_html\TheMMO\config\

Unknown said...

There's the problem. your TheMMO directory should be in the xampp directory. if you are following my tutorials. Then you take the htdocs directory inside TheMMO directory and copy the contents to public_html/TheMMO

Anonymous said...

Ehm im not sure i follow you.. is there anyway i could talk to you on msn or skype or something like that?