Thursday, April 12, 2012

Drupal site structure change couldn't be saved

We have a huge site structure in drupal 6. After we upgraded php 5.2.6 to 5.3.3, we got a fatal error when trying to access the site structure page:


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 82 bytes) in .....

So we have to put this line in %drupal_home%/sites/default/settings.php:

ini_set('memory_limit', '512M');

This increased the drupal memory limit from 128M bytes to 512M bytes. Now we can see the site structure page. However, when we tried to make some changes, the changes are not saved and no error on the web page. Then we found this warning in the apache error log:

[error] [client xxx.xxx.xxx.xxx] PHP Warning:  Unknown:
Input variables exceeded 1000. To increase the limit change max_input_vars in php.ini. in Unknown on line 0, referer: https://yoursite.com/menu-site-structure

So now we added this line to php.ini:

max_input_vars = 2000

This increased the max input variables from 1000 (default) to 2000, and this solved the problem.


Thursday, April 5, 2012

Debugging Drupal Source Code remotely in NetBeans

Configuring the Server:


1. Make sure PHP XDebug module is installed.
2. Add this section to your php.ini (i.e. /etc/php.ini).  NOTE: make sure you put IP address of the client machine (the debugging computer) for the "remote_host", not the the server IP!

; xdebug config
xdebug.remote_enable=on
xdebug.remote_host=%client IP address%
xdebug.remote_port=9000
xdebug.remote_log=/var/log/xdebug.log
xdebug.idekey=netbeans-xdebug

3. Restart Apache (i.e. $apachectl graceful).
4. Run php -info. And you should see something like this:

xdebug support => enabled
Version => 2.1.4
... 
DBGp - Common DeBuGger Protocol => $Revision: 1.145 $
...
xdebug.idekey => xxxxx => netbeans-xdebug
xdebug.remote_enable => On => On
xdebug.remote_handler => dbgp => dbgp
xdebug.remote_host => xxx.xxx.xx.xxx => xxx.xxx.xx.xxx
xdebug.remote_port => 9000 => 9000
...

Configuring the Client:

1. Make sure PHP plugin is installed for the NetBean.
2. Start NetBeans and create a new PHP project (File->New Project). Select PHP Application from Remote Server and click Next.
3. Give the project a name and local location and click Next.
4. Setup the Remote Connection as appropriate for your server and click Next. Click the "Manage" button the set the remote connection by putting in the username and password. If you use SSH to access the server, leave the password field blank but provide the private key file.
5. NetBeans will construct a list of files it will download. Click Finish to download the files.

Debugging Drupal Remotely:

1. Make sure you open the port for Netbeans if you use Windows 7 and Vista.
2. In Netbeans, set the drupal project as the main project, then go to "Debug Project".
3. Enjoy debugging.