Migrated database 'upload_path' - server crashes

This is my third trellis deployment, so I thought I’d seen most of the issues. But I had a surprise in store. Having deployed the site to a production server (digitalocean droplet), I migrated my databases and uploads. One site seemed to hang indefinitely if ‘contact-form-7’ was activated, and I decided to sleep on that and tackle it today.

Today, the whole server seems to be having issues, and after some digging I see I have absolutely no free space on my server, reason being PHP has generated 16GB of error logs. The logs begin with an attempt to access/create a new uploads directory (for this month), but using the path from my old server. As per the functions.php file, it attempts to access the parent directory, eventually repeatedly trying to access the root.

2016/09/25 15:32:53 [error] 1290#1290: *5 FastCGI sent in stderr: "PHP message: PHP Warning:  file_exists(): open_basedir restriction in effect. File(/home/theorange/public_html/olivier.uk/wp-content/uploads/2016/09) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1611
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/home/theorange/public_html/olivier.uk/wp-content/uploads/2016) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/home/theorange/public_html/olivier.uk/wp-content/uploads) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/home/theorange/public_html/olivier.uk/wp-content) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/home/theorange/public_html/olivier.uk) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/home/theorange/public_html) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/home/theorange) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restricti
2016/09/25 15:32:53 [error] 1290#1290: *5 FastCGI sent in stderr: " restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/wp/wp-includes/functions.php on line 1616
PHP message: PHP Warning:  is_dir(): open_basedir restriction in effect. File(/) is not within the allowed path(s): (/srv/www/:/tmp) in /srv/www/patterncutting/releases/20160925120458/web/w
2016/09/25 15:32:53 [error] 1290#1290: *5 FastCGI sent in stderr: "/web/wp/wp-includes/functions.php on line 1616

This goes on indefinitely. In 30 seconds it was able to generate 256MB of logs.
The offending entry in the database is wp_options: upload_path.

I’ve tried replacing it with the path to the current uploads folder /srv/www/SITENAME/shared/uploads/, but this hasn’t worked. My MySQL fu is distinctly weak, so I need some help here.

I can see a similar topic was addressed, but since I am not using the ‘media’ directory, it doesn’t look like that will apply. There’s also an unsolved thread along a similar line.

After checking in another bedrock site’s database, I can see the upload_path field in the database should be empty.

After clearing the entry, the site now works as expected, though it’s quite unsettling error handling to generate logs like those!

So you had some code that would check a folder, and if it didn’t work, check one folder up, continually?

Actually it’s a Wordpress function, which determines the permissions of the parent in order to set that on the new child being created. See includes/functions.php : 1614

// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) ) {
	$target_parent = dirname( $target_parent );
}