Skip to content

Instantly share code, notes, and snippets.

@pcostarg
Last active November 9, 2017 18:38
Show Gist options
  • Save pcostarg/850c39a8e1f9d87715c2a62421e40c04 to your computer and use it in GitHub Desktop.
Save pcostarg/850c39a8e1f9d87715c2a62421e40c04 to your computer and use it in GitHub Desktop.
Install Development Environment for PHP on Windows
  • Install VS Code
    • Install following extensions:
      • Code Runner
      • PHP Debug
      • PHP Intellisense
    • Restart VS Code
    • Add the following to user settings (pay attention to php.exe path):
    {
      "code-runner.executorMap": {
          "javascript": "node",
          "php": "C:\\servers\\xampp\\php\\php.exe",
          "python": "python",
          "perl": "perl",
          "ruby": "C:\\Ruby23-x64\\bin\\ruby.exe",
          "go": "go run",
          "html": "\"C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe\"",
          "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
          "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
      },
      "php.executablePath": "C:\\servers\\xampp\\php\\php.exe",
      "php.validate.executablePath": "C:\\servers\\xampp\\php\\php.exe"
    }
  • Install XAMPP
  • By now we should be able to use code runner extension on VS code if XAMPP is all running well
  • Install XDebug (https://xdebug.org)
    • XDebug has a nice way to get the right dll by adding the phpinfo to the wizard: https://xdebug.org/wizard.php
    • to get phpinfo the easiest way is by creating a file in VS code
      • Create a file (eg.)test.php and write the following line:
        phpInfo();
        • Note: notice the intellisense from the plugin working :)
        • Select this line, right click and choose "run code"
        • the output window opens with all the information needed for XDebug wizard, just ignore the VS code line notifications and the phpInfo() (which is the code asked to run). In my case this would be the first 2 lines and the last line on the output. Copy everything else to the wizard.
    • Click the button to analyze and it will give you all information you need.
    • Save the file were it states it should be
    • Open the php.ini were it says, copy the information stated and paste it to the end of the file
  • Further more we need to config XDebug to connect to a remote debugger. This instructions were on the PHP Debug extension page and should added to the end of php.ini, after the information we pasted before in there. It should look like this (might have different dll path or name):
zend_extension = C:\servers\xampp\php\ext\php_xdebug-2.5.4-7.1-vc14.dll
[XDebug]
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
  • Go to XAMPP console and stop and start Apache

  • Go to VS Code

    • Debugger menu on the left
    • click on the cog settings and choose php
    • on the dropdown make sure it is selected "Listen for XDebug"
    • Whenever want to debug just run the debugger by pressing the play button here
  • Tidying up Apache for multiple projects and pointing it in the right place:

    • I like to have virtual hosts for different projects and without being stuck to the \xampp\sites\ folder. eg. of what I want: tv.localhost (points to c:\projects\tv), stuff.localhost (points to c:\stuff\stuffing), etc.
    • Go to your httpd-vhosts.conf file. Mine is in "C:\servers\xampp\apache\conf\extra"
    • Add the following to the end:
    <VirtualHost *:80>
       DocumentRoot "C:/servers/xampp/htdocs/"
       ServerName localhost
    </VirtualHost>
    
    <VirtualHost *:80>
       DocumentRoot c:\projects\transporter
       ServerName tr.localhost
    
       LogLevel info
    
       ErrorLog "logs/transporter-error.log"
       CustomLog "logs/transporter-access.log" common
    
       <Directory c:\projects\transporter>
           Options Indexes FollowSymLinks
           AllowOverride All
           Require all granted
       </Directory>
    </VirtualHost>
  • The first one is for default settings and keep reaching the XAMPP dashboard page and most importantly phpmyadmin "http://localhost/phpmyadmin/"

  • Other site I made is in "http://tr.localhost/" which points to "c:\projects\transporter"

  • If you need more just grab the second virtual host clone it under and make the needed changes to names and paths

  • Go to XAMPP console and stop and start Apache to read this config file from virtual hosts

  • All good to go :)

  • Just a side note it is easy to change the name of your server (different than localhost) by adding the new name on the windows host file and making the needed changes on this virtual host file config. So that for example you could get something like. tr.myhhouse.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment