Table of Contents
If you want to send us your comments, please do so. Thanks
More on comments
Debugging PHP
Useful links
Debugging in PHP
About debugging in PHP
A Detailed Guide to PHP Debugging
howto debug PHP code
Warning: PHP does a syntax check before executing the code. If the syntax check fails the program can terminate without any (error)message
^M
The program looks like
#! /usr/bin/php <?php The code ?>
When you run it you get an error:
/usr/bin/php^M: bad interpreter: No such file or directory
This can be solved by opening the program in a text editor like Geany and then
- CTRL-A
- CTRL-C
- CTRL-N
- CTRL-V
- CTRL-S and save the file under the same or a new name
Try again
Build in functions
Sometimes if you expect that a function is already build in into PHP, or that a function which is build in into PHP, can solve your issue. This in not always the case. You will need to write your own function / code in those cases to solve the issue.
Some functions
Functions to use for debugging when the script is ran from a webbrowser
Function | Explanation |
---|---|
echo | Output one or more strings |
nl2br | Inserts HTML line breaks before all newlines in a string |
echo nl2br (“\nThis text will be printed\n”); | Prints some text. Use a new line at the beginning and at the end of the text to make sure the text is on a separate line |
print_r ($somevariable); | Prints human-readable information about a variable |
var_dump ($somevariable); | Dumps information about a variable |
$resultvariable = is_bool ($somevariable); var_dump($resultvariable); | Check if a variable is a boolean |
$resultvariable = is_bool ($somevariable); echo nl2br ($resultvariable ? 'true' : 'false'); | Check if a variable is a boolean |
$resultvariable = is_int( $somevariable[0]); var_dump($resultvariable); | Check if element 0 of array somevariable is an integer |
echo nl2br (“Showing if somevariable is an array: ” . is_array($somevariable) . “ 1: it is an array, 0: no array\n”); | Check if a variable is an array |
echo nl2br (“Showing characterset: ” . mb_internal_encoding() . “\n”); | Get the internal character encoding |
Tools
Database management
- With phpMyAdmin a mySQL database can be managed
- Adminer is a replacement for phpMyAdmin in a single PHP file
Debugging
Firebug is deprecated. This is what followed Firebug
Install Xdebug
Do, logged in as root, in a termiknal
- Install with aptitude php-dev or for your specific version, an example: php7.0-dev
- pecl channel-update pecl.php.net
- mount -o remount,exec /tmp/ or whereever the temporary directory is located pecl uses
- If needed do mount -o remount,noexec /tmp/ to restore /tmp/ to its original state
- pecl install xdebug
Then you should get a lot of output from the compiler (make) which ends with something like
---------------------------------------------------------------------- Libraries have been installed in: /tmp/pear/temp/pear-build-rootiu8Wto/xdebug-2.9.0/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the 'LD_RUN_PATH' environment variable during linking - use the '-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to '/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'. running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0" install Installing shared extensions: /tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0/usr/lib/php/20151012/ +----------------------------------------------------------------------+ | | | INSTALLATION INSTRUCTIONS | | ========================= | | | | See https://xdebug.org/install.php#configure-php for instructions | | on how to enable Xdebug for PHP. | | | | Documentation is available online as well: | | - A list of all settings: https://xdebug.org/docs-settings.php | | - A list of all functions: https://xdebug.org/docs-functions.php | | - Profiling instructions: https://xdebug.org/docs-profiling2.php | | - Remote debugging: https://xdebug.org/docs-debugger.php | | | | | | NOTE: Please disregard the message | | You should add "extension=xdebug.so" to php.ini | | that is emitted by the PECL installer. This does not work for | | Xdebug. | | | +----------------------------------------------------------------------+ running: find "/tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0" | xargs ls -dils 137518 0 drwxr-xr-x 3 root root 60 dec 14 19:16 /tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0 139134 0 drwxr-xr-x 3 root root 60 dec 14 19:16 /tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0/usr 139135 0 drwxr-xr-x 3 root root 60 dec 14 19:16 /tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0/usr/lib 139475 0 drwxr-xr-x 3 root root 60 dec 14 19:16 /tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0/usr/lib/php 137962 0 drwxr-xr-x 2 root root 60 dec 14 19:16 /tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0/usr/lib/php/20151012 137966 1796 -rwxr-xr-x 1 root root 1835992 dec 14 19:16 /tmp/pear/temp/pear-build-rootiu8Wto/install-xdebug-2.9.0/usr/lib/php/20151012/xdebug.so Build process completed successfully Installing '/usr/lib/php/20151012/xdebug.so' Segmentation fault
- Something about the Segmentation fault warning
- Run make test
- This results in: “make: *** No rule to make target 'test'. Stop.” Are we missing something?
- Goto Configure PHP and follow the instructions
- vi /etc/php/7.0/apache2/php.ini
- Add to the end: zend_extension=“/usr/lib/php/20151012/xdebug.so” or where ever xdebug.so is located.
- You can use find / -type f -name xdebug.so 2> /dev/null to find it
- and also for vi /etc/php/7.0/cli/php.ini
- The end of php.ini should look like
; Added for Xdebug zend_extension="/usr/lib/php/20151012/xdebug.so" ; End:
- Restart the webserver.
- In case of Apache do: systemctl restart apache2 and / or systemctl restart apache2.service
- In case of Lighttpd do: systemctl restart lighttpd and / or systemctl restart lighttpd.service
- Run php -m and look for
[Zend Modules] Xdebug Zend OPcache
- Run /var/www/html/test.php or where ever the contents of your webserver is stored. This should be in test.php
- Do chmod 644 /var/www/html/test.php
<!DOCTYPE HTML> <html> <head> <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?> Hello, Here is "some" info about PHP on this computer <?php phpinfo(); $d = date("D"); if($d == "Fri" || $d == "Sat"){ echo "Have a nice weekend!"; } else { echo "It is not a weekend tomorrow. Have a nice day with a lot of fun!!!"; } ?> </body> </html>
- Ready
Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy
RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.