I have a Virtual Server (1 CPU 1020 MB RAM), with Ubuntu 12.04.4 LTS and Apache2, PHP5.5, Mysql, and four web projects inside with a low number of users. It has worked like a charm last year. But suddenly, when I try to access any of those projects, I see this error on the browser:

Error establishing a connection to the database

I have solved it by restarting mysql:

service mysql restart

but the error comes again after a while. Checking log files I've found in /var/log/apache2/error.log:

[Tue Aug 05 09:04:45.607024 2014] [:error] [pid 8545] [client ipAddress] PHP Warning: curl_setopt_array(): CURLOPT_FOLLOWLOCATION cannot be activated when an open_basedir is set in /webDir/project/wp-content/themes/custom/js/aPhpFile.php on line 56, referer: webDomain

Looking at this code:

$op = array(
  CURLOPT_RETURNTRANSFER => true, // return web page
  CURLOPT_HEADER => false, // don't return headers
  CURLOPT_FOLLOWLOCATION => true, // follow redirects
  CURLOPT_ENCODING => "", // handle all encodings
  CURLOPT_USERAGENT => 'sharrre', // who am i
  CURLOPT_AUTOREFERER => true, // set referer on redirect
  CURLOPT_CONNECTTIMEOUT => 5, // timeout on connect
  CURLOPT_TIMEOUT => 10, // timeout on response
  CURLOPT_MAXREDIRS => 3, // stop after 10 redirects
$ch = curl_init();

$op[CURLOPT_URL] = $encUrl;  
curl_setopt_array($ch, $op);

and this link: http://us2.php.net/manual/en/function.curl-setopt.php#102121, I can see why this error is thrown.

I just disabled open_basedir (safe_mode is also disabled) and restarted the server.

Again I see this error which appears and disappears. But now there are no new errors in /var/log/apache2/error.log. Even I've tried:

//Show today logs
grep -r "Aug\s05" /var/log 

But the only messages are in /var/log/apache2/error.log.

Any idea of what can be happening and how to solve it?

  • When the error occurs, is it possible to connect to your MySQL-Server from your shell?
    – etagenklo
    Aug 5 '14 at 9:46
  • @etagenklo - Yes, it is possible by mysql -u root -p.
    – Manolo
    Aug 5 '14 at 9:51
  • Is it also possible with the credentials your script is using?
    – etagenklo
    Aug 5 '14 at 11:31
  • @etagenklo - The script is using root user.
    – Manolo
    Aug 5 '14 at 11:45

Ultimately, it is not a curl_setopt issue. It was just an error caused by a PHP configuration file (wordpress.stackexchange.com answer).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.