For being able to run your tests via your IDE open your Settings window and navigate to Languages & Frameworks PHP Test Frameworks. Click on the +icon on the right side and select PHPUnit Local. Specify the Path to phpunit.pharand select the phpunitfile within your.phpunitdirectory. IDE configuration. After following the current Testing documentation it’s mandatory to manually run./bin/phpunit once in your terminal. Symfony will install its own instance of PHPUnit within your bin directory which will provide the executable phpunit file for our IDE. PhpStorm provides coding assistance and navigation facilities for developing applications with the Symfony framework. Symfony support is provided by means of the Symfony Plugin. The source code for the plugin, as well as its issue tracker, can be found on GitHub. Symfony builds on both the installation itself and other extensions. Therefore, you also need to download and install it or leave it all on PhpStorm, which also has built-in resources for working with this tool. The choice is yours again Creating a new project.
Published on 2020-06-21 • Modified on 2020-10-18
In this post, we will see how to do step by step debugging with Xdebug, Symfony and PHPStorm. We will do a basic example where we will stop the execution of the Symfony code just before rendering a template to check the data passed to it. Let's go! 😎
» Published in 'A week of Symfony 704' (22-28 June 2020).
Prerequisite
I will assume you have a basic knowledge of PHP, Symfony and that you know how to modify your PHP configuration thanks to the php.ini
file.
Introduction
Why this blog post? Well, because of this tweet:
PHP developers that don't use Xdebug for debugging are amateurs.
— Derick Rethans 🔶 (@derickr) June 20, 2020This is the kind of tweet I don't like, a typical troll, trying to make a generality of something more complex. It brings negativity as It can be interpreted by people not using Xdebug by:
“If you don't use Xdebug, you aren't a real developer.” 😔
Even it's not what Derick meant to say, it's what people may understand. There is no smiley. We don't know if the tweet is pure sarcasm or not. I wanted to answer at first. But what about transforming something negative to something positive and useful? 😀 That's why I decided to write this blog post. 🙂
Configuration
I use the following configuration, but it should be OK with previous versions of each of these components. Here, I use the Symfony binary to serve my application. If you use another type of setup (Apache, Docker..), you'll probably have to make small adjustments to the following instructions.
- PHP 7.4
- Symfony 5.2
- Xdebug 2.9.6
- PHPStorm 2020.3
Installation
I will assume you have a working PHP/Symfony installation. So first let's install Xdebug, it can be done with PECL:
If not done, activate the Xdebug extension in your php.ini
file. You can find this file by running:
Verify that in this file, the xdebug.so
(or .dll
) library is loaded. You must see a line like the following (it can also be loaded in an external file like conf.d/ext-xdebug.ini
):
If everything is OK, you should now see Xdebug when getting the PHP version:
Or when grepping the module list:
The debug bar also shows if Xdebug is available when you pass over the Symfony version number with your mouse:
Now that Xdebug is activated let's see how to configure it for PHPStorm.
Configuring Xdebug and PHPStorm
Xdebug
First, we must enable the remote option of Xdebug. Add the following parameter in your PHP configuration as we did previously:
We keep the other default parameters to keep the configuration as minimal as possible. So, with this setup, the port used by Xdebug is 9000
and the default IP address is 127.0.0.1
. Check out the xdebug.remote_host
and xdebug.remote_port
parameters in the documentation.
PHPStorm
Now, let's check the configuration inside PHPStorm. Open the menu entry: Run > Web Server Debug Validation. You should see this window:
In the first parameter put the full path of your project public directory where is stored the Symfony front controller (generally public/index.php
with Symfony 5). In the second parameter, put the local URL of your project. Then click on validate. If everything is OK, you should see ✅ like above. You can ignore the error of the last line, it seems to be a known problem, but it won't prevent the debugger from working. The final step is to tell PHPStorm to start listening to Xdebug connections. It must be done with the Run > Start Listening for PHP Debug connections menu entry.
Step by step debugging
Now that PHPStorm has validated our setup let's try to add our first breakpoint. Open one of your controllers and click between the line number and the start of the code editor panel of the line you want to stop the execution. A red disc 🔴 appears like this (at line 33 in this example):
Now, open your browser and access a page that calls the action where we put the breakpoint. If it works, PHPStorm gets back as the active window of your OS, and you get the following output:
As you can see, the code window is different from what we use to have. First, after the controller method declaration line, we have the values of the parameters received by the action. $_locale
is 'en', $goals
is an array with two keys, and lastly, $articleRepository
is the Doctrine repository of the Article
entity. Just below, we see that the line of the breakpoint is highlighted; this is to show that the code has stopped here like expected. Just before this line, after the declaration of the $data
(at the right), we see the value of this new variable. It is empty as we just declared it.
Just below, in the debug panel, we have a Variables section where we can inspect all the local variables available at the breakpoint.
This panel is very convenient; we can see all the variables (even the globals) and expand them to check their content. We also find the function parameters ($_locale, $goals, $articleRepository
). As this controller extends the Symfony AbstractController
, we can notice that it has access to the dependency injection container ($this->container
).
Now let's try to advance to the next 'step', to go to the next line. We can use the 'Step over' button (F6 with my setup).
As you can see the highlighted line has changed, it's now line n°34. We can see the value of the $date
variable just above. This new $date
variable is now part of the 'Variables' panel. We can continue like this until the end of the action to check that the $data
array contains the correct keys and values and can be passed to the Twig template. To continue the execution of the script, click on the 'Resume program' button ⏯️ (F8).
If you don't need the breakpoint for now but want to keep it for later, you can right-click on it and deselect the 'Enabled' option. The red disc appears now as a circle. Refresh the page, and you will notice that the script doesn't stop anymore.
The browser extension
We can also install a browser extension (available for Firefox, Chrome, Safari, Opera) to disable/enable the debug on the fly. When disabled, nothing is caught by PHPStorm even there are still some active breakpoints. It is faster than deactivating the breakpoint manually or altogether disable Xdebug in the PHP configuration. It looks like this:
Conclusion
Et voilà! We have a practical step by step debugging workflow using Xdebug! What about telling Derick that we are now professionals PHP developers? 😁
About the original tweet, I really liked the answer of Jordi; this is precisely what I think:
I can see a debugger being valuable when code is very complex or unknown, and often use it in JS. In PHP code though I usually am familiar enough with what libs I use and find no benefit to debugging interactively. Like most things, it depends. No need to call people amateurs IMO
— Jordi Boggiano (@seldaek) June 20, 2020If you don't drink Guinness you are an amateur
— Gary Hockin (@GeeH) June 20, 2020PHP developers who don’t use @doctrineproject are amateurs.
— Jonathan H. Wage (@jwage) June 20, 2020Developers that don't use a computer to develop are amateurs
— Gregoire Pineau (@lyrixx) June 21, 2020PHP developers that don't write there own frameworks are amateurs
— Simon Bennett (@MrSimonBennett) June 20, 2020PHP developers that write bugs and need to debug are amateurs. https://t.co/NG5YtmdD3k
— Liam Hammett (@LiamHammett) June 20, 2020That's it! I hope you like it. Check out the links below to have additional information related to the post. As always, feedback, likes and retweets are welcome. (see the box below) See you! COil. 😊
They gave feedback and helped me to fix errors and typos in this article, many thanks to jmsche. 👍
Did you like this post? You can help me back in several ways: (use the Tweet on the right to comment or to contact me )
- Report any error/typo.
- Report something that could be improved.
- Like and retweet!
- Follow me on Twitter
- Subscribe to the RSS feed.
- Click on the More on Stackoverflow buttons to make me win 'Announcer' badges 🏅.
Phpstorm Written In
Thank you for reading! And see you soon on Strangebuzz! 😉
[🇬🇧] New blog post, this is my answer to the tweet: 'PHP developers that don't use #Xdebug for debugging are amateurs.' https://t.co/SPd8UIOrQ8 Proofreading, comments, likes and retweets are welcome! 😉Annual goal: 4/6 (66%) #php#strangebuzz#blog#blogging#debug#bug#blogging
— COil #StaySafe 🏡 #OnEstLaTech ✊ (@C0il) June 23, 2020Introducing CW: a cache watcher for Symfony
Adding a custom data collector in the Symfony debug bar
Note:- This blog is updated on 13-11-2020.
All set to get your hands unclean with PHP development tools? PHP IDE is the primary tool that you require to get on the go with PHP programming. There are a lot of IDEs accessible in the market, both free and paid, and picking one can be a tricky job.
It is utterly possible to get going ahead with PHP programming tools in a fundamental text editor, like notepad, but healthier is to commence off with a feature rich and absolute PHP IDE such as NetBeans. The set of tools like PHPStorm, VIM, Cloud9, Zend Studio, and Atom are, particularly for professional web development.
The best PHP IDE comes filled with multiple features and functionalities with using PHP programming support. The integrated development environment is a developer’s open space and to improve it you need to invest efforts and time upfront to choose the PHP web development tools that most excellently fits your project requirements.
Which one you must go for? This query is for you and the choice depends on what you necessitate, like, and can have the required funds. It is not an awful idea to try some prior to closing on one of them. Let us give you a few statistics concerning PHP which will stimulate you the most. As per a survey carried out by Inc, PHP is a 7th well-liked programming language across the world and as per GoCertify, it is the 5th most extensively utilized programming language in all over India.
There is a lot of PHP editors available that are maintained on Windows, Linux, and Mac and are obtainable for free download. If you are a learner web developer, setting up to learn PHP, my advice is to go in advance with freely on hand PHP coding software like NetBeans, VIM, Atom or Eclipse PDT.
Install Phpstorm
Enterprises developers can also get the job done with these free IDEs. However, there are commercial and business-related IDEs accessible. They are more superior and are backed by enterprises, supporting the newest set of functionalities as well as advanced features. The best IDEs in 2021 for PHP Programming comprise of PHPStorm, Zend Studio, Sublime Text, Nusphere, PHP Designer, PHPED and Cloud 9, to name some.
PHPStorm
PHPStorm is the best IDE for PHP developer and comes packed with the freshest set of features that facilitate swift web development. It is developed and promoted by a company named JetBrains. It is in the midst of the most accepted companies in developer tools market and is making PHP coding software simpler and pleasant for developers for preceding 15 to 16 years.
PHPStorm works well with key frameworks like Symfony, Zend Framework, Yii, CakePHP and Laravel. It even supports chief Content Management Systems (CMS) such as Drupal, Magento, and WordPress.
Any web development project is not absolute without front-end technologies and that is where PHPStorm works the best. It enables live editing of front-end technologies including CSS, Sass, HTML5, CoffeeScript, TypeScript, JavaScript, Stylus, Less and others. It enables code refactoring, debugging and unit testing.
When it comes to best tools for PHP developers, it provides access and integration with sturdy version control systems, different databases, PHP MySQL development tool, vagrant, composer, remote deployment, rest client and command line tools. From debugging viewpoint, it works with Zend Debugger and Xdebug, both remotely and locally.
PHPStorm is an enterprise grade IDE, which comes with a license price and largely targets specialized developers. It, on the other hand, is offered, free of cost to students, teachers and to enable open source projects.
The reputation of PHPStorm can be gauged from the reality that big brands like Yahoo, Expedia, Cisco, Wikipedia, and Salesforce have bought PHPStorm IDE licenses.
Eclipse PDT
Eclipse PDT is a highly used Open Source PHP Development Tools is another open source preference without directly costing you. Eclipse has a massive community of developers working on all sorts of plugins, requisite to authorize Eclipse with features that any other best PHP IDE such as Storms PHP, NetBeans, and Zend studio has to provide.
It is a slightly tricky task in the commencement to get underway with Eclipse as contrasted to other business-related IDEs but its use is worth the money it saves for you. It saves on licenses which are the biggest gain if you ask for an evaluation amid Eclipse PDT and PHPStorm or Zend Studio. If you are an old-time Eclipse follower, you will feel easy to deal with Eclipse PDT.
Some people say that Eclipse is sluggish and let me be frank; it is time-consuming when you deal with system configuration while other business-related products relatively perform superior. However, the fundamental laptop configuration these days it is of high-quality to run Eclipse swift enough to not let you perceive any lags.
Some of the essential features comprise syntax highlighting, code formatting, code assist, refactoring, code navigation, code templates, PHP debugging, syntax validation and eclipse ecosystem that possess a vast community which is quite supportive.
To start off with, you can download Eclipse package for PHP developers which comes fully to a capacity of PHP language support, Git client, XML Editor, and Mylyn.
NetBeans
NetBeans is the PHP IDE for plenty; it is attributed rich, free and enables manifold languages, counting English, Russian, Japanese, Brazilian, Portuguese, and basic Chinese. The free version of NetBeans dates back to 2010 when it was originally prepared open source by Sun Microsystems, getting hold by Oracle afterward.
Ever since its release, NetBeans boosts one of the largest communities of developers operational on an open source integrated development environment being downloaded 18+ million times. Spss 26 download for mac.
Gone are the days when this tool was sluggish and was known only for development in Java, the existing stable release of NetBeans is lightweight, much quicker and supports the whole thing in PHP. It has the best support resources for all the rage PHP frameworks like Zend, Smarty Doctrine, and Symfony2. It even supports Laravel through Laravel-ide-helper and enables support for frameworks such as Yii, FuelPHP, CakePHP and WordPress CMS.
Some of the essential features that keep NetBeans on a peak of the list comprise code generation tools like getter setter generation, smart code completion, code templates, quick fixes, hints and refactoring. Other fundamental features supported include try/catch code completion, code folding, and formatting as well as rectangular selection.
When it comes to debugging, you can moreover use a command line or xDebug together locally and remotely. NetBeans PHP Editor supports web development taking into account JavaScript, HTML, and CSS. All these features simply make NetBeans as the paramount open source PHP IDE.
which PHP IDE comes with SSH support and which PHP IDE has Git support? Yes, NetBeans, you guessed it right.
Sublime Text 3
It is an accepted and a competing tool for the most sturdy text PHP editors. It is lightweight with required feature and is supported on OSX, Windows as well as Linux. The Sublime text editor is put up to gain its powers through different plugins and packages.
There are a lot of PHP packages accessible out there in the market that assists in transforming this smart editor into a graceful Sublime PHP IDE. Some of the most helpful and noteworthy packages for this purpose consist of package control, xDebug client – CodeBug, Sublime PHP companion, Simple PHPUnit, PHPCS, CodIntel, and PHPDoc.
Once you group sublime text 3 as a PHP IDE with aid of add-on packages, you get classiness of sublime text as well as the sturdiness of PHP at one place, for an utter easiness of PHP development.
NuSphere
It is another company that is keen on developing best tools of PHP products to step up web development experience and PHPED is the IDE they have to propose.
It supports the most recent release of PHP Editor that supports PHP 7 and many other new as well as old PHP frameworks which includes Laravel, Yii and Symfony to include few along with the Content management systems (CMSs) like WordPress and Joomla. The added feature with the most up-to-date release is the capability to run unit tests for mutually local and remote projects.
In summing up, NuSphere PHPED IDE is a packed stack web development tool that comes full with support for JavaScript debugging, CSS pre-processing with LESS pre-processor, HTML5 and rest of everything in PHP.
Having supposed that, I would rate Zend and PHPStorm superior to NuSphere in terms of style, the end to end customer support, enhanced documentation and release execution in the required commercial space.
Zend Studio
Zend Studio is amongst the top commercial PHP IDE from the development house of the organization named Zend and targets proficient web developers.
Zend as a company provides all the things covering PHP functionalities and has a huge number of clientele utilizing one or other of its products that assists PHP development with a supreme breeze. Some of its top clients incorporate companies like DHL, BNP Paribas Credit Suisse, and Agilent Technologies.
Zend Studio is enabled on Windows, OS X, and Linux and works with most recent PHP versions counting PHP 7. Zend Studio comes with an instinctive user interface and offers most of the up to date features and tools that lend a hand to speed up PHP and web development with multiple purposes. Some of the essential features of Zend Studio comprise
- Swifter performance in indexing, validation and searching PHP code
- Debugging with Xdebug, Zend Debugger, and integration with Z-Ray
- Hold up the Eclipse plugins ecosystem, Docker and Git Flow support
- Sharp code editor which supports PHP, JavaScript, CSS, and HTML
- Deployment sustenance which included cloud support for Amazon AWS and Microsoft Azure
- Backing for PHP 7 express migration and flawless integration with Zend server
A powerful feature of Zend is its support for mobile application development on the peak of live PHP apps and server system backend. This offers a good initiation in development when it comes to harmonizing present websites and web applications with mobile-based apps.
Atom
Atom is an up to date text editor built by GitHub folks and accessible free of cost underneath MIT license. Atom has an ecosystem of its own with the vast community at the back of it and tons of plugins and packages on hand to expand its functionality.
Atom is truly flexible which means you can turn Atom into your required PHP online editor since it is scalable and extremely customizable. In addition, it is an accurate cross-platform alternative with support for Windows, Red Hat Linux, OS X, Debian Linux and Fedora 22+.
How to twirl Atom into PHP IDE Free?
When it comes to PHP, there are numerous packages presented that convert Atom editor into an entirely loaded IDE for PHP which is not only free of cost but very effective than many other commercial PHP IDEs.
The packages you call for to turn atom editor into a totally functional free PHP IDE comprise php-cs-fixer, hyperclick-php, php-integrator-base, linter-php and atom-autocomplete-php.
Komodo
It is Developed by ActiveState in the year 2000, Komodo IDE is one of the best PHP MySQL development and functional tools. Most of the functionality of Komodo is innate from the Python interpreter.
It utilizes Mozilla and Scintilla as its foundation for the reason that they share much functionality, features and support the alike languages. Due to its numerous extensions and pipe feature, Komodo has turned to be an enormous success.
Features:-
- Provision of Split View and Multi-Window
- Swift Bookmarking
- Smart Language Detection
- Document Object Model Viewer
- Sustain for Git and Remote File Access
Aptana Studio
The Aptana Studio built by Aptana Inc. in the year 2014 is one of the finest open source PHP development tool. It is simple to download from the web and accessible to all at free of cost. It is obtainable as a standalone on Windows, Mac and Linux OS.
Features:-
- Comes with Syntax Error Annotations
- Has built-in PHP Server
- Supports DOM and CSS
- Code Formatting and Auto Indexing
- Supports PHP Debugger
Cloud 9
Cloud9 comes pre-packaged with necessary tools for all the rage programming languages, together with JavaScript, Python, and PHP, so you don’t require installing files for your development machine to commence new projects. In view of the fact that your Cloud9 IDE is cloud-based, you can execute your projects from your home or office or anywhere utilizing an internet-connected machine.
The platform offers a flawless experience for developing serverless applications empowering you to straightforwardly define resources, debug, and switch amid local and remote execution of serverless applications. With Cloud9, you can swiftly share your development environment with your team, facilitating you to pair program and monitor every other’s inputs on a real-time basis.
Features:-
- Code just with a browser
- Code mutually in real time
- Build serverless applications with effortlessness
- Initiate novel projects swiftly
- Direct using a terminal access to AWS
Codelobster
Codelobster IDE modernizes and simplifies the PHP development procedures. You don’t require keeping in mind the names of functions, arguments, tags, and attributes. The platform has enabled all these for you with auto complete functions intended for PHP, HTML, JavaScript, and CSS.
An internal free PHP Debugger facilitates you to validate the code on a local basis. It automatically detects your existing server settings and configures related files to let you utilize the debugger.
Codelobster IDE has the following features and capabilities to work with Magento:
- Higher capacity to build projects automatedly installing Magento platform
- Autocomplete for Magento methodologies
- Tooltips for Magento methodologies, Context, and Dynamic help
- Codelobster IDE backs Windows, Mac OS, Linux, WordPress, Ubuntu, Mint, Fedora, etc. and has exceptional plug-ins for working smoothly with Joomla, Drupal, Twig, JQuery, Symfony, CodeIgniter, Node.js, BackboneJS, EmberJS, CakePHP, VueJS, Laravel, AngularJS, Phalcon, Magento, and Yii.
So, Which PHP code editor can I choose? Let’s explore some more options.
Novi HTML Visual Editor
Novi HTML visual editor, the technical side of the HTML editor, was enormously user-oriented. In 2016, Elementor for WordPress was the only proficient drag & drop editor that offered WYSIWYG abilities. So, people required something such as that for HTML-based online projects.
Firstly, Novi facilitated non-technical professionals to design their websites without difficulty. Secondly, the builder turned useful to multiple web designers as well as developers. This visual HTML editor enabled all over the world to further the working process effortlessly.
The fundamental actions and features users were able to execute with Novi:
- Craft clean, structured site layouts with a code-free approach
- Enabled drag and drop technology
- Design pages of utilizing ready-made content modules
- Generate visitor-friendly web portal navigation
- Customize UI and UX elements
- Use of ready-made content blocks
- Set-up elements swiftly
- Handling media library
- Change color schemes, gradients, and images
- Enabling CSS, HTML, and JS code
- Facilitating contact forms, popups, and maps
- Applying visual effects, carousels, countdown timers, and sliders
So, which IDEs are the best for PHP development? Let’s explore some more alternatives.
Brackets
Brackets which is an advanced and modern text editor, makes it simple to design in the browser. With straightforward visual tools and pre-processor backing, it is quite tailor-made for web designers and front-end developers.
Here are some of the functionalities and features of Brackets
- Inline Editors
- Live Preview
- Pre-processor Support
Instead of jumping amid file tabs, Brackets enables you to open a window right into the code. Brackets facilitate you with all the CSS selectors with that ID in an inline window so you can implement code side-by-side without any popups’ involvement.
You can enable a real-time connection right to your browser. Make modifications to CSS and HTML, and you will instantaneously see those alterations on screen. Also, view where your CSS selector is being used in the browser by cleanly putting your cursor on it. It is the sturdiness of a code editor with the handiness of in-browser dev tools.
With Brackets, you can utilize Quick Edit as well as Live Highlight with LESS and SCSS files, which will turn working with them more straightforward than ever.
Dreamweaver
Adobe Dreamweaver is a leading and professional web development software package. It is a multi-faceted product fitting for everything right from straightforward page design to development of dynamic pages supported or written with PHP, ColdFusion, XML, XSLT, ASP, CSS, and JavaScript.
Some of the features of Dreamweaver
- Integrated CMS Support
- Smart Coding Assistance
- CSS Support
Dreamweaver enables to test most CMS’s, including Drupal, WordPress, and Joomla. This feature comes with live view navigation that facilitates viewing the webpage in action for simple editing. For implementing dynamic pages it helps you access all page associated files.
As beginners, you can benefit from the JavaScript, HTML, and Ajax code hints that Dreamweaver offers. The code hinting includes Spry, Prototype, jQuery, and PHP methods.
Dreamweaver enables us to showcase the CSS box model without requiring or knowing how to code CSS manually.
Notepad++
Notepad++ is an absolutely free source code editor and Notepad substitute that backs multiple languages. It runs in the MS Windows environment and is governed by GPL License.
The features of Notepad++ include
- Autosave
- Finding and replacing strings of text using expressions
- Enable Line bookmarking and Guided indentation
- Allows macros and simultaneous editing
- Facilitate split screen editing along with synchronized scrolling
- Helps with line operations, sorting, and case conversion
- Assists with the removal of redundant whitespace
- Lends a hand with tabbed document interface
Conclusion:-
PHP is the most well-liked and all-inclusive programming language for web development and there are loads of PHP IDEs obtainable which are further advancing with time. Most of the PHP development tools covered in this blog come with diverse flavors but the universal objective is bringing swiftness into web development with convenient and scalable code.
Phpstorm Download Mac
Take a closer look, list down some of your important requirements and choose the best PHP web development tools that most excellently fit your needs.
Download Phpstorm
If you have any question or planning to develop a PHP web application for your business then you can contact us. We have experienced team of PHP developers who are able to full fill your requirements.