How to debug using WAMP? - php

I just installed WAMP on Windows XP. I have a simple PHP file that is crashing. I ran it from command line using php test.php.
What is the best way to debug php files? How do I display debugging info?
I looked at php.ini and it includes display_errors = On. Does this do anything?
I tried turning on XDebug from the PHP WAMP menu. This doesn't seem to do anything, besides restarting the server. Do I need to use this? How?
Thanks.

You can look at the log at c:/wamp/logs/php_error.log. If you are not sure whether your PHP log is being redirected here, check your php.ini file and search for a line like this:
;error_log = "c:/wamp/logs/php_error.log"
You may want to remove the comment on this line.

As much as i know about PHP and WAMP.I don't think there is any special debugging option available in this.for the debugging you need to print the answer using echo and exit function wherever in your code you feel the error may posible. The other option is, you need to use software which provide debugging facility such as eclipse with php.

I am using WAMPSERVER 2.4 on Windows 8 pro. I was using WAMP on localhost.
It appears that in my version of WAMP, the php.ini file had appeared as:
;error_log = "Z:/wamp/logs/php_error.log"
When in actuality,for me get the function error_log() to work properly, I wanted it to appear as :
error_log = "Z:/wamp/logs/php_error.log"

Related

Blank pages after installing PHP on IIS

I am attempting to install PHP onto Windows Server 2008 R2. I have followed the instructions here but when I try to load phpinfo.php I get a blank page.
There are no errors in the Event Viewer.
The server is used to host multiple other Asp.Net websites but I am using PHP so that I can install MediaWiki.
UPDATE:
When trying to load simple HTML (with no PHP) it also loads as blank. The fix for this seems to be to enable "Static Content" in the "Turn Windows features On/Off" manager - but this is already in place.
This happened to me as well just running the handy dandy php installer microsoft has on their site using their Web Platform Installer and it turned out in the php.ini file by default short_open_tag by default is off so my code
<?
print("hello world!");
?>
would not work because it was expecting
<?php
print("hello world!");
?>
.... so yea ... just go and change that if this is your problem too!
If copying over an old Wordpress installation from an old server - make sure you copy ALL the files. Oops... <embarassed>
A blank page is also possible when there is an PHP error and error reporting is of. Try to run the script below to see what happens.
<html>
<body>
Hello HTML
<?php
error_reporting(E_ALL);
echo "Hello PHP";
?>
</body>
</html>
You could also try to see if a normal HTML page with PHP extentions runs fine. Perhaps your server is setup to disallow PHP extention.
You have to configure fastCGI for each PHP website, more details you can find here - Best Practices for Configuring FastCGI and PHP
So I found the solution after hours of randomly trying things. I removed and re-added the Static Content role in Windows - still same result. Then I edited the Error Pages feature of the website in IIS to say return Detailed Error Messages. At this point PHP started to complain about the timezone so I set to "Europe\London" - for this to take effect you need to restart IIS.
After that it worked, phpinfo now loads!
I had this issue; at "turn Windows features on or off", I enabled:
HTTP Errors
Server-Side Includes
Directory Browsing
Windows Authentication
I also set these options in C:\Program Files (x86)\PHP\v5.3\php.ini:
display_errors = On
display_startup_errors = On
After that, a 401 Unauthorized error was displayed. I added 'Everyone' and 'Users' groups to the folder to fix.

xdebug on OS X partially working (e.g., prints stack trace in terminal but not browser).

I'm trying to get xdebug working on my Mac. I'm using OS 10.6 with the built-in versions of Apache (2.2.1) and PHP (5.3.8). I followed the "tailored installation instructions" on the xdebug website, which basically consisted of these steps:
Build xdebug (version 2.1.3) from source
Move xdebug.so to /usr/lib/php/extensions/no-debug-non-zts-20090626
Add to php.ini:
zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
Restart the webserver.
From what I understand, that should be it. I know most people use xdebug with an IDE like PHPEclipse, but it doesn't sound like that's necessary just to get debugging output on the page. And a lot of old instructions involve installing MAMP, but it looks like that's no longer necessary.
Signs xdebug is working: When I run php -m and phpinfo() I get the expected information on xdebug. In scripts I'm able to call functions like xdebug_is_enabled() (returns 1) and xdebug_get_function_stack() (returns the stack).
Ways xdebug is not working: The main reason I installed xdebug was to get a stack trace when there's an error, and that's not happening. According to this documentation page, I should get a stack trace as long as display_errors is set to On in php.ini, (which it is). I've tried code that should evoke a warning (e.g., echo(hello)) as well as code that produces a fatal error (e.g., $x->awesomefunction() when $x isn't an object). Neither one produces any xdebug output, and the fatal error just causes the page to die silently. The test code given in the documentation I linked to also produces nothing.
UPDATE: It turns out that if I run a script with a fatal error from the terminal, I do get a stack trace from xdebug. However, it's still not showing up when I run the script from a browser
Also, regular error reporting is now broken: Previously, I'd get error output by including the commands:
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);
Now, putting those lines in my script doesn't produce any error reporting either. (in the browser. It does cause errors to be shown when I run the script from the terminal.)
So, what's wrong here? Did I leave something out of the xcode installation? Do I have a setting hanging around somewhere else on my system, suppressing errors? I've tried everything I can think of, but I'd be happy to test any ideas you have.
If it is working on console and not on browser, it's probably a xdebug configuration issue.
I'm not a Mac user, but on Ubuntu there are 2 different php.ini files, one for console and one for apache. If that's the case for Mac also, you can check if xdebug is enabled and properly set up in both php.ini files.
Also you can check the xdebug settings mentioned in the guide.
After several more hours of thrashing, I discovered that one of my test files actually was including another file that set display_errors to 0. The other test file was straight off of the xdebug site, but I think that at the time I was using it I'd introduced some other config error that prevented it from working properly. I'm truly embarrassed! Let this be today's object lesson in the importance of systematic, repeatable tests during debugging. On the bright side, xdebug is now working like a peach.
To summarize, the series of steps that worked was:
Build xdebug (version 2.1.3) from source
Move xdebug.so to /usr/lib/php/extensions/no-debug-non-zts-20090626
Add to php.ini: zend_extension = /usr/lib/php/extensions/no-debug-non-zts-20090626/xdebug.so
Add to php.ini: display_errors = On
Restart the webserver.

Is there an Easy out of the box solution to debug PHP?

I am writing a php web application and I get stuck because my script doesn't work how I would expect. Then I check the logs and I get nothing. My php.ini file is set to display all errors and log all errors. But I am not getting anything. On my mac, how can I debug PHP so I can step through the code and see what the problem is?
If you use apache then look into apache logs.

Can't get XDebug to make a connection in Vim. Getting "no attribue 'stop'" error

Judging by how many search engine hits this error message generates, I know this is a common problem, yet there aren't any helpful answers out there.
I'm trying to setup XDebug in Vim using Sam Ghods Debugger.vim script while following the instructions on How to Debug PHP with Vim and XDebug on Linux (which is a commonly referenced source on getting Vim setup with XDebug). I'm running MacVim 7.3 on OSX 10.6 and when I try to connect the debugger to the server, I get:
(<type 'exceptions.AttributeError'>, AttributeError("DbgProtocol instance has no attribute 'stop'",), <traceback object at 0x104595680>)
File "/Users/tjlahr/.vim/plugin/debugger.py", line 1078, in debugger_run
debugger.run()
File "/Users/tjlahr/.vim/plugin/debugger.py", line 928, in run
self.protocol.accept()
File "/Users/tjlahr/.vim/plugin/debugger.py", line 560, in accept
self.stop()
Does anybody have experience troubleshooting this error?
Please note that I'm not debugging over port 9000 because it seems it might conflict with fastcgi enabled in PHP. So I'm debugging over port 9001 and have changed by settings in php.ini and the g:debuggerPort variable respectively.
Thanks for your help.
I think I got it!
Can you try installing this Vim Plugin:
http://www.vim.org/scripts/script.php?script_id=2508
It seems that "AttributeError("DbgProtocol instance has no attribute 'stop'",)" is a general error.
I just installed XDebug and the debugger.vim plugin and ended up receiving this message. My problem was that remote debugging was not enabled. Build a phpinfo file:
<?php
phpinfo();
?>
somewhere in your web server directory, and check over all your xdebug configuration variables, which should be listed near the bottom of the page. On my system with xdebug-v2.2.0-dev built from the GitHub repo, xdebug.remote_enable was set to false. Pasting that at the bottom of your php.ini file and setting it's value to 1 enabled clients to connect to the xdebug session.
Also, in the xdebug source there is a directory called "debugclient", which can be used to test any connection problems. Follow the instructions in the INSTALL file in it's directory to build it.
And, one last thought, after you run the plugin script in VIM, you need to refresh the webpage you are trying to debug within 5 seconds, or else the script, acting as a client, will timeout.

wamp cannot load mysqli extension

WAMP installed fine, no problems, BUT...
When going to phpMyAdmin, I get the error from phpMyAdmin as follows:
Cannot load mysqli extension. Please check your PHP configuration
Also, phpMyAdmin documentation explains this error message as follows:
To connect to a MySQL server, PHP needs a set of MySQL functions
called "MySQL extension". This extension may be part of the PHP
distribution (compiled-in), otherwise it needs to be loaded
dynamically. Its name is probably mysql.so or php_mysql.dll.
phpMyAdmin tried to load the extension but failed. Usually, the
problem is solved by installing a software package called "PHP-MySQL"
or something similar.
Finally, the apache_error.log file has the following PHP warnings (see the mySQL warning):
PHP Warning: Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
PHP Warning: Zend Platform does not support this version of PHP - please upgrade to the latest version of Zend Platform in Unknown on line 0
PHP Warning: Zend Debug Server does not support this version of PHP - please upgrade to the latest version of Zend Debug Server in Unknown on line 0
PHP Warning: gd wrapper does not support this version of PHP - please upgrade to the latest version of gd wrapper in Unknown on line 0
PHP Warning: java wrapper does not support this version of PHP - please upgrade to the latest version of java wrapper in Unknown on line 0
PHP Warning: mysql wrapper does not support this version of PHP - please upgrade to the latest version of mysql wrapper in Unknown on line 0
So, for some reason PHP is not recognizing the mysql extension.
Anyone know why? Any solution or workaround?
I deleted the PHP in program files ad everything started working , the problem that there two installations of pHp
I tried many solutions, and none worked for me. I tried the following solutions:
Restart wampserver
Reinstall wampserver
restart machine
and all other solutions mentioned in this question.
However, none of these worked. Then I found that my PHPMyAdmin was not working in chrome and was working in firefox. So I tried clearing cache, restarting browser etc, but still it would not work.
Then I deleted all the files from C:\wamp\tmp and then tried again, and it works. I am not sure why it works, but here is what I think. The session was cached and not getting cleared. So as soon as I deleted all files in this directory all the sessions were deleted and hence it worked fine.
First, make sure that the php.ini file is loading the mysqli extension.
If you are using WAMPServer, click on the icon in the system tray, go to PHP -> PHP Extensions and make sure it is checked. If not, go into the php.ini file and make sure that the line: extension=php_mysqli.dll is uncommented (eg, remove the ; if it exists). If that line does not exist, add it.
If this still does not work, double check that the right php.ini file is being loaded.
To do so, view your phpinfo() (Here for WAMPServer). Scroll down to the Loaded Configuration File row and see which php.ini is being loaded.Make sure it is the right file. If you're using WAMPServer, it should be(WAMP INSTALL FOLDER)\bin\apache\Apache2.2.11\bin\php.ini. By default, it isC:\wamp\bin\apache\Apache2.2.11\bin\php.ini`.
If a different php.ini file is being loaded, just rename it to something else so that PHP will try and find the file somewhere else. There should be a way to specify which on eyou want to use, but I forget exactly how to do that...
If this still doesn't work... Try messing around with phpMyAdmin's settings, or using another answer, but I'm afraid I can't help beyond this.
I was running WAMP with two PHP versions 1) 5.2.9 and 2) 5.2.13.
As per site requirement i needed to change PHP version to 5.2.9 from 5.2.13. after swapping PHP version, error was "mysqli extension is missing". after debugging long time i get to know it was due to wrong "extension_dir" path in php.ini file.
So i changed its value:
Old: "extension_dir" c:/wamp/bin/php/php5.2.13/ext/
New: "extension_dir" c:/wamp/bin/php/php5.2.9/ext/
Restarted All services in wamp server, then it's fixed.
I had the same problem. I had WAMP server installed. All was working fine. Then one day I restarted my computer and it just stopped working! I tried desperately going through all help posts and doing them but nothing worked.
What they usually suggest you do is, first go to your php.ini file and make sure your 'extension_dir' is properly set. Then to make sure these two lines are not commented (remove the ; infront):
extension=php_mysql.dll
extension=php_mysqli.dll
Then some suggested that I download fresh copies of these two files but none worked. I also tried uninstalling everything (php/mysql/apache) and reinstalled fresh copies of WAMP server several times but with no luck.
Finally I managed to find an alternative solution. I switched to 'easyphp' (http://www.easyphp.org/). This is something very similar to WAMP. First I made backups of my sql databases so I can reload them on the new installation.
Then I installed 'easyphp' and everything seems to work fine. I reloaded my sql databases from my backup and now things are back to normal.
I hope someone suffering from a similar prob. will find this useful. If someone has really found a fix to make WAMP server work. Pls do be kind enough to post it here so many will benefit.
in wampserver go to php.ini. open the file and uncomment extension=msql.dll by removing semicolon(;) for respective operating sytem.
Just add in your php.ini:
[PHP_MCRYPT]
extension=php_mcrypt.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
Also setup the mysql password:
SET PASSWORD FOR root#localhost=PASSWORD('your_password');
And the phpmyadmin mysql password in config.inc.php:
$cfg['Servers'][$i]['password'] = 'your_password';
Had the same problem, with wamp. Try to exchange your current version of php.ini with a backup. There is one in: wamp\bin\php\php5.3.0phpForApache.txt. Worked for me.
Just wanted to chime in on this one. Using Wamp Server 2.0, and using Zend Studio with Zend debugger for development.
I wasn't able as of yet (will get back to it at some point) to get the zend debugger working with php 5.3. So in wamp I loaded an earlier php version, 5.2.11. I was getting the same error when acessing php my admin.
What I had to do was change the php.ini file value for "extension_dir" to c:/wamp/bin/php/php5.2.11/ext/ to match the version of php I was using. After that it was all good.
I had this problem and spent 2 hours trying all the solutions online, none worked.
Tried this, and it woked:
Change
mysql.default_host =
to
mysql.default_host = localhost
and restart WAMP. pay attention if you are using mysqli or not.
I had the same error. When I increased the script memory size and enabled E_ALL then restarted the server, I got that error in phpmyadmin. All I had to do to fix it was restart my computer!
I got this problem for a long time. Tried all I've read on forums and this finally worked for me:
Open your php.ini (I assume you've got the good one that is loaded...) and find this line
mysqli.default_port = 3306
change for
mysqli.default_port = 80
Restart all services
Go to localhost/phpmyadmin -> won't work
Reopen the php.ini file and retype this
mysqli.default_port = 3306
Restart all services
Worked for me.
For me worked this, after searching all logs/internet/every non-normal things.
You have to register dl by:
Through application:
WAMP -> PHP settings -> enable dl
or
# php.ini #
; Whether or not to enable the dl() function. The dl() function does NOT work
; properly in multithreaded servers, such as IIS or Zeus, and is automatically
; disabled on them.
; http://php.net/enable-dl
enable_dl = On
I have just installed WampServer, and faced same problem. I have found solution, that works for me, it is ridiculously simple.
Disable PHP extension php_mysqli.
Restart WampServer, visit local phpmyadmin.
Enable php_mysqli back.
Repeat step 2.
After few page refreshes, remaining errors plates (about MySQL and sqli) had gone.
i tried hard by
installing the wamp again and again,
by checking the php.ini file,
by restarting the machine,
by replacing the index.php file,
but none works.
then i go to the wamp/temp and deleted all files and it works fine now.
I had path variable in windows set to some random version of php.
The fix was to update it and set it to the folder within my wampserver installation:
C:\wamp64\bin\php\php5.6.38
Then I realized this is wrong also for my specific case, and I should actually be running the script from within vagrant. Live and learn.
I had this issue because of a different reason:
Check the PHP Error Log(Get from the Wamp Tray -> PHP -> PHP Error Log.
I had a syntax error in the php.ini file while I was editing the file.
Check the log and clear the error. This will open your PhpMyAdmin properly.
Check your phpForApache.ini file's extensions. This file should be same as your php.ini file.

Categories