Tuesday, July 9, 2013

How to solve CURL problem "Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in"

The problem is exactly what is says in the error message - you have safe_mode or open_basedir enabled in php.ini. Either edit php.ini to disable whichever one of those you have on, or don't use PHP's flavor of curl. If you can't edit php.ini you'll have to ask your web hosting company to do it or change your webhosting company (suggestion : hostandwork.com).

Set safe_mode = Off in your php.ini file (it's usually in /etc/ on the server). If that's already off, then look around for the open_basedir stuff in the php.ini file, and change it accordingly.

Basically, the follow location option has been disabled as a security measure, but PHP's built-in security features are usually more annoying than secure. In fact, safe_mode is deprecated in PHP 5.3.

Using SSH Console solution:
Simply, as long as either open_basedir or safe_mode is enabled in the php.ini file, the CURLOPT_FOLLOWLOCATION configuration cannot be used. To change those settings, I can only give general notes:

  1. SSH to the server
  2. cd to the directory (usually /etc/php5 on linux, depends on your distribution or OS) that contains php.ini
  3. sudo to edit (eg, sudo nano php.ini).
  4. edit the lines that specify open_basedir or safe_mode and either turn them off.
  5. Remember to restart your httpd afterwards!
Disqus Comments