Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

How to setup VSCode launch.json for Xdebug version 2

I had to make some maintenance on a web application using Yii 1.1.4 framework running on PHP 7 and for that, I set up an Ububtu 18.04 LTS Desktop on a virtual machine. 

After the usual bunch of "apt-get install" commands and a few configurations, I got the new development environment up and running having Visual Studio Code as my IDE.

But, almost as soon as I got it running, I got the need to step debug it. For that, I went to Xdebug, I installed it via "apt-get" and configured it, but it was not working as expected.
I check the configuration parameters and give it another try. No go. Xdebug was installed, PHP was recognizing it on both cli and web, but it was still not working.
After a few seconds, I spotted the issue: it was a Xdebug version 2!

A lot has changed between version 2 and 3 of Xdebug.

The thing was that I wanted to keep version 2, and for that I had to configure "launch.json" file and Xdebug in the appropriate way.

On PHP configuration file:

zend_extension=xdebug.so
xdebug.idekey=XDEBUG_VC
xdebug.remote_port=9003
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
 
And on "launch.json":

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
       
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.remote_autostart=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.remote_autostart=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}

The default port is 9000, but I'm used to have Xdebug on 9003, so I reconfigured it. The remaining parameters are, basically, the version 2 way of activation the debugger on a request.

./M6

Could not close zip file php://output.

Ever got a "Could not close zip file" when using PHPExcel Writer? Usually the full error message is something like
[exception.PHPExcel_Writer_Exception] exception 'PHPExcel_Writer_Exception' 
with message 'Could not close zip file php://output.' 
in /var/www/vhosts/yourdomain/phpexcel/Classes/PHPExcel/Writer/Excel2007.php:399

This is caused because the PHPExcel requires access to the /tmp directory but the apache configuration is not allowing it.

The solution is easy and fast, just add the /tmp to your php_admin_value open_basedir parameter, as in this example:
php_admin_value open_basedir "[your current paths]:/tmp"

When using EHCP, it is recommended to update the Virtualhost configuration in all your templates (apachetemplate, apachetemplate_ipbased, apache_subdomain_template, apache_subdomain_template_ipbased) located in /var/www/new/ehcp:
php_admin_value open_basedir "{homedir}:/usr/share/php:/usr/share/pear:/tmp"

./M6

Debugging in PHP with XDebug

Debugging in PHP does not necessarily mean "print" or "log" debugging, even if one's using Lampp.

While checking out how to set up a good Joomla! 3 development environment, I've learned how to set up XDebug and configure it for PHP debugging.
Just check the correct XDebug version numbers and don't just "copy-paste" the settings.

./M6

Stripe, Payments for Developers

While developing in Django, sometimes one needs to access a payment system.
Django is a development framework and it does not have payment plugins like VirtueMart or Magento.

One possible and fast solution is to use Stripe.
It's focused to help developers to overcome the payment solution implementation, it has wrappers for Ruby, PHP, Python and more.

./M6

Learn Yii Framework

After evaluating some PHP frameworks, I've picked Yii because it seems to have the best ratio between cost/benefit. It's quite complete, easy to learn, performs fast and even has some similarities with Django, my favorite web framework.

Here's my Yii learning process:


If you'r new to Yii and are looking for a starting point, this one worked for me.

./M6

MetaMod Placeholder Position Display Management

When using Joomla! sometimes one requires to hide some information, like a specific menu, or an entire position.

MetaMod let’s you do this in a quite easy way.
One can follow their documented technique of moving stuff from an non-existing position into the real position, or one can use a simpler strategy that does not imply having virtual positions and nor moving stuff between these virtual positions and the real position: MetaMod Position Display Management.

./M6