Portable PHP Development

The CIS 505 class will be using a USB drive that includes all the PHP (short for PHP: Hypertext Preprocessor) development tools inside the DVD you were provided at the beginning of the semester. This wiki page will offer some guidance as to how to copy the DVD contents to a USB drive for the student's personal use.

Introduction
The XAMPP web server solution stack, Eclipse PDT for PHP development, and the Java Development Kit (JDK) have all been configured to work seamlessly off a USB drive. In this way, students taking the CIS 505 (Advanced Web Authoring) course can obtain a professional, comprehensive, and fully functional development environment in a completely portable package (that we hope is OS independent, too. So far, I know that it will work with XP, Vista, and Windows 7) that has been preconfigured to allow for minimal hassle in endeavoring to learn PHP programming.

Software Components
For an introduction into the basic functionality of Eclipse, please visit the Eclipse wiki. Some of the Eclipse features that have been preconfigured with the portable PHP development kit are:
 * Xdebug
 * Simpletest

To learn more about the XAMPP server stack, visit the XAMPP wiki. Features of XAMPP include:
 * Apache
 * MySQL
 * PHP interpreter

Learn to set a Windows PATH variable: PATH

Portable PHP Development: DVD version
The XAMPP/Eclipse/Java JDK/Devel package on a DVD represented the first undertaking in the quest to provide students a Portable PHP Distribution. It shall be referred to as Portable PHP Development Kit version 1 from now to all eternity. Issues quickly arose, namely: the JDK package provided on the DVD was entwined with running Eclipse PDT (and was unnecessary since most students have a copy installed to their systems); and secondly, that the entire setup was contingent upon running off a USB storage device assigned to the drive letter E:. To learn how we addressed these issues, read the following subsections:

Assigning a Drive Letter
'''Note: If there is a permanently connected device attached to your system that impedes on the availability of assigning drive letter E, then you need to first reassign its letter before proceeding with the USB drive letter assignment.
 * For Windows 7, read http://windows.microsoft.com/en-US/windows-vista/Change-add-or-remove-a-drive-letter for instructions on how to assign drive letter E to the USB drive in which you will be running the portable PHP development package.
 * For Windows XP, read http://support.microsoft.com/kb/307844.
 * For Vista, see http://windows.microsoft.com/en-US/windows-vista/Change-add-or-remove-a-drive-letter.

Remove USB Java/EclipsePDT Dependency
Most students already have the Java Development Kit installed on their hard drive, and might therefore wish not to run it off their USB device when working with Eclipse PDT. To remove the USB JDK, follow these steps:

-vm E:/java/bin/javaw>
 * 1)  Delete the Java folder off the USB drive.  You don't need it, as it's already installed on your computer.  A reason for keeping it on the USB would be if you were always on-the-go using multiple computers (some of which didn't have the JDK already installed, and you didn't want to keep installing the JDK on the systems)
 * 2)  Delete the "js.bat" file that's located at the USB drive root (E:)
 * 3)  Open the "Eclipse" folder, then edit "Eclipse.ini" in Notepad++
 * 4)  Erase the first 2 lines of code
 * Save Eclipse.ini. Reopen Eclipse.

Configuring XAMPP to operate on ANY drive
If you copied the XAMPP/Eclipse files from the DVD onto your USB device, then you're aware of the drive letter limitation. There is a workaround which basically enables the XAMPP package to operate utilizing a relative addressing scheme (so no matter the drive letter, XAMPP will be able to run properly). However, if you have downloaded the newest XAMPP.zip package off the student share network drive, then these configuration settings have already been implemented, and you do not have to bother with this process. Follow these instructions to enact relative addressing with your XAMPP distribution:
 * Browse to your XAMPP\install directory. Open install.php in Notepad++
 * On line 10, you should see the following line of code: $partwampp = substr(realpath(__FILE__), 0, strrpos(dirname(realpath(__FILE__)), '\\'));
 * Make a blank 11th line of code. Insert the following line onto the 11th line: $partwampp = substr($partwampp, 2);
 * Open the "httpd.conf" file in Notepad. Should be located at XAMPP\apache\conf
 * Scroll to line 243 (approximately). This is where the new E:/devel/web document root has been defined.  It should look like this:
 * Change E:/devel/web to simply /devel/web (this means that your document root will be located on whatever drive letter your USB storage device is assigned)
 * Change any aliases defined in the httpd.conf file you have that reference a drive letter to a relative location. Example: alias /web E:/devel/web changed to alias /web /devel/web
 * Run "setup_xampp.bat" at the Xampp root. Double clicking it should launch a command prompt.  Press 1 when you see the selection prompt, and then press enter.
 * Retry using running XAMPP off a new drive letter.
 * One last thing: open php.ini in notepad++, search for any admin comments, and make sure all Xdebug directives reference a relative pathway.

Portable PHP Development: Zipped Version
The second distribution, which fixed the above issues -- specifically the limitation on being only able to run XAMPP on drive E:, was provided in .zip format through the student share drive. There are two .zip files: Eclipse.zip and PortablePHP.zip. You may extract Eclipse.zip to any location, hard disk included, and be able to run it. It is a standard distribution of the Eclipse 2.2.0 PDT IDE, and is recommended that you create a shortcut to its executable on your desktop for faster retrieval and loading. PortablePHP.zip should be extracted to the root of a USB storage device (right at F:\, G:\, H:\, etc..). The extraction process will create a XAMPP folder and a Devel folder. Note: these are the folders that should reside at the root of your USB drive. The two folders are linked, in that XAMPP components, namely Apache, are setup to look for your document root off of whatever the drive XAMPP is running off. Stated another way, It is mandatory that in order for XAMPP processes to function correctly, you need to have XAMPP and the devel\web folders on the same drive (whether that be C:,D:,E:,F:, etc). Do NOT have XAMPP running on your flash drive while the devel\web folders reside on your hard drive, for example. Finally, take note that once you have Eclipse PDT running on your hard drive, be sure you specify the exact directory location of your workspace, IE, x:\Devel\web.

IIS
If you type "localhost" and you get a screen that says IIS you'll need to disable IIS.

To disable IIS go to the start menu.


 * Click control panel.
 * Find the icon for "Add or Remove Programs" and click it.
 * Then click "Add or Remove Windows Components" icon located to the left.
 * You will see check boxes next to windows components.
 * Find Internet Information Services (IIS) and un-check the box.
 * Windows might need a restart after this and its possible you'll need to reinstall XAMPP.

Port Dependencies
If you have Skype installed by default it is set up to use port 80 which is needed by the Apache server.

Disable Skype usage of port 80 and port 443:
 * Open the Skype window.
 * Click on Tools menu and select Options.
 * Click on Advanced tab.
 * Go to Connection sub-tab.
 * Un-tick the check box for Use port 80 and 443 as an alternatives for incoming connections option.
 * Click on Save button and then restart Skype to make the change effective.

Other programs can use ports needed by XAMPP if you dont get the XAMPP screen.

Go to XAMPP-control panel and click the port check button. It should tell you which ports are blocked or used and the offending program using the port. Disable or uninstall the program.

Eclipse PDT issues
Eclipse.zip extracts a preconfigured copy of Eclipse 2.2.0 PDT IDE. If XAMPP and your devel\web document root are not running off the E:\ drive, then some settings will have to be changed that are dependent on the drive location where XAMPP and devel\web reside. You won't be able to debug as a script or as a web page without first changing the PHP executable from the Eclipse preferences. See the following two categories on how to set the PHP executable to the correct path.

Debugging issues
Has an error window displayed that says a Problem Occurred after attempting to debug as a script? Details for this error state that "Exception occurred executing command line. Cannot run program "E:\xampp\php\php.exe" (in directory "F:\devel\web\cis505\H3"): CreateProcess error=3, The system cannot find the path specified." The reason for this error is that Eclipse is looking for the PHP executable on the E:\ drive, while you are currently running it on another. To solve this problem, see the following instructions:


 * While running Eclipse, select Window->Preferences->PHP->PHP Executables.
 * You should see the name PHP 5.3.5, with the Xdebug Debugger type, and the location E:\xampp\php\php.exe. Select this executable, and click the Edit button. Once in the Edit window, change the executable path to, for example, C:\xampp\php\php.exe (or wherever XAMPP is located).

If you don't see any PHP executables listed, then follow these steps:

PHP ini file text field is optional. However, you can browse to the php directory and select the php.ini file.
 * Click on PHP Executables. Next, click the "add.." button to add a new PHP executable definition.
 * Enter PHP 5.3.5 for the Name text field.
 * Browse to the executable path and select the PHP interpreter from the php directory. If you have XAMPP installed on C:, then the path is probably c:\xampp\php\php.exe. IMPORTANT NOTE: I strongly recommend that you use the "Details" view in Windows Explorer and you always show the extension of the file. This way you'll know if the php file name corresponds to php.ini or php.exe.
 * From the PHP debugger drop down list, select XDebug.
 * Restart Eclipse. If you don't exit Eclipse, changes will not take effect until you do.

Running your script as a web page
If you are getting an "Object not found" 404 error within your web browser, this is indicative of a document root and/or alias that has not been configured correctly. See the course wiki Apache for a discussion of how to set these settings. Also, be sure that XAMPP-control has been launched, and that you have started Apache.

Setup a CIS505 folder
Create a new project within your workspace: Second step involves adding a new alias to the httpd.conf file (located at xampp\apache\conf\httpd.conf). Now we must map to a path to this folder for the server:
 * In Eclipse, click File -> New -> PHP Project.
 * The "New PHP Project" window displays.
 * In the "Project Name" field enter cis505 and click Finish.
 * Edit the file in Notepad++
 * Scroll down to the alias module and find where there have already been aliases defined (approx line 338)
 * Type Alias /cis505 /devel/web/cis505 to define a new alias for /cis505.
 * While in Eclipse, select off the menubar Window -> Preferences
 * From the tree menu, expand PHP, then select PHP Servers.
 * Click the "Default PHP Web Server" and click the edit button.
 * Select the Path Mapping tab, and then click the Add button.
 * For the Path on Server, type \devel\web (This is provided you are running Eclipse off the same USB drive as your workspace/document root folder. If you have Eclipse running on your hard drive and your USB storage device is where your workspace folder is located, then you need to specify the absolute location of your workspace, so be sure to include the correct drive letter.)
 * For the Path on Workspace, type /cis505.