WordPress – HP’s Blog

A few days ago I was faced with the task of having to establish a connection between the .NET and the PHP world as part of a small project.

As a .NET developer, I’m actually used to working with Visual Studio. Even if you are not always super satisfied with VS, you can still develop quite well with it. Therefore it was important to me for this PHP excursion to first build a “clever” development environment for this project.

Since I already use WebStorm (both first-class products from JetBrains) in addition to ReSharper (Visual Studio Plugin), it quickly became clear to me that PhpStorm from the same manufacturer should be used as the PHP IDE.

I understand a “clever” development environment as a minimum requirement:

  • A good editor (IDE) (best syntax highlighting)
  • A decent debugger (preferably integrated into the IDE)

With PhpStorm I have already selected the “good” IDE.

However, I cannot solve the problem of the integrated debugger directly and easily, either with PhpStorm or with another development environment for PHP that I know of.

To debug PHP there is an extension called “Xdebug” that works directly with PHP and has to be configured in PHP.INI.

And it was precisely this configuration and setup that was somehow not really easy for me as a .NET developer.

The configuration of Xdebug in PHP was still quite simple and well documented. However, how to set breakpoints from the IDE (PhpStorm) and how to use the debugger remained a sealed book at first.

About configuring PHP and Xdebug on an IIS using PhpStorm, there were actually no or only incomplete instructions (or I just couldn’t find them).

But enough of the preamble, from here it’s about the description (step by step instructions) how to set up a complete development environment for PHP on a Windows computer, with which even a .NET developer can do something 🙂 .

System environment, programs, requirements:

  • Windows 2008 R2 Server (Windows 7 with IIS installed would also work)
  • WordPress (Or any other PHP application such as Joomla)
  • imagePhpStorm 3.X
  • Xdebug (Debugging tool for PHP)

Installation / verification IIS

An IIS 7 or 7.5 (no IIS Express) is required.

Under W2K8, this is easy to do by selecting and installing the Web Server (IIS) server role.

image

No special role services are required, so just click Next and Install until the installation is complete.

image

Install WordPress (and all required components)

The easiest way to install a product like WordPress on a Windows machine is certainly to use the Web Platform Installer (which is also integrated into WebMatrix, by the way).

The web platform installer itself determines which components are available on the computer and which must be installed in order to be able to use the selected product.

Here you can download the Web Platform Installer

So download and call up (install) the Web Platform Installer.

After the initialization, we enter “WordPress” in the search field and confirm the entry with the Enter key.

Now we select WordPress in the desired language and press the Add button.

image

If you now click on Install, the following tools and products will be installed.

image

During the installation we still have to provide the following information:

image

Since I want to build a development environment, I will have MySQL installed on the local machine. (click next)

All the products to be installed are now displayed again and you are prompted to agree to the license terms.

image

Now a root password for the MySQL installation must be specified:

If you click Next, the installation will start.

The installation can take a different amount of time depending on the Internet speed, since the current packages are downloaded and installed during the installation.

With DSL 16000 and a computer with an I7 processor, the entire installation takes 3 – 5 minutes.

Configure next stop website for WP:

image

Since I only want to call WordPress in the development environment and not make it accessible externally, I leave the settings as default. After installation, this means that the page will be accessible under localhost/wordpress.

Another stop create database

image

Select / create database and root password

image

Of course, since we just installed MySQL, we need to create a new database.

In the input field (red arrow(, we must enter the root password that we assigned during the installation of MySQL.

Enter database user / password

image

We do not have to adjust the entries with the green arrows.

A password for the database user must now be entered in the fields with the red arrows. This does not have to be the same as the root password, but it can be (but please only on local development systems, otherwise the database password should not correspond to the root password)

No entries need to be made in any of the other fields.

image

image

WordPress and all the necessary tools and programs are now installed.

WordPress should be working now, so let’s test it.

Open browser and type localhost/wordpress.

image

It is best if we enter the necessary data for WP right away, so that we are later directed directly to the WordPress homepage and no longer to the admin setup page.

The next time it should look like this:

image

Install xdebug

Now we need to install the Xdebug Extension.

As we can see above, PHP version 5.2 was installed, so now we need to download and install the Xdebug version for PHP 5.2 as well.

But be careful, there are 2 different variants:

One thread-safe and one non-thread-safe (nts), the nts variant must be used for the installation on the IIS.

Click here to download xdebug version 2.1.2 for PHP 5.2 Not Thread Safe

The extension consists only of a DLL file with the name:

php_xdebug-2.1.2-5.2-vc6-nts.dll

After downloading the file, it must be copied into the PHP Ext directory.

With a standard installation on a W2K8 server (64 BIT), the Ext directory can be found under the following path:

C:Program Files (x86)PHPv5.2ext

Next, the PHP.INI must be adjusted to use the Debugger Extension

The PHP.INI is in the directory:

C:Program Files (x86)PHPv5.2

So we open the PHP.INI with a text editor and add the following entries:


[xdebug]
zend_extension = "C:Program Files (x86)PHPv5.2extphp_xdebug-2.1.2-5.2-vc6-nts.dll"
xdebug.remote_enable = On
xdebug.remote_host = "localhost"
xdebug.remote_port = 9000
xdebug.remote_handler = "dbgp"

Actually, it doesn’t matter where these entries are added, but if you like to stick strictly to specifications, you can insert the entries directly under the following entry, then it will definitely work.

image

Now we save the PHP.INI and still have to restart the IIS:

Either through the console “Internet Information Services (IIS) Manager

or via the command line:

net stop WAS (to stop IIS)

and then

net start W3SVC (to start IIS again.)

Later (after we have installed PhpStorm and thus also have a usable editor at our disposal) we also check whether the extension has been set up correctly.

Install PhpStorm

PhpStorm is available in a 30-day trial version, so if you don’t have a license, you can take a look for 30 days to see if PhpStorm is worth the money it costs (I think it’s definitely a great product as it is all JetBrains products. No, I don’t get any percentages 🙂 )

You can download it here: http://www.jetbrains.com/phpstorm/download/

After downloading we just install PhpStorm with all default settings.

Set up WordPress project in PhpStorm

Now we open PhpStorm and select the following option:

Create New Project from Existing Files

image

The scenario: local web server and source code below the web root fits our project perfectly.

image

Now we select the root directory (Don’t select the WordPress directory) of the default WEB of our localhost.

image

Now we give the project server a name (e.g. MyLocalServer)

image

In the next step (see figure above) we now enter the project URL of our WordPress installation.

And have thus set up the project (as you can also see in the following figure).

Check xdebug

We open the index.php file from the root directory of our WordPress installation in the PhpStorm Editor.

There we insert the phpInfo() function directly after the comment and save the file.

image

Now we open the browser and enter localhost/wordpress. If this PHP info page is displayed instead of the normal WordPress start page, we have already done everything right up to this point.

image

In order to be able to carry out the Xdebug check, we need the source code of the phpinfo page displayed in the browse.

To do this, we display the source text of the page, select the entire source text, copy it to the clipboard, and then open the following website:

http://xdebug.org/find-binary.php

image

Where the red arrow is pointing, we then paste the source text on the clipboard and then press the “Analyze my phpinfo() output” button.

If Xdebug is properly installed, the result should look like this:

image

If Xdebug is not installed correctly, you should check whether the path and file name of the Xebug DLL in PHP.INI are correct.

Configure PhpStorm for debugging

image

We open the “Edit Configurations” dialog

image

Now let’s add a new configuration:

image

A PHP web application configuration

image

In the unnamed field we give our configuration a name. For example IIS.

Then we have to select a server (but since we haven’t configured one yet, we have to create a new one first).

Open a dialog to set up a new server here:

image

Then click the + in the dialog to create a new server:

image

Here is the completed dialog:

image

Confirm the entry and then add the following entries, see description below the figure.

image

Give the configuration a name (e.g. LocalIISWordPress)

And add WordPress to the StartUrl so that the correct link (http://localhost/wordpress) is displayed under the Start URL.

It should then look like this:

image

Then we also confirm this dialogue

And if we now press the RUN button ….

image

The default browser should open automatically with the WordPress page.

Actually, setting a breakpoint should work now, let’s try it by setting a breakpoint on the phpinfo() line that we added to index.php.

image

By the way, you can easily set a breakpoint by clicking with the mouse on the spot where the red arrow is pointing.

And if we now press the DEBUG button instead of the RUN button …..

image

Correct, the program flow stops at the breakpoint and waits for us to continue the program flow.

So and now have fun with PHP debugging.

I like it:

Like Loading…