|
|
|
|
Remote Debugging With PHPEd 5, RedHat Linux, and SSH Via PuTTY
I started using PHP back when it was called PHP/FI. Before that, I made
simple desktop applications using Visual Basic and REALbasic. So, I was
used to having a step-by-step debugger available to diagnose problems in
my code. At the time, I was unable to find any IDE for PHP which offered the
same functionality.
Enter PHPEd. The PHPEd IDE offers a remote debugger for your PHP projects.
The remote debugger is installed on your web server as a PHP module, and sends
the debugging information back to your development computer where PHPEd is running.
Because of this, you can debug your code in the environment where it
will be living, with the same database, permissions, and http server.
The setup for remote debugging is not difficult, but I think this step-by-step
article will help anyone who is using the same setup as I am. Just to be clear, that setup is:
- PHPEd 5.0
- Rackspace Hosted: RedHat Enterprise Linux 4 ES
- PHP 5.2.3
- PuTTY 0.60
Setting Up Remote Debugging
-
Install PHPEd. If you do not already have PHPEd,
you can download a trial at
http://www.nusphere.com.
Choose Complete Installation to ensure
that you have all features.
-
Download PuTTY if you do not already have it. PuTTY is a
free SSH/Telnet client which can be found at
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html.
-
You'll also need an FTP client to move the PHPEd debugger (named DBG) to your
web server. I recommend the free FileZilla, available at
http://filezilla.sourceforge.net.
-
You will need to find the appropriate debugger module, installed along with PHPEd,
and move it to your web server. Here's how:
-
Open the PHPEd program directory \ debugger \ server \ Linux:
C:\Program Files\nusphere\phped\debugger\server\Linux
-
Look for the file named: dbg-3.1.12-Linux.tar.gz
-
Transfer dbg-3.1.12-Linux.tar.gz to your web server using an FTP
client, like FileZilla. It doesn't matter where you put the file on
your web server, because we will later extract the file, and move its contents
elsewhere. So, you can simply FTP the file into your home folder on the web server,
if you like. For this example, we will FTP the file to myfakeserver.com into
directory: /home/nate
-
Use PuTTY to establish an SSH connection to your web server.
-
For this example, I will login to my web server as nate.
-
For some of the following steps, you may need to be
the root user. So, change to the root user.
su
-
Extract the files from the dbg-3.1.12-Linux.tar.gz archive.
In this case, the tar command does the follwing:
- -v Use verbose output. (Show me what you're doing!)
- -z Use GZip to uncompress the archive.
- -x Extract the archive.
- -f Extract this file.
tar -vzxf dbg-3.1.12-Linux.tar.gz
-
After the files are done being extracted, the dbg-3.1.12-Linux
folder will appear. Inside this folder are all of the DBG (debugger) modules
for Linux. We only need one of them, specifically the one titled
dbg.so-5.2.x located in dbg-3.1.12-Linux/x86/.
You should move this module to your PHP modules folder.
mv /home/nate/dbg-3.1.12-Linux/x86/dbg.so-5.2.x /usr/lib/php/modules/
Please note, your PHP modules directory may be different. To find the path to your PHP modules
folder, oppen your /etc/php.ini file and look at the extension_dir variable.
-
You will need to modify your php.ini configuration file. Here's how:
-
Use a text editor, like nano or pico, to edit your php.ini file.
nano /etc/php.ini
-
Find the Dynamic Extensions section of the php.ini file. Add the
following line to that section:
extension=dbg.so-5.2.x
-
At the end of the php.ini file, we will need to configure the
DBG debugger. Add this code to the bottom of the php.ini file:
[debugger]
debugger.enabled=on
debugger.profiler_enabled=on
debugger.hosts_allow=localhost
debugger.hosts_deny=ALL
debugger.ports=7869, 10000/16
We are telling the debugger to allow a connection from
localhost only, and listen for that connection on port 7869.
-
Save the php.ini file, and exit the text editor. For nano and pico:
Ctrl-X Save Modified Buffer: Y File to write: /etc/php.ini
-
You will need to restart the Apache web server for the above changes to take effect.
/usr/sbin/apachectl restart
-
You will need to open PHPed and configure the communication settings for the remote debugger.
- Open PHPEd on your development computer.
- Open the Tools menu and choose Settings.
- In the Tools section select Debugger.
- Check the box labeled: Use Custom Port and Host (SSH Tunneling).
- For Port enter 7869.
- For Debugger Host enter localhost.
- Click OK.
-
You will need to configure your project to use the remote debugger.
- Still in PHPEd on your development computer...
- Right-click on your project and choose Properties.
- For this example, we'll assume the following:
-
Your project's root folder, on your development computer, is
C:\MyFakeProject\htdocs
-
Your project is published to a folder on the web server where it
is served by Apache. That publishing folder is:
/home/myfakeproject/htdocs
-
Your project contains at least one file, index.php, and that file is stored
locally in:
C:\MyFakeProject\htdocs\index.php
-
That same file is published remotely in:
/home/myfakeproject/htdocs/index.php
-
You access your project in a web browser at the following URL:
http://www.myfakeproject.com
-
In Project Properties, look at the
Mapping section of the Properties tab.
-
Choose HTTP Mode (3rd Party WEB Server) in the Run Mode popup menu.
-
Enter http://www.myfakeproject.com in the Root URL field.
-
Enter /home/myfakeproject/htdocs in the Remote Root Directory field.
-
You will need to configure PuTTY to forward SSH traffic from the Debugger.
- Open PuTTY on your development computer.
- Create a new Session to be used with the PHPEd debugger.
-
In the Host Name (or IP Address) field enter the host name for your web server.
myfakeproject.com
-
In the Saved Sessions field enter a name for your session:
MyFakeProject.Com Debugger
-
In the Category panel select:
Connection » SSH » Tunnels
-
In the Source Port field enter: 7869
-
In the Destination field enter: localhost:7869
-
Select the Remote radio button.
-
Click Add.
-
In the Category panel select:
Session
- Click Save.
-
Before you start debugging your code in PHPEd, you will need to connect to
this session in PuTTY. By doing so, you will forward all of your debugger traffic
via SSH.
-
Now that everything is set up, debugging in PHPEd is simple! Simply open the root file
for your web site, index.php, and click the Run in Debugger F9 button.
If you don't have the debugger toolbar, then simply open the Run menu and choose
Run in Debugger F9.
For more information, visit these sites:
|
|
|
|