PhpStorm Xdebug go to the wrong line - php

I'm using Xdebug/PhpStorm for a long time and never saw this problem:
PhpStorm 2019.1.3
Docker 18.09.2
image mattrayner/lamp:latest-1804
Ubuntu 16.04.6
PHP v7.3.3-1+ubuntu16.04.1+deb.sury.org+1
When I run debugger in PhpStorm, the debugger breaks on the correct line but when I step through the code, it jumps to random places in the code, and the browser receive empty response, with no errors in the log.
More info:
I have a similar setup on the same machine with image mattrayner/lamp:latest-1604 - in this setup the problem does not reproduce
If I set "stop at first line" I can step through the code on the first, but subsequent run will not step though the code
, difference: PHP Version 5.5.9-1ubuntu4.27, Ubuntu 14.04.6
when the debugger breaks, any operation will fail - e.g. clicking on run will finish the execution but the browser display empty response and no action executed after the break.
Content of /etc/php/7.3/apache2/conf.d/20-xdebug.ini
zend_extension=xdebug.so
xdebug.remote_enable=1
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_port=9000
xdebug.remote_connect_back=0
xdebug.remote_host=host.docker.internal
Any idea how to solve it?
Tried with different version (7.2, 7.3 , 7.4) - same results:
here is my path mapping
and my Apache conf
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName dev.usaddress.com
CustomLog /var/log/apache2/access.log vhost_combined
SSLEngine on
SSLCertificateFile /app/dev.usaddress.com.crt
SSLCertificateKeyFile /app/dev.usaddress.com.key
DocumentRoot /app/usaddress
<Directory /app/usaddress>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

You should check your path mapping. That's usually a case for me. It can be mapped correctly in the place where your script firstly enter but can be mapped wrong in some other place. Make sure that you mapped only the root of your project or that you have correct mapping at all possible routes.
Server setting can be found at Languages & Frameworks > PHP > Servers
If you will look on my screenshot you can see that only folder public is mapped with absolute path on the server (which is /srv/sylius/public here). That means that other folders will be mapped relatively to this public folder.
If you think that it's not a case than I can advise you only to try manually go through code starting from that place where debugger breaks on the correct line step by step until unexpected behavior occurs. And from that point try to understand why it happening.

close your project
go to the project directory
delete .idea folder
create a new project with the project directory
go to 'Edit configuration' and recreate your debug configurations
run debuger
Notes:
I was not able to reproduce this bug with a similar env
I was not able to reproduce this bug with a different project running on the same env
therefore, I tried to recreate the project and it solved the problem

For me this issue was due to a watch expression that was causing an error during evaluation when the first breakpoint was hit. Removing the offending watch resolved it.

Related

Show Errors instead of Internal Server Error

When my code have error (even syntax errors) browser show 500 - Internal Server Error,
In .env I set the APP_DEBUG to true and APP_LOG_LEVEL is debug
How can I enable error messages?
UPDATE:
I use Laravel 5.3
UPDATE 2:
I use Apache and defined VirtualHost to access this app :
<VirtualHost *:80>
ServerAdmin myemail#domain.com
DocumentRoot "/Dev/Web/site/public"
ServerName site.local
ServerAlias www.site.local
ErrorLog "/private/var/log/apache2/site.local-error_log"
CustomLog "/private/var/log/apache2/site.local-access_log" common
<Directory "/Dev/Web/site/public/">
Require all granted
AllowOverride All
</Directory>
</VirtualHost>
UPDATE 3:
My /etc/hosts records:
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost gat.local www.gat.local site.local www.site.local shop.local www.shop.local
Short answer you can't. Why?
Simply because 500 - Internal Server Error is exactly what it says Internal Server Error, it has nothing to do with Laravel. Server software (Apache in your case) causes error 500. Most likely permissions problem. (server software can not read / write to certain files etc.)
From Laravel documentation:
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run.
You have to check Apache logs
Default on OSX machine /private/var/log/apache2
You want to see more errors? Follow up this SO thread.
Neat trick, make sure to have one entry per project in your hosts file.
#127.0.0.1 project1.dev www.project1.dev
#127.0.0.1 project2.dev www.project2.dev
.
.
.
Why? You can just comment out / delete line, searchable, easier to read.
#MajAfy You can use barryvdh/laravel-debugbar. This will give you in depth knowledge of every error. What query you are running and lot more.
Here is the link https://github.com/barryvdh/laravel-debugbar .
Its easy to install due to its well documentation.
After many tries, I found problem,
Everything return to file permissions,
I changed the permission of laravel.log in storage/logs to 777 and everything work fine !

Laravel5 only shows default page in linux ... the same works in windows

Maybe I miss something small , but I really get lost in here.
I made a virtual host to tun laravel:
I've created file in etc/apache2/site-available:
<VirtualHost *:80>
ServerName laravel5.local
DocumentRoot "/var/www/ProjectFiles/NewProjects/laravel/public"
<Directory "/var/www/ProjectFiles/NewProjects/laravel/public">
AllowOverride All
</Directory>
</VirtualHost>
And in site-enabled this is enabled
In etc/hosts I've:
127.0.0.1 laravel5.local
So:
"laravel5.local" shows laravel5 default page.
"laravel5.local/index.php" shows the same.
The problem is that I've changed this page (welcome blade)
And if I try this :
"localhost/ProjectFiles/NewProjects/Laravel/public/"
I see the change I've made
Please note that if I do :
php artisan serve
and try on "localhost:8000" I still do not see that change, so the problem
should not be in a mistake made in the virtualhost.
And the strangest thing is that all this works perfect in Windows.
Thanks in advance
P.S. and php artisan route:clear do not help
In your VirtualHost section you wrote /laravel/ with lower case L in the text with localhost you wrote it with upper case L. Make sure you have the right upper/lower case in Linux.
Windows doesn't care about it but Linux does!

W7, apache, php: 403 Forbidden You don't have permission to access /phptest/phpinfo.php

There are lots of questions on this but I still cannot get it to work.
I am installing Apache 2.4 and PHP 5.4.37 on a W7 Pro PC. PHP is running as a load module. If installed respectively in c:\apache24 and c:\php, with the document root as default at c:\apache24\htdocs, it all works fine.
However, I then decided I wanted the document root at f:\webroot (local drive), making necessary changes to document root in httpd.conf. webroot has all the same permissions as c:\apache24\htdocs, but I get the error message in the title.
A normal index.html file in webroot is served OK, it is just any PHP file that isn't.
I noted that the Apache service is started with user LocalSystem. So I tried various others. I even tried running Apache from the command line (instead of as a service) logged in as Administrator, which should have had access to anything, and it made no difference - same message.
Don't understand what is going on. I can go back to the default document root, but at some point will need to access folders elsewhere on the system, so I will be back with the same problem, I guess.
Further info:
Tried various combinations of the commands in <directory "f:/webroot"> to no effect, BUT have found that if in <directory /> I set 'Require all granted' instead of 'Require all denied', it works. However, not sure (a) if that is wise (it probably isn't) and (b) why it is needed anyway. Any suggestions about what I should set it to?
Solved this:
Not only do you have to set Document root and the matching <DIRECTORY ...> section entry in httpd.conf, but also DocumentRoot in the <VirtualHost _default_:80> section of the ...\conf\extras\httpd-vhosts.conf file.
Setting 'Require all granted' in <DIRECTORY /> was a mistake.

Running PHP file outside of documentroot (cgi-bin folder)

I am working with a colleague to set up their local environment on a MAC in XAMPP, on windows my vhost looks like the one below.
When I access a URL like http://domain.local/cgi-bin/handler.php the web server processes the PHP correctly but on his we get a 500 server error and this message...
The server encountered an internal error and was unable to complete your request.
Error message:
Premature end of script headers:
We tried changing the name of the cgi-bin folder to something else as I noticed there was another alias in httpd.conf but this had no effect...so it seems to me like the issue is permissions related.
We believe the alias is setup ok as accessing http://domain.local/cgi-bin/filenothere.php which doesn't exist throws a 404 as expected, any .html/.pl files fail to execute.
The permissions that exist on the cgi-bin folder are...
rwxrwxrwx dave staff
and is owned by the user and group....
dave staff
Vhost
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName www.domain.local
ServerAlias domain.local
ServerAlias api.domain.local
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot E:/home/www/www.domain.co.uk/htdocs/
# CGI Directory
ScriptAlias /cgi-bin/ E:/home/www/www.domain.co.uk/cgi-bin/
<Location /cgi-bin>
Options +ExecCGI
</Location>
# Logfiles
ErrorLog E:/home/www/www.domain.co.uk/logs/error.log
CustomLog E:/home/www/www.domain.co.uk/logs/access.log combined
</VirtualHost>
Any idea what is causing this PHP file to not be executed?
UPDATE
Tried adding a header to say that the content is PHP to the start of the PHP file and this now simply outputs the PHP code.
It's as if any path specified in as an Alias is accessible but the server doesn't know how to execute the content, this is for HTML as well as PHP
I think you need a section for your cgi-bin.
The fact that your server can show you the script sources means the server has at least read permissions on /file/system/path/to/cgi-bin and IIRC that clashes with ScriptAlias b/c ScriptAlias expects /file/system/path/to/cgi-bin to be unaccessible for security reasons. I think your solution should look something along the lines of:
<Directory /file/system/path/to/cgi-bin>
Options ExecCGI
SetHandler cgi-script
</Directory
There is (very) rarely a need to run PHP scripts as CGIs given that the PHP module for Apache can execute them directly. Try adding this to your Apache config:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Afterwards simply place the PHP scripts into the document root for the site and see if they work. You'll want to remove the /cgi-bin/ part of the URL.
You say you're setting XAMMP on a Mac, but you have a drive letter (E:) prefixing your paths. OS X does not have drive letters like Windows, and this may also be causing (part of) your issue.
I don't know much about settings used. But I think you should go through following links. Might get some help.
http://www.sean-barton.co.uk/2009/02/setting-up-a-phpmysql-local-development-environment-on-a-mac-doing-it-properly/
http://docs.joomlabamboo.com/using-joomla/setting-up-a-quick-start-package-on-your-local-server-xampp-pc
http://www.adobe.com/devnet/dreamweaver/articles/setup_php.html
How to create Mac OS X dev environment for legacy PHP app?
Assuming that PHP is running in Safe Mode you may need to "open" your cgi-bin directory, as the execution of user (PHP) scripts is limited to the DocumentRoot and it's subfolders.
For all I know you could do that in two ways
1. Edit your php.ini
Locate the line containing open_basedir. If there's a comment at the beginning of the line - a semicolon - remove it. Then add your cgi-bin directory.
open_basedir = "E:\home\www\www.domain.co.uk\cgi-bin\"
If you need to open more than one directories you can use semicolon ; as a separator. On Linux based server, use a colon :
open_basedir = "E:\home\www\www.domain.co.uk\cgi-bin\;E:\home\www\www.domain.co.uk\another_dir\"
In cases like mine, where your server is hosted by third party, you'd need the second option (well sort of)
2. Edit your VirtualHost
Add the following to your VirtualHost, i.e. after DocumentRoot:
php_admin_value open_basedir "E:\home\www\www.domain.co.uk\cgi-bin\"
Same rules apply here for multiple directories and difference between Linux and Windows systems as above.
Hope that helps
Do you know whether PHP is running as a CGI program or as a webserver module? You should be able to find this out if you can get a phpinfo() page working (maybe from a regular folder inside the website root). If you're running as a webserver module then you should have a section near the top with a heading of Server API which says Apache 2.0 Handler (or equivalent).
From these pages:
https://bugs.php.net/bug.php?id=13316
http://php.net/manual/en/install.unix.commandline.php
http://gallery.menalto.com/node/8955
... it seems that it may be either due to PHP running as a CGI script, or else a conflict between PHP and another CGI handler.
One of the posters on the third linked page found that their similar-sounding end of script headers issue was resolved by removing / commenting out the Options +ExecCGI line in their .htconfig / vhosts file.
Might be worth having a read through the above links to see if your problem is related.

Netbeans and Zend-Framework

I have just started using the Zend-Framework. On advice of a friend I use NetBeans for PHP development with Zend. I have installed NetBeans and referenced the Zend-Framework under Tools>Options>PHP>Zend, registered it since I am using a version newer then 1.10.
Under PHP>General I have inluded the Zend-library path as a Global-Include-Path.
Since I've read that the beginners tutorial provided on the website (http://framework.zend.com/manual/en/learning.quickstart.create-project.html) has some errors and since it does not use NetBeans I started with this video tutorial: http://netbeans.org/kb/docs/php/zend-framework-screencast.html
Creating the project as a Zend-Framework Project worked just fine, all default folders and files are created. However, when I run the project with this defauilt setup the browser should diplay the index.php provided by the Framework under localhost/quickstart, instead of that it just displays a listing of the files of directories:
Index of /quickstart
Parent Directory
.zfproject.xml
application/
docs/
library/
nbproject/
public/
tests/
I suppose there is something wrong with the configuration of the apache server but the video screencast did not mention any needed configuration when using netbeans.
I am using xampp and one of the things that might be the problem is the httpd.conf file as described in the tutorial (http://framework.zend.com/manual/en/learning.quickstart.create-project.html) since no NameVirtualHost-propperty is defined there and no VirtualHost configured. However I didn't want to change the httpd.conf without knowing if that is the problem.
Also adding a line "127.0.0.1 quickstart.local" to the hosts file turned out to be impossible under Windows 7, so in case this is actually neccesary, I would apreciate any help.
Thanks,
Lukas
Have you set the DocumentRoot in the apache httpd-vhost.conf to the public folder?
All you should need to do is add public to the end of your current document root...
Also to change the vhosts file in windows 7 you need to find notepad in the start menu -> all programs -> accessories
Right click and run as Administrator
File -> open -> C:\Windows\System32\drivers\etc\hosts
Now add your records and save.
Opening as Administrator allows the save to attually save the changes.
Ironically, I just went through all of this yesterday. First, what happens when you type: localhost/quickstart/public, into your browser instead of: localhost/quickstart ? The controller is accessed via the index action and .htaccess file inside that directory.
Second, in regards to editing the hosts file... I have windows 7 as well, and all i did to find it was type "system32" in the Search Programs and files, then follow the path to the hosts file. I was able to edit it using notepad and it worked great!
there are two steps to configuring the vhost after that. You will need to uncomment a line in the httpd.conf file under the apache folder, remove the # from httpd.conf:
#Include conf/extra/httpd-vhosts.conf
Then go to the extras folder and add the following to the bottom of your httpd-vhosts.conf file like so:
<VirtualHost *:80>
ServerAdmin webmaster#dummy-host.localhost
DocumentRoot "C:/path_to_local_webroot/quickstart.com/public"
ServerName quickstart.com
ServerAlias quickstart.com
ErrorLog "logs/quickstart.com-error.log"
CustomLog "logs/quickstart.com-access.log" common
</VirtualHost>
For your hosts file, just add one line to the bottom:
127.0.0.1 quickstart.com
Then restart your server and you should be good to go.

Categories