PHP Classes

Fast Debugging of PHP Code Using PHPEd Part 3: Remote Debugging and Remote Projects

Recommend this page to a friend!
  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog Fast Debugging of PHP...   Post a comment Post a comment   See comments See comments (4)   Trackbacks (0)  

Author:

Viewers: 1,177

Last month viewers: 5

Categories: PHP Tutorials, Sponsored

IDEs are good to help debugging your code before it goes to production, but sometimes you need to find bugs in your code that cause problems and can only be observed in production. This is one case on which remote debugging is necessary.

IDEs like PHPEd support remote debugging. You do not need to download the project files from the production server to debug your project remotely. Thanks to the remote projects feature of PHPEd, it can retrieve only the server files that you need to debug so you can start debugging remote projects very quickly.

Read this article to learn how to setup and use PHPEd to debug remote projects running in production server for instance.




Loaded Article

Introduction

In the first part of this tutorial series it was covered setting up PHPEd for debugging simple projects and the framework based projects in the second part.

The part covers a more advanced aspect of PHPEd debugging, which is to debug projects running on remote servers.

Remote access to projects is needed by software developers that need to debug projects that are running in other machines, those being in production or testing machines, or even virtual machines running locally.

A software team can achieve great productivity gains when working with an IDE that supports remote debugging.

Example of Remote Projects and Applications

Remote debugging involves working from your local computer on software that is on another computer, the remote machine.

Our firm relies heavily on cloud platforms. I would say 80% of the infrastructure is on the cloud, and is often accessed by engineers and developers in different locations of the country at any given time. Majority of the applications we develop and use are PHP based.

The remote stack of our PHP applications consists of among others:

1. Linux environment test server (Centos 6.5)

2. Ioncube Licensing Server (Windows Server 2012)

3. Windows environment test server (Windows 2008 R2)

4. Accounting software (Windows Server 2008 R2)

5. Mobile transactions server (Centos 6.5)

The team may need to access any of these servers. At times, they are accessed by consultants who telecommute, or work from the client site. Thus remote access for debugging may be required at any point in time in such an environment.

Overview of Remote Debugging and Remote Projects

PHPEd IDE allows you to use the same debugging techniques on a remote server that you can use with local server. In this article, I will demonstrate a debugging session of the PHP based CRM named X2-Engine remotely using PHPEd IDE.

Remote projects allow developers to handle files in a remote server as if they were local. Actually it can retrieve just the necessary files from the remote server so you do not have to wait to download the whole project files.

We will look at how we can create remote projects to our headless Linux Server to enable developers access the project using the IDE.

While remote projects are rather straightforward, remote debugging will take a bit of setting up on the IDE to ensure that it works correctly. To give you a quick understanding of the process, below you can see a image from the PHPEd forums which highlights well what happens during a remote debugging session.

phped3_1_overview.gif

Remote Debugging and Remote Projects: Customizing X2CRM

Creating The Remote Project on the Linux Server

Our test server runs on Centos 6.5. We have several Web based projects running there. Our latest project involved uploading of X2 Engine CRM to the server. This is a Yii based framework, a framework that is also supported by the IDE.

Being a test environment, developers may be required to log in to tweak certain parameters as well as to work on source code remotely. Testers also log in to write, update and run tests. Listed below is th base directory of the CRM

phped3_2debugging_linuxserverx2directory

Setting Up FTP Accounts in the Linux Server

Remote projects may use a variety of file transfer protocols. FTP and SFTP protocols are supported. For the Linux server, we have an FTP account for each developer who is authorized to log in remotely. I am not covering setting up of FTP server on Centos.

There are several qualified instructions online on this security sensitive process. This is one of the tutorials I found online on the topic: for Centos 6.5  and Centos 7.

Setting Up the FTP Accounts in PHPEd IDE

Set up the remote SFTP account by visiting Tools >> Accounts Section

Next, select File Transfer based accounts. There are several options for the various protocols that you can choose. Since we are using FTP, select FTP option.

phped3_4remoteproject_addsftpaccount2.png

Type the FTP account credentials and save the profile. It would be nice to see a test connection feature here added by the PHPEd team which would enable you know if you have already configured the account correctly prior to beginning your coding.

Prior to connecting to your project server, you should verify that the ports required for FTP or SFTP are opened in your server, to avoid having unnecessary connection errors when your developers are trying to create the remote project.

phped3_5remoteproject_addsftpaccount3.png

Creating a Remote Project

Start the new project wizard and select the option "All project files are on the remote server".

phped3_6remoteproject_filesonremoteserver1.png

Next, select the appropriate directory under the FTP section of the Directory listing. If you get an error when trying to expand the FTP tree, verify your FTP settings again in the IDE accounts menu, or verify that your firewall settings appropriately have authorized the ports required by FTP to connect.

Most of our servers run on AWS. We added the below to the inbound security rules on the Centos 6.5 server in order to allow FTP access.

phped3_7remoteproject_awsinboundsecurityrules1.png

As per the below illustration, select the appropriate remote directory from the FTP section of the Directory listing in the Project creation wizard.

phped3_8remoteproject_selectrootdirectory1.png

You may then proceed to complete the wizard, including the option of whether to enable support for PHPUnit in the project or not. This allows you to integrate Unit Tests into your project.

phped3_9remoteproject_selectrootdirectory2.png

During the installation process, you have the option of deciding whether to let PHPEd install DBG extension or you on the remote server.

Because we want to also run remote debugging, remember to enable checks for PHP and DBG-Wizard to complete the steps because the DBG extension is essential to the debugging process when you are developing your projects.

phped3_10remoteproject_phpanddbgwizardcheck.png

Because the remote web server did not have DBG installed and configured, the health checks did not complete.

I had to copy the dbg-php-5.6.so file to the server to enable the DBG wizard to work. This file is located in C:/Program Files/NuSPhere/debugger/server/dbg-x.x.x-YourPlatform.tar.gz.

For my case it was dbg-8.1.5-Linux.tar.gz. We are using PHPEd 17. This was done via FTP. It is important that all your checks go through to ensure your developers are able to work comfortably.

Upon taking 5 minutes to install the required .so and make the changes in php.ini on the remote server, we are able go get a clean bill of health on all the checks.

I opted out of SSH connection:

phped3_13remoteproject_sshconnectivity1.png

The Wizard will recommend that you leave the port 7869 as default unless you are a member of a development team using an agreed unique port.

phped3_14remoteproject_port7869.png

Our project is now ready to go and we may begin configuring the CRM for web use

phped3_15remoteproject_editcode.png

Now that our DBG Session is loaded, we can proceed to Debug our CRM application.

Running a Remote Debugging Session

Our assignment with this particular CRM was to override default X2Engine parameters which have been boiler-plated. We will be stepping into the bootstrap process that the CRM does. Being a YII based software, requests are routed through the index.php file, which is the file that will launch into a debug session.

You may get the IDE failing to launch the session after showing the "Loading debug session" message for a while. This is likely a port issue and you need to check if your debug port (default 7869) is open.

phped3_18_remoteproject_portissue.png

Once you open  the ports, you are now able to step into the code

phped3_19_remoteproject_stepinto.png

When in a remote debug session a window called Transfers shows the files which have been moved to your local disk to enable introspection by the Debugger.

phped3_20_remoteproject_transferswindow.png

We iterate and locate the boilerplate configurations, and proceed to customize the CRM as required by the client.

phped3_22remoteproject_theme2.png

Conclusion

You can see that we were able to connect to the remote server and make our CRM customizations on x2Engine remotely. Such applications are usually very customer centric thus can allow your remote team of developers to work from the comfort of their remote office or home.

If you would like to try this remote projects feature for debugging with PHPEd you can try it for free downloading the 32 bit or 64 bit version from this page.

If you have a question about debugging of remote projects, post a comment here.




You need to be a registered user or login to post a comment

1,614,673 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:



Comments:

1. Catching bugs that only show up in Prod - Nick Weavers (2016-06-29 17:12)
PhpEd's invaluable remote debug debugger... - 3 replies
Read the whole comment and replies



  Blog PHP Classes blog   RSS 1.0 feed RSS 2.0 feed   Blog Fast Debugging of PHP...   Post a comment Post a comment   See comments See comments (4)   Trackbacks (0)