Praj's Blog

PHP database can’t connect to localhost but 127.0.0.1 works

There are many reasons for this, so first check that MySQL/MariaDB is running properly, that you are using the correct credentials and that the the appropriate user@localhost has access.

Also check you aren’t using skip-name-resolve and bind-address in your my.cnf file if accessing from outside of the localhost. These are things you will find with a google search.

Apart from this one other reason why 127.0.0.1 will work and localhost will not work is if you are using something other than the default socket=/var/lib/mysql/mysql.sock location in your my.cnf.

If that is the case, you’ll need to update the relevant default_socket= parameter in php.ini (for each driver) to match that socket – see the entries under my.cnf [mysql] and [mysqld] sections for the socket parameter. This is more likely to occur if you are using MariaDB for example.

$_SESSION global is empty

If you find that your global $_SESSION variable is empty there can be several reasons, here are a few:

  • The session.save_path is invalid (does not exist) or is not writable.
  • The session.cookie_secure is set to true but you not using a secure site (SSL/https).
  • The session.cookie_domain is set to a domain that does not match your site – very common if setting up a dev or test environment from a production site with a public domain.

Fixing Mac Book Pro – No Internal Speakers

This happens on occassion on the Mac Book Pro – You lose the internal speakers and are only left with digital out. A sign this has occurred is that the red light in the headphone port (where you plug in your headphones) will be on.

There are numerous ways to try to fix this, anything from system preference tweaks all the way to opening up your Mac Book.

Here’s the simplest thing you can try (and it does seem to work with a bit of persistence):

  1. Open System Preferences > Sound
  2. Plug in your headphones as you won’t have control over the volume/mute of the digital output
  3. Once headphones shows up on the list, move the volume slider up and down and check/uncheck the mute button.
  4. Unplug your headphones
  5. Check if digital out has disppeared and been replaced by Internal Speakers.
  6. Rinse and repeat. Note it can take several attempts before this works. For example, after 3 times, I finally had internal speakers appear for a second then disappear back to digital out. On the fifth attempt, internal speakers appeared again and this time stayed. Basically what you are doing is trying to get the Macbook to recheck its sensors and correctly revert to internal speakers.

Good luck.

Moodle Unexpected Output while processing AJAX request

I had this one come up when expanding the Site Administration menu:

Coding error detected, it must be fixed by a programmer:  
Unexpected output whilst processing AJAX request.  

This could be caused by trailing whitespace. Output received: ' '

What causes it is there is a new function in later versions of Moodle in lib/ajax/ajaxlib.php called “ajax_check_captured_output”. This is a useful check for developers, and therefore when the site is in DEVELOPER debug mode it throws an exception. You can change the debug mode to something less than DEVELOPER and you shouldn’t get an exception (but note that there is still an underlying problem).

One catch is that if the site administration navigation is failing, you can’t actually get to Site administration > Development > Debugging. Easy work around, visit http://your-moodle.com/admin/settings.php?section=debugging and adjust your debugging settings there.

Mahara Class ‘HTMLPurifier_Config’ not found

This error relates to a call to the clean_html function in lib/web.php which loads HTMLPurifier. Turns out that due to a bad .gitignore file where all files with the name config.php were being ignored, the file:

lib/htmlpurifier/HTMLPurifier/Config.php

Wasn’t in the install and caused this error. Fixing up the .gitignore file to only ignore the root level config.php (/config.php/) resolved the issue and allowed the missing config.php file to be deployed on the target install.

Alfresco could not resolve view error

In Alfresco Share (share.log), I kept getting this error and couldn’t figure out what was causing it:

ERROR [org.alfresco.web.site] javax.servlet.ServletException: Could not resolve view with name 'user/guest/dashboard' in servlet with name 'Spring Surf Dispatcher Servlet'

After a lot of fruitless google searching and trial and error, I finally tracked it down to items missing share-config-custom.xml, so if you get something similar, review your share-config-custom.xml in detail.