PhpStorm is JetBrains' integrated development environment for PHP, based on IntelliJ IDEA. As of 2017, PhpStorm is one of the best commercial PHP IDE-s. JetBrains offers PhpStorm for free for Tiki development.
Table of contents
- 1. Comparison with alternatives
- 2. Issues
- 3. Setting it up
- 3.1. Installation
- 3.2. Import Tiki Code Style Settings
- 3.3. Debugger (side of the HTTP server)
- 3.4. Configuring the PHP interpreter & path
- 3.5. Server
- 3.6. Add a PHP Web Application
- 3.7. Create project(s)
- 3.8. Configure directories
- 3.9. Set default headers
- 3.10. Create a custom scope
- 4. Tips
- 5. Troubleshooting
- 6. Useful links
In no particular order (yet) by Jonny Bradley
- Navigate -> File... (and Class... and Symbol...)
Especially the way you can type the initials of the words in the filename
e.g. "t a t o o" gets you tiki-admin_toolbars (the php, tpl and js files if you want)
- Edit -> Copy Reference
Except the way it includes the leading slash... must looks for a pref for that!
makes me smile, but seriously, the debugger knows what's going on to a far deeper level than any other PHP IDE i've tried
- Code -> Refactor as... (variable, method etc)
Common on Java IDE, but not seen it on PHP
- Code -> Comment/Un-comment
Sounds trivial but it's the first thing i've found that does it correctly in all languages, not just PHP and JS, but Smarty, HTML and CSS too. Chealer 2018-02-07: Not reliable for me
- View -> Compare with clipboard (you can merge changes form the clip board into an open file)
- Advanced debugging (breakpoint activation when another breakpoint is hit, expression evaluation on hover, etc)
- CSS colour indicators
- Column select
- Tools -> Deployments -> Sync and Diff with Deployment
- Code completion on SQL files (fills in tables and column names from your database - thanks Luci ;)
- Branch merging - as you would expect, far more civilised (and quick) than any other IDE i've tried, and so much more controllable (for me) than using a shell
- Shelve changes which reverts your current changes and keeps them in a safe(ish) place until you want them back again
- Live templates: create your own idiosyncratic code snippets and insert them by typing an abbreviated name followed by TAB
- You can get a free version for use on your Tiki work (see details below)
- The SFTP plugin (Remote Host) is in development. Specifically, as of version 0.1 (PhpStorm 7.1.5), at least on Windows, direct drag-and-drop from/to Windows Explorer is not supported, unlike Eclipse's Remote System Explorer. Remote files can not be downloaded.
- The history of commit messages cannot be shared between projects (for example, when backporting a change).
- "Find Usages" does not necessarily provide an exhaustive list. For example:
- A method will not show its usages through objects whose type PhpStorm fails to infer.
- A method will not show its usages from Smarty templates if the object on which the method is called is assigned from PHP.
- Calls to methods through callbacks specified with a simple string are ignored.
- Using "Find Usages" on a global variable in a function will only find usages in that function (see WI-18065).
- "Find in Path" forgets the scope when switching between projects
- Tiki's default Smarty cache behavior is to compile only if a template file's timestamp is newer than the timestamp recorded on the latest compilation. Using PhpStorm's Revert action from Local history sets the reverted file's timestamp to the time the original version was created, rather than the time the reversion was performed. As of PhpStorm 2017.2.1, there is apparently no setting to control that behavior. This means Local history reverts performed by PhpStorm will not be reflected in Tiki until template cache is cleared, by default. To deal with this, either perform a dummy modification of all reverted files (for example, add a space and then remove it) or set Smarty to recompile always and accept a performance hit for every request.
- PHP's extract() function is problematic. Reads of the variables extracted are reported as errors. Moreover, the debugger does not show these variables in the Variables zone due to Xdebug bug #546.
- Similarly, importing Global variables in function scope using composed variable name / variable variables will fail to add them to the Debug tool window, and accesses will be erroneously displayed as errors.
- In the editor's vertical scrollbar, the thumb's position and size is broken, which makes it confusing to try navigating issues.
- "Comment with Block Comment" does not behave properly on function with PHPDoc comments
- The inspection for unused variables generates numerous false positives due to several scenarios, notably file inclusions and variable variables.
- Move Caret to Code Block end/start in a PHP file can bring to wrong location
- With certain layouts (including French Canadian), some keyboard shortcuts have no effect, such as "VCS Operations Pop-up" and Move to code block end/start.
- Annotating several files (such as tikilib.php on branch 15.x) results in an error being displayed at the top ("Number of lines annotated by Subversion is not equal to number of lines in the file. Check file encoding and line separators."). With "Display anyway", some of the lines show correct annotations, but some lines lack annotations in some cases. Not clear if missing annotations are due to this bug or to excessively long histories. Affects Chealer with PhpStorm 2017.3.2
- Controlling indentation can be problematic in Smarty templates, as described in this ticket.
- "Merge From..." appears broken with branches in 2017.2.1 if one directly selects the branch (another menu opens prompting to select a file in 17.x, for example). Instead, selecting "branches..." and only then 17.x works.
- When merging, non-conflicting changes are not applied automatically.
- Annotations are very intelligent, blaming the initial commit when the last change is from a merge, but perhaps too confident. The initial commit displayed can apparently be wrong if a merge encompassed several commits on the same file (PhpStorm 2017.3.2).
- By default, a tab is quietly closed when opening a new tab with already 10 tabs open.
And many more...
This section is incomplete and likely outdated.
If you are a regular contributor to the TikiWiki project, then you may be eligible for a free license to PhpStorm.
- Contact Nelson (nkoth on IRC) and ask him for the user name and license key.
- Once you receive the mail, log in to Jetbrains.
- Download PhpStorm from https://account.jetbrains.com/licenses
- Start PhpStorm
- With PhpStorm 2017, you will get prompted on the first launch and can just enter your JetBrains account credentials. If not, keep reading this section...
- Help > Register
- Enter the user name and license key exactly as in the email
Don't enter the key as a single line!
The license key you will have received, may be on several lines.
You must enter it exactly like that, without trying to "unwrap" the key into a single line.
Get PhpStorm from http://www.jetbrains.com/phpstorm/
Download this XML file for PhpStorm 2017, or another file from here for previous versions.
Go to File -> Settings... -> Editor -> Code Style and in the drop-down menu next to the Scheme drop down at the top, select Import Scheme ->Intellij IDEA code style XML.
Choose a PHP debugger, either Xdebug or Zend Debugger, install and configure it on the HTTP server's side.
To install Xdebug for PHP 5 on Debian, the following command may be used:
sudo apt-get install php5-xdebug
To install Xdebug under Mac 10.9 Maverick using MacPorts (couldn't manage to install phpunit) Bernard Sfez / Tiki Specialist :
sudo port install php5-xdebug
To configure Xdebug on the HTTP server's side, the following settings could be used as a reference:
[xdebug] ; Remote settings xdebug.remote_enable = On xdebug.remote_cookie_expire_time = 100000 ; 1 day ;xdebug.collect_params = 2
Some useful info on setting up xdebug and phpstorm to do remote debugging can be found here: https://confluence.jetbrains.com/display/PhpStorm/Remote+debugging+in+PhpStorm+via+SSH+tunnel, mainly the part about the ssh port 9000 tunnel - that's the bit that was missing for me Jonny Bradley
This section is outdated. You should probably skip it. 2017-06-26
PhpStorm expects to find the Php interpreter in a particular location (ex: on my mac, it's /usr/bin/php). But it could be that you are using an interpreter that is in a different location.
Here is how you can do that. The particulars of the steps seem to depend on the version of PhpStorm you use. Below are the steps as described originally by Jonny, and those for PhpStorm 6.0 (written by Alain)
- Preferences > PHP
- Click on ... to the right of Interpreter.
- Browser to the location of the php interpreter (ex: /opt/local/bin)
- Click on the + sign at the top left, then Specify other
- For Name, enter a freetext name for that version of the interpreter (you could just set it to the full path)
- For PHP home, enter the path of the directory that contains the php executable (ex: /opt/local/bin). Do not include php at the end of the path (it has to be a directory, not the path to the executable itself).
- Preferences > PHP
- Choose the interpreter for which you want to set the path, by clicking on the ... to the right of Interpreter
- Click on the + sign at the bottom right of the PHP window
- NOT SURE ABOUT THE REST
File → Settings → PHP (open)
Interpreter > Add
Enter the following:
Name: "php on ubuntu" (free text)
PHP home: /usr/bin/
→ See appear the PHP version (here PHP version 5.3.... )
- Click at the plus sign
- add path to application source (real place without links)
- Name: localhost
- Host: localhost
- Port: 80
- Debugger: Xdebug
- (X) Use path mappings (select if the server is remote or symlinks are used)
Open Run -> Edit configurations...
Click on the plus ("+") sign at the top and select "PHP Web Application".
Adjust the Name and Start URL fields and select OK.
The code edited needs to be in a PhpStorm project. If you are working on several Tiki versions, it is best to create one project per version.
PhpStorm allows to use a single window for all projects or one window per project. Most Tiki developers seem to choose the latter option.
For Tiki 17 and above, in File -> Settings... -> Directories, mark temp/ as Excluded.
In Settings..., Editor -> File and Code Templates, Includes tab, set PHP File Header to something like:
// (c) Copyright 2002-2017 by authors of the Tiki Wiki CMS Groupware Project // // All Rights Reserved. See copyright.txt for details and a complete list of authors. // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. // $Id$
A custom search scope will make Find in Path faster and more relevant. In Settings -> Appearance & Behavior -> Scopes, add a local scope which can be named "Tiki proper".To exclude vendor directories, you can use a Pattern such as
language.php files are a major slowdown. To exclude them only keeping - for example - French (fr) files, you could use a pattern like
Since Remote Host does not support copy-pasting files, uploading changes to a server can be done by copy-pasting the whole contents of modified files.
However, this can change indentation, since PhpStorm reformats on pastes by default. There are 2 ways to avoid this issue. Furthermore, since PhpStorm considers all pasted lines as modified, it will feel free to remove trailing whitespaces by default when the remote file is saved. To keep the remote file as identical as possible, you need to set the "Strip trailing spaces on Save" setting in Editor -> General, Other section to "None". This has the unfortunate side effect of disabling trailing spaces stripping even in new code you write. To minimize the risk that you unintentionally add trailing whitespaces, you may enable Show whitespaces in Settings... Editor -> General -> Appearance.
To update a checkout, do VCS -> Update project....
If you have several projects, select the one to update.
Turn on Autoscroll from source option, so that the project browser repositions itself automatically to the page you are currently have in the editors. That way, if you want to do an operation on the file you are editing (ex: delete, rename), or see other files in the viscinity, you can just go from the editor to the project browser.
To set this option on:
- Click on the project
- Click on the gear icon (top right of the project browser)
- Check Autoscroll from source
Make use of the various navigation and search shortcuts. One really powerful thing about those is that you can search for things by specifying parts of its name, that might not be consecutve. So for example, searching for a file with "tiki permissions" will find "tiki-debug-permissions.tpl".
Below are some of the more useful search and navigation shortcuts:
- Command+Shift+O: search for a file.
- Ctrl+Shift+F: Search all files in the project
- Command+O: Search for a class.
- Ctrl+Alt+Shift+N or Ctrl+Command+O: Search for a symbol (class, method, variable, etc...)
Useful tip from this 2015 mail:
Seems that the way i do merging of single commits in phpStorm isn't in their documentation, i think i just worked it out several versions ago (don't like manuals mostly
So here's what i do... let's say i want to merge a commit from trunk into 14.x...
First thing to do is configure the branches in your project (you need that also to do "Compare with branch..." which is really handy too.
It should work out where trunk is, and last time i did it it added branches, mods, third_party etc as branch locations, you can remove everything apart from branches from there (the lower box).
To do a merge, go back to the Changes panel - Working Copy info pane where the config branches link was and just under it is "Merge from..." - click that and the little drop down branch menu appears, click "trunk" (in this case) and you get the "Select Merge Variant" dialog, with "Quick Manual Select" button, should be obvious from there (?)
The other two options (merge all, only any use when merging an experimental branch back into trunk, but i've never used it, looked too scary!) and Select with pre-filter, which takes ages and ages on tiki, probably due to our extensive history (and svn being a bit rubbish at this).
Hope that helps, odd that it's not on their documentation (afaics)
P.S. Compare with branch instructions are here https://www.jetbrains.com/phpstorm/help/comparing-with-branch.html
- As of PhpStorm 2017.2, "Merge from..." is now in the "Subversion Working Copies Information" tab of the Version Control tool window.
- "Quick Manual Select" requires you to check the revision you want to merge, not just to select it.
When there are conflicts, the "Apply All non-conflicting changes" button needs to be used to reduce the list of changes to apply to those which conflict.
If you get this error, it probably means that the permissions on your Tiki files are wrong. Typicall, when you run setup.sh, all the files in Tiki end up being owned by _www with _www as the group (unless you specify other choices). But on most platforms (at least on Mac), PhpStorm runs as your own regular user, which is not part of group _www.
Here is how to fix this issue on Mac. Details for other platforms may vary.
# First, add your user name to group _www sudo dseditgroup -o edit -a yourusername -t user _www # Next, rerun setup.sh, but this time, specify # yourusername as the user, but leave _www as # the group sudo sh setup.sh # Then make sure certain directories are writeable # by the _www group. sudo chmod -R g+w db dump img/wiki img/wiki_up img/trackers modules/cache templates_c templates styles whelp
When attempting to run project '9.x' on 'LocalApache' server, I see these messages:
Cannot find PHPUnit in include path (.:/usr/share/php:/usr/share/pear)
Unable to attach test reporter to test framework or test framework quit unexpectedly
Once phpunit is installed (& phpstorm restarted), the error message dissapears.
When attempting to go to "Run > Debug '9.x on LocalApache'", I see this message at the bottom:
Error running 9.x on LocalApache:
Debug server doesn't exist. Check 'Remote' tab in run configuration editor.
Ok, after I added "localhost" as Debug Server, and run again "Run > Debug '9.x on LocalApache'", I did get these messages:
Testing started at 18:35 ...
Http request failed: HTTP/1.0 500 Internal Server ErrorE_WARNING: require_once(Zend/Cache/Backend/ExtendedInterface.php): failed to open stream: No such file or directory
- 0 /var/www/9.x/lib/core/Zend/Cache/Backend/Test.php(27): require_once()
- 1 /usr/share/php/PHPUnit/Util/Fileloader.php(95): include_once()
- 2 /usr/share/php/PHPUnit/Util/Fileloader.php(79): load()
- 3 /var/www/9.x/_intellij_phpunit_launcher.php(527): checkAndLoad()
- 4 /var/www/9.x/_intellij_phpunit_launcher.php(821): collectTestsFromFile()
- 5 /var/www/9.x/_intellij_phpunit_launcher.php(929): main()
E_COMPILE_ERROR: require_once(): Failed opening required 'Zend/Cache/Backend/ExtendedInterface.php' (include_path='.:/usr/share/php:/usr/share/pear')
- 0 /var/www/9.x/lib/core/Zend/Cache/Backend/Test.php(27)
Sometimes, nothing happens when you click on the Commit button.
When that happens, make sure you uncheckall the boxes in the Subversion and before commit section have to be unchecked.
You typically get this error when running the debugger PHP Script run configuration.
The error usually means that the PHP interpreter you are using does not have the xdebug extension installed.
To find out which interpreter you are using
- Preferences > PHP
- Click on ... to the right of the Interpreter field
- The path of the interpreter is in the PHP Home field.
To see if xdebug is installed for that interpreter:
pathtoyourinterpreter/php -i | grep xdebug
If the phpinfo doesn't contain any line with xdebug, it means it's not installed.
To install xdebug for use with PhpStorm, see the Configuring the Debugger section above.
If you notice that PhpStorm occasionally gets in a rut and becomes very slow in responding to your actions, it probably means that you haven't allocated enough heap memory to it.
The way to fix it is to add or change the heap size setting. From the main menu, choose Help | Edit Custom VM Options to create a copy of the
idea.vmoptions file in the user home directory. See PhpStorm's help page for more information.
For example, here is Alain's idea.vmoptions file:
-Xms128m -Xmx2048m -XX:MaxPermSize=350m -XX:ReservedCodeCacheSize=96m -XX:+UseCodeCacheFlushing -XX:+UseCompressedOops
Although the graphical svn UI in PhpStorm is pretty good, there may be time when you want to use the command line SVN.
If you do that, it could be that the command line SVN will complain that the current directory is in the wrong SVN format.
This is usually due to the fact that PhpStorm uses its own version of SVN (which is embedded as a java library), and that it uses a SVN data format that is more recent that the command line SVN you are using. For example, maybe your command line SVN uses the 1.6 format, while the PhpStorm svn uses 1.7.
There are two ways to deal with this
- Upgrade your command line SVN so it can deal with the data format version used by PhpStorm.
- Redo the checkout, but ask PhpStorm to store the data in the format that your command line uses.
As of this writing (Oct 29, 2013), the easiest option for Mac users seems to be to redo the checkout, because macport doesn't seem to have version 1.7 of the command line SVN (which is what PhpStorm uses by default).
Free video tutorial to help you setting (xdebug) and customising PhpStorm: https://laracasts.com/series/how-to-be-awesome-in-phpstorm/