📜 ⬆️ ⬇️

Installing and configuring JetBrains PhpStorm 6 for Windows 7 for developing web applications in PHP

I am Microsoft Scum and got used to the presence of installers, after the successful implementation of which I have installed and configured everything I need on my machine.

With PHP it turned out wrong, which led to several hours of torment and false moves, to eliminate which I wrote this article.

How it works


Being a web developer under ASP.NET since 2003, I got used to the fact that the application being developed is running on IIS. Now, together with Studio, a compact version of IIS is being installed, and, to admit, development under it is in most cases much more convenient than deploying an additional development environment under a full-fledged IIS.
')
PHP also has a launch mode as a server with a choice of application root directory. However, it turned out that this mode does not allow for a human debugging of the product. For this reason, we will recreate a more or less native environment for frameworks: Apache + PHP. At the same time, the ability to debug and test is provided by separate modules that have a specific assembly for a specific PHP assembly without any freedom of choice. It is for the better - the lack of freedom of choice of versions limits us to only one installation scenario. We will describe it then.

The article will use the default values ​​for 64-bit Windows. For 32-bit, the only difference is that instead of the C: \ Program Files (x86) folder, you must use the C: \ Program Files folder.

Target configuration




We put PHP 5.4


At the time of this writing, the installer was not offered, so we put what we have:
  1. Login with an account with administrative rights;
  2. windows.php.net/download/#php-5.4 - download the VC9 x86 zip archive (http://windows.php.net/downloads/releases/php-5.4.15-Win32-VC9-x86.zip); hard hardcore lovers can download the corresponding Debug Pack, but I haven’t yet offered a build for me;
  3. unpack the contents of the zip-archive into the folder “C: \ Program Files (x86) \ PHP \ v5.4” (I think a hypothetical installer would put everything there);
  4. inside the resulting folder, run the scripts “pws-php5cgi.reg” and “pws-php5isapi.reg” (this is not necessary, but this way PHP will be registered in IIS and will give you the opportunity to master your masterpiece);
  5. we copy "php.ini-development" in "php.ini"
  6. open "php.ini", find a block there:
    ; Directory in which the loadable extensions (modules) reside. ; http://php.net/extension-dir ; extension_dir = "./" ; On windows: ; extension_dir = "ext" 
    and remove the comment from the last line, it turns out:
     ; Directory in which the loadable extensions (modules) reside. ; http://php.net/extension-dir ; extension_dir = "./" ; On windows: extension_dir = "ext" 
  7. all in the same php.ini find the block:
     [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = 
    and register the zone where the computer is located (I have this “Europe / Moscow”, php.net/manual/en/timezones.php contains information about the supported zones):
     [Date] ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = "Europe/Moscow" 
  8. go to Start \ Control Panel \ System \ Advanced System Settings, there in the Environment Variables in the System Variables list we find the “Path” variable and add it via “;” path "C: \ Program Files (x86) \ PHP \ v5.4"
  9. Open the cmd and make sure that the command 'php -v' (register matters) gives information on the installed version of PHP (in the guide it is 5.4.15).

Is done.

We put XDebug 2.2.2


There is traditionally no installer, so:
  1. like we are already logged in as admin ...
  2. xdebug.org/download.php - download 5.4 VC9 (32 bit), which without the TS xdebug.org/files/php_xdebug-2.2.2-5-5.4-vc9.dll suffix is ​​just for multi-threaded PHP 5.4; it is immediately .dll, so the browser can express doubt about the expediency of downloading - convince him;
  3. we put the downloaded file into the folder “C: \ Program Files (x86) \ PHP \ v5.4 \ ext” - in this folder are all PHP extensions;
  4. open php.ini (with any editor, but always in Run as administrator ... mode, otherwise our edits cannot be saved) and add the block:
     [XDebug] ; http://xdebug.org/wizard.php zend_extension = ext\php_xdebug-2.2.2-5.4-vc9-nts.dll xdebug.remote_enable=1 xdebug.remote_port="9000" xdebug.profiler_enable=1 xdebug.profiler_output_dir="D:\Temp\XDebugProfiler" xdebug.remote_host = "localhost" 
  5. open cmd and go to the folder, which is not a pity to clog one file;
  6. run the command in it: “php -i> out.txt” - in the current directory there will be 30 kilobytes of php configuration information;
  7. xdebug.org/wizard.php - go to the xdebug settings page, paste the contents of “out.txt” into a large white field and click on [Analyze my phpinfo () output], you should get the following result:
    SUMMARY
    • Xdebug installed: 2.2.2
    • Server API: Command Line Interface
    • Windows: yes - Compiler: MS VC9 - Architecture: x86
    • Zend Server: no
    • PHP Version: 5.4.14
    • Zend API nr: 220100525
    • PHP API nr: 20100525
    • Debug Build: no
    • Thread Safe Build: no
    • Configuration File Path: C: \ Windows
    • Configuration File: C: \ Program Files (x86) \ PHP \ v5.4 \ php.ini
    • Extensions directory: ext
    YOU'RE ALREADY RUNNING THE LATEST XDEBUG VERSION
    But here are the instructions anyway:
    1. Download
    2. Move the downloaded file to ext
    3. Update C: \ Program Files (x86) \ PHP \ v5.4 \ php.ini and change the line
    zend_extension = ext \
    Capsule inscription is the most important. If suddenly tomorrow comes the latest version of XDebug, write, I'll put it myself too.

Is done.

We put PHPUnit


  1. pear.php.net/go-pear.phar - put the downloaded file into the folder “C: \ Program Files (x86) \ PHP \ v5.4” (phar is the file with the application distribution kit, you can start the distribution package with the command “php file_name. phar "in the console);
  2. we run the command prompt on behalf of the administrator, go to the folder “C: \ Program Files (x86) \ PHP \ v5.4” and call the command “php go-pear.phar”, answer the script questions “system”, in the next question click Enter (or accept all the locations of the default directories), allow you to edit php.ini (the installer will prescribe "C: \ Program Files (x86) \ PHP \ v5.4 \ pear as inclusive paths");
  3. As a result of the previous paragraph, the PHP package management system appears (similar to NuGet for the Studio), which uses online repositories - we will add the PHPUnit repository there by entering the command pear channel-discover pear.phpunit.de () in spite of the proxy, everything worked out for me, otherwise check the correctness of the proxy server settings in Windows and its efficiency);
  4. if in the command prompt enter the command “pear remote-list -c phpunit”, then it becomes clear that besides PHPUnit itself there are many other cookies, but for now we will put only the base itself, and add additional modules as needed: “pear install phpunit / phpunit ";

Is done.

Upgrading PHPUnit and other modules installed with PEAR is done with the pear upgrade-all command. In general, I recommend reading the instructions for PEAR. An experienced developer, she will certainly inspire thinking about how to distribute her work not by downloading via FTP, but using the same PEAR.

We put Apache 2.4


Personally, I have clogged ports 80 (IIS), 8080 (TFS) and 8000 (HTTP proxy). For this reason, I set Apache to listen to port 8085. Here are the settings for Apache on port 8085. I also use “d: \ www \ Apache” as root directories.

Apache for Windu has a separate website www.apachelounge.com , from where you can download the most recent one. Since PHP is x86, all its .dll files are x86, so Apache will have to install x86.

  1. www.apachelounge.com/download - Download httpd-2.4.4-win32.zip and unpack the contents of the Apache24 folder of the archive into the folder C: \ Program Files (x86) \ Apache24;
  2. open the file C: \ Program Files (x86) \ Apache24 \ conf \ httpd.conf for editing (under admin)
  3. find the setting ServerRoot and set
     ServerRoot "C:/Program Files (x86)/Apache24" 
    (Since Winda has turned from a graphical shell over DOS into an independent OS, it doesn’t care which way the slash is tilted, but Apache doesn’t care, we have to use strictly "/");
  4. find the Listen setting and set
     Listen 8085 
  5. find the DocumentRoot setting (and the Directory block following it) and set up our paths:
     DocumentRoot "D:/www/Apache/web" <Directory "D:/www/Apache/web"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory> 
    do not forget to create this directory (you may have noticed that at the end of the path I added a web subdirectory - this is due to the fact that I am going to use symfony, which assumes the content of the site itself in the web subdirectory of the overall project);
  6. find a list of a large number of LoadModule instructions and uncomment / edit / add tailing
     LoadModule php5_module "C:/Program Files (x86)/PHP/v5.4/php5apache2_4.dll" 
  7. It’s not a fact that the module is loaded, so in the last Apache other settings related to the module are taken to swear into the IfModule condition, checking that the module has loaded, therefore we find / add the container for the PHP module settings under Apache:
     <IfModule php5_module> </IfModule> 
  8. configure the PHP module for Apache:
     <IfModule php5_module> PHPIniDir "C:/Program Files (x86)/PHP/v5.4" AddHandler application/x-httpd-php .php </IfModule> 
  9. find the settings of the directory listing module and edit it:
     <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> 
  10. register the Apache as a service with the command in the command prompt
     "C:\Program Files (x86)\Apache24\bin\httpd" -k install 
  11. when loading Apache will be started automatically, and now we will start it manually by command in command prompt
     net start Apache2.4 
  12. and now let's see how all this will take off, placing in the directory "D: \ www \ Apache \ web" file "index.php":
     <?php phpinfo(); 
    and requesting it from the browser by url http: // localhost: 8085 /

Is done.

Customize PhpStorm 6



www.jetbrains.com/phpstorm - download, install , launch PhpStorm 6 (it has a trial month, personally, this was more than enough for me to purchase).

Installing integration with TFS (optional)

It is necessary to get used to working with TFS from PhpStorm, as well as from other products that use the Idea environment. Terminology and behavior are significantly different from those in Visual Studio. However, integration is much more convenient. than running in Visual Studio for each file.

So,
  1. The screen should have a PhpStorm start window, if instead of this window the development environment is displayed, close the current project;
  2. in the right area of ​​the start window, select Configure / Plugins Go to File / Settings;
    From the development environment, this setting is available from the File / Settings menu. The left part of the window displays a list of settings for both the project and the environment as a whole. You will need to select the Plugins environment setting.
    “Project Settings” - settings from the list with the heading Project Settings,
    "Environment Settings" - settings from the list with the IDE Settings heading.
  3. in the list of plug-ins that will open, make sure that the “TFS Integration” plugin is not installed (by default it is not included in the PhpStorm package) and click the “Install JetBrains plugin” button (at the bottom of the window);
  4. in the search window we drive in “TFS” and double-click on the line with the “TFS Integration” plugin, to the question about the intention to download the plugin, we answer with a solid “Yes”;
  5. wait until the plug-in is installed, close the settings windows and restart PhpStorm so that the newly installed plug-in will work.

Now we have an environment ready to work with TFS.

Create or open a project

  1. In the folder D: \ www \ Apache create a new empty project, or open an existing one
    Remember that the Apache server is configured for the web subdirectory, and therefore the site itself will be located in the web project folder. In the future, in addition to the .idea project, subfolders such as vendor for storing third-party developments, test for test scripts and other subfolders for frameworks may appear next to the web.
  2. if the site is empty, then we create a simple index.php page on the site with the contents of the type
     <?php phpinfo(); 
  3. If the project is serviced by a version control system, this must be specified in the settings of the Version Control project.

Set up a php server in PhpStorm

  1. In the project settings, open the PHP configuration and configure it there:
    PHP language level: 5.4
    Interpreter: click "...", specify Name: PHP 5.4, PHP Home: C: \ Program Files (x86) \ PHP \ v5.4, Debugger: Xdebug;
    Include path: click "+" and specify "C: \ Program Files (x86) \ PHP \ v5.4 \ pear" so that our project automatically pulls in the previously installed PHPUnit.
  2. in the project settings, open PHP / Servers - a bookmark with an empty list of servers will open;
  3. Press "+" to add a new server and fill in its data:
    Name: Local Apache
    Host: localhost
    Port: 8085
    Debugger: Xdebug
  4. if the port other than 9000 is specified in the Xdebug configuration, then go to the settings of the PHP / Debug project and set up the “Debug port” in the “Xdebug” section;
  5. In the project settings, open PHP / PHPUnit and make sure that it says "Load from include path".

We configure the web application

  1. In the "Run / Edit Configurations" menu, click on "+", select "PHP Web Application" and fill in its data:
    Name: My Application at Local Apache
    Server: Local Apache
    Start URL: start page (index.php)
    Browser: I chose Chrome, but for each specific page there is a launch option in any browser

We start debugging

  1. We put a breakpoint on any instruction;
  2. in the “Run / Debug” menu, select “My Application at Local Apache” - the site will be debugged;
  3. make sure that the execution of the php-script was interrupted at breakpoint, and all the advantages of the debager are available to us.

Wednesday is ready to go.

Conclusion


MS Visual Studio users will have to get used to the fact that pressing the Run button while debugging is on does not continue the execution of the current script, but opens a new request to the server in the browser and disables debugging, but even with such differences, the debugging process is pretty easy.

Of course, just a comfortable development environment is not enough to create a good product. I recommend reading habrahabr.ru/post/174963 - an article that summarizes the main rakes that developers stumble upon in their first projects. If you already have successful experience in developing large projects on other platforms, try to look for similar solutions on the PHP platform, or bring your own ideas.

Source: https://habr.com/ru/post/177631/


All Articles