Posts

How to make WordPress display PHP errors

Your site is down just displaying “This site is experiencing technical difficulties” and you need to investigate what is causing the error. If you turn on PHP error reporting at your hosting provider, WordPress still just displays the generic message.

Turn on PHP error reporting at your hosting provider.

Edit the wp-config.php file and comment out the line define( ‘WP_DEBUG’, false );

// define( 'WP_DEBUG', false );

Then add the following lines and make sure they occur before the line /* That’s all, stop editing! Happy blogging. */

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
define( 'WP_DEBUG_DISPLAY', true );
@ini_set( 'display_errors', 1 );

When you are done, remember to revert the above changes.

WordPress shows white page after site move

WordPress just showing a white page means it is experienceing PHP errors. When it occurs after a site has been moved from one hosting to another it can be caused by several reasons.

To make it possible to track down the cause you can temporarily add the following to the .htaccess file in the root. If this gives you a internal server error 500 it means it is not allowed by the host. If allowed, you will get error messages from PHP dispayed on screen when accessing the site:

php_flag display_startup_errors on
php_flag display_errors on

There are visbible PHP ending tags ?> on the site

If you see more or less normal output from the site but once in a while you see lines ending with ?>. This can happen if the site has been running on PHP 5 where the short PHP start tag <? is allowed (instead of the longer <?php.

If the site has been moved to PHP 7 where this is not longer allowed, it can cause this kind of strange behaviour.

If you don’t want to go through all the code and find all the occurrences of <? and replace them with <?php (which is one solution), you can simply add the following to your php.ini:

short_open_tag=On

You need to restart Apache after this.

Wordfence plugin is installed

You need to manually edit the system specific paths in the following files:

  • .user.ini in the site root, change the path after auto_prepend_file
  • wordfence-waf.php in the site root, change the paths on all occurrences

WP Rocket plugin is installed

The file wp-content/advanced-cache.php contains system specific paths. You can manually update them or just simply delete the file and login to wp-admin of the site and it will be recreated automatically with the correct paths.

APS package installation_task stuck in ISPConfig3

When trying to install an APS package on a ISPConfig3 system, the package was never installed and the status “installation_task” remained for the site I tried to install a package.

Investigating /var/log/ispconfig/cron.log revealed:

PHP Fatal error: Uncaught Error: Call to undefined function curl_init() in /usr/local/ispconfig/server/lib/classes/aps_installer.inc.php:627

This problem can occur when curl is not installed on the target server, but that was not the problem in this case.

The server had been upgraded to Ubuntu 16.05 which runs PHP 7.0 instead of PHP 5. Curl was installed but the problem was that php7.0-curl was missing. The problem was resolved by:

sudo apt-get install php7.0-curl

The next issue that occured according to the logs was:

PHP Fatal error: Uncaught Error: Class 'ZipArchive' not found in /usr/local/ispconfig/server/lib/classes/aps_installer.inc.php:106

This problem was resolved by:

sudo apt-get install php7.0-zip

After this nothing more had to be done. The ISPConfig cron now successfully installed the APS package automatically.

Joomla! Component skeleton or framework

I was going to develop a Joomla! Component for a client and started to read the documentation on how to build a Joomla! Component. I searched online for a skeleton or framework so I didn’t have to program that from scratch. Googeling it didn’t show up any really good results.

Until I realized there are actually services for this. Component Creator is one of them. Through a web interface you can specify the details for your component and you can download a ZIP-file which is installable for Joomla! to start bulding upon.

However, documentation is something not really existing for Component Creator. Instead there are community forums and some video tutorials. I was searching the forums for a specific matter and it turned out that the same question had been asked several times by other users. The reply from the Component Creator staff was that you will get the answer to that question by buying the Premium service. So instead of documenting an answer to a common question they want each client to contact the support team to get the answer, probably in order to sell more Premium subscriptions. A bit odd to me. The free service is so limited anyway so without the Premium subscription you quickly run into it’s limitations, so they will sell them anyway.

You should also be aware that Jensen Technologies who is behind Component Creator also is a consulting business offering development of Joomla! components. So your supplier will also be kind of your competitor. I am not saying they will go and steal your business or clients but it is not always a healthy thing when your supplier is also your competitor. Their in house developers will naturally always have the best support compared to their clients.  If it was me, I would have split it into two different companies.

Anyway, the Component Creator is a powerful and helpful tool when starting a new component project for Joomla!.

The video tutorials can be found here:

There is also a webinar recorded on Youtube here:

Below is a demonstration of building a component in 30 minutes using Component Creator by Søren Beck Jensen (2015).

Ispconfig3 php5-fpm Error 500 Internal server error

When trying to change a client website on a Ispconfig3 host from Fast-CGI to PHP-FPM the page just gave Error 500 Internal server error. Investigating the site error log showed lines like:

[Sat Oct 22 10:39:56 2016] [error] [client xx.xx.xx.xx] (2)No such file or directory: FastCGI: failed to connect to server "/var/www/clients/client6/web447/cgi-bin/php5-fcgi-*-80-domain.xx": connect() failed
[Sat Oct 22 10:39:56 2016] [error] [client xx.xx.xx.xx] FastCGI: incomplete headers (0 bytes) received from server "/var/www/clients/client6/web447/cgi-bin/php5-fcgi-*-80-domain.xx"

Checking the status of PHP-FPM by the command:

service php5-fpm status

gave the result “not running”.

Investigating the PHP-log file, /var/log/php5-fpm.log, displayed lines like:

[22-Oct-2016 10:34:53] ERROR: [pool web405] cannot get uid for user 'web405'
[22-Oct-2016 10:34:53] ERROR: FPM initialization failed

However, the site widh id 405 and user web405 did no longer exist on the server and has been left there by Ispconfig3 for unknown reasons.

The solution was to manually remove the file /etc/php5/fpm/pool.d/web405.conf file and then:

service php5-fpm restart
service apache2 restart

Joomla 1.5 PHP fatal error allowed memory size exhausted in libraries/joomla/error/exception.php [SOLUTION]

After a site move (from one webhosting to another) the site reported error 500 internal server error. When checking the logfile the file libraries/joomla/error/exception.php reported that allowed memor size was exhausted. I tried increasing it by adjusting the php.ini settings all the way up to 2 GB without resolving the problem. This is way more than Joomla should need.

The problem was that I had forgot to update the temp and log paths in Global settings to the ones on the new server. The path the site is running under can be found by the menu Help -> System info. Then I adjusted temp path and log path in Global settings and the problem was resolved.

If your site gives you error 500 internal server error, access your Joomla database using for example phpMyAdmin and delete all rows in the jos_session table.

Another solution if the problem is a corrupted database is to repair the database tables using phpMyAdmin.

In configuration.php, also try setting cache_handler=”file” instead of “memcache”.

PHP Parse error: syntax error, unexpected end of file in XXXXX.php

  • Check that you have spaces around curly braces, i.e. for example don’t use <?php}?> but instead use <?php } ?>
  • If your script has been running without problems on earlier versions of PHP but you are now running PHP 5.4 or later, replace all occurrences of <? with <?php

Joomla! 1.5 menu items not visible

I was moving a Joomla! 1.5 site to a new hosting server. The site had been running on PHP 5.2 on the prevoius server but on the new host only PHP 5.6 or later was available. Joomla! was version 1.5.14.

After installing the site on the new server, no menu items were visible, not in backend, nor in frontend. I checked the database tables and the menu items were present in the database, they just didn’t show up in Joomla!.

The solution was simply to upgrade Joomla! to the latest verion, 1.5.26, which is compatible with PHP 5.6 (something that I would have done anyway as the next step).

Joomla! 1.5 upates can be downloaded here.

Check if a file is open by another process in PHP (Linux/UNIX)

The PHP flock() function is good when the file locking method is used the same way by all programs that will lock the file.

However, you can’t check if any process in the system is actually using the file or not. If you for example are monitoring an incoming ftp folder, you don’t want to start processing a file until the file is completely tranferred (i.e. wait until the ftp daemon is no longer having the file open).

The following code illustrates how the command lsof can be used for the purpose: 

<?php
$filename = "locktest.txt";
$directory = ".";
while (1) {
        $result = exec("lsof +D $directory | grep -c -i $filename");
        if ($result == "0") {
                echo "$directory/$filename is NOT open ($result)\n";
        } else {
                echo "$directory/$filename IS OPEN ($result)\n";
        }
        sleep(1);
};
?>

 

/tmp problem when installing plugins in WordPress

When you try to install a plugin in WordPress and get an error message like this:

Warning: file_exists() [function.file-exists]: open_basedir restriction in effect. File(/tmp//google-integration-toolkit.tmp) is not within the allowed path(s): (/var/www/XXX/) in/var/www/XXX/web/wp-includes/functions.php on line 2140

Warning: touch() [function.touch]: SAFE MODE Restriction in effect. The script whose uid is 12345 is not allowed to access /tmp owned by uid 0 in /var/www/XXX/web/wp-admin/includes/file.php on line 184

Download failed. Could not create Temporary file.

This is happening when the server is running with SAFE MODE because WordPress will not be able to access paths outside it’s web root. Find out the full path to your web root on the server (a hint is in the error message you just saw). Create a temporary directory within your website path and add the following line.

Edit wp-config.php and add:

define(‘WP_TEMP_DIR’, ‘/var/www/XXX/tmp’);

(Replace /var/www/XXX/tmp with the full path to your temporary directory.)