Resolving issue with tmp directory

On some hostings, when using CSS and/or JS minification, you might notice that your website looks broken, and if you look inside the minified files, you see this:

PHP Warning: is_file(): open_basedir restriction in effect. File(/tmp/fontawesome.min.css) is not within the allowed path(s)

This means that the default path for the tmp directory WP Rocket is trying to use is not the correct one.

To fix the issue, you can modify the path to the tmp directory by using the  mu-plugin below:

❗️Don't forget to replace /path_to_tmp_directory/ ,in the last line, with the correct path for your filesystem!

<?php
/**
 * Plugin Name: Rocket custom tmp path
 * Description: Modify the tmp path used for minified files creation.
 * Author:      WP Rocket team
 * License:     GNU General Public License v3 or later
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */


// Basic security, prevents file from being loaded directly.
defined( 'ABSPATH' ) or die( 'Cheatin&#8217; uh?' );


add_filter( 'rocket_override_min_cachepath', '__return_true' );
add_filter( 'rocket_min_cachePath', '__rocket_custom_min_cachepath' );
function __rocket_custom_min_cachepath() {
    return '/path_to_tmp_directory/';
}

Once you added the mu-plugin, you need to clear the cache once to update the minified files.