How to Fix CURLOPT_FOLLOWLOCATION cannot be activated PHP Error in Kloxo Linux

Today I was running a PHP script which used CULROPT_FOLLOWLOCATION option and it threw an error saying:

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in ...

I had encountered this error previously as well, but it dint really matter to me as the script used to work just fine even after the error.

So I looked up this error and realized that I need to set up two things correctly:

  1. safe_mode
  2. open_basedir

Every single post available out there just talks about these settings in php.ini file, so I will begin with the same.

Open your php.ini file which will most probably be located in /etc folder

Make sure that following line is not commented in it:

safe_mode = Off

Also, if you are using Kloxo, there might be couple of occurrences of this line, so make sure both of them have safe mode turned off.

Next, confirm that open_basedir line is commented, it should be like:

;open_basedir =

Also, again make sure that there are no more occurrences of this line assigning values to open_basedir.

Once you have configured the above settings, restart your web server. If you are using apache, you can use the following command:

service httpd restart

Now create a test php file with following code:

<?php echo ini_get('open_basedir'); ?>

Run this file using web browser and check the output.

In my case, it gave an output like:

/home/admin:/home/admin/kloxoscript:/home/httpd/nimishprabhu.com:/home/httpd/nimishprabhu.com/httpdocs:/tmp:/usr/share/pear:/var/lib/php/session/:/home/kloxo/httpd/script

So I spent another 30min figuring out where exactly were these settings configured?!

Finally, I found the files in a directory which I had never looked into before.

Navigate to:

/home/apache/conf/domains

In this directory, you can see that for each of your domains, there exists a .conf file.

Open the corresponding configuration file, in my case it was nimishprabhu.com.conf file.

You can see couple of occurrences of following piece of code:

<Location />
 <IfModule sapi_apache2.c>
 php_admin_value open_basedir "/home/admin:/home/admin/kloxoscript:/home/httpd/nimishprabhu.com:/home/httpd/nimishprabhu.com/httpdocs:/tmp:/usr/share/pear:/var/lib/php/session/:/home/kloxo/httpd/script"
 </IfModule>
<IfModule mod_php5.c>
 php_admin_value open_basedir "/home/admin:/home/admin/kloxoscript:/home/httpd/nimishprabhu.com:/home/httpd/nimishprabhu.com/httpdocs:/tmp:/usr/share/pear:/var/lib/php/session/:/home/kloxo/httpd/script"
 </IfModule>
 </Location>

They can be found under:

  • <VirtualHost \IPAddress\>…</VirtualHost>
  • <IfModule mod_ssl.c>…</IfModule>

Comment the code between <Location />…</Location>

curl followlocation error fix

 

Restart your web server and run the test.php file again.

It should have a blank output this time.

Now run the script which uses CURLOPT_FOLLOWLOCATION, it should work flawless. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.