wp-media / wp-rocket-cli

WP CLI interface for the WP Rocket plugin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

htaccess regeneration not working from CLI with Bedrock

Sidlegionair opened this issue · comments

Hi,

The regeneration command does not work when running bedrock (https://roots.io/bedrock). It fails to detect the correct htaccess path from CLI and then it will stop to work here (htaccess.php line 33)

$htaccess_file = get_home_path() . '.htaccess';

if ( ! rocket_direct_filesystem()->is_writable( $htaccess_file ) ) {
	// The file is not writable or does not exist.
	return false;
}

Note for grooming: Check possible connection with #22

Reproduce the problem ✅

Reproduced on local installation under Flywheel + Bedrock

Identify the root cause ✅

The root cause is related to get_home_path() which brings the / path.
Based on Bedrock documents, it seems that .htaccess file needs to be located under: web/.htaccess and this is the issue.
WP Rocket uses $htaccess_file = get_home_path() . '.htaccess'; which will identify the path to .htaccess file as : /.htaccess which is not accurate.

UPDATE: IT seems this is only from CLI due to wrong ABSPATH coming from Bedrock

The issue is coming from this line:
$home_path = substr( $_SERVER['SCRIPT_FILENAME'], 0, $pos ); from get_home_path() -> file.php WP class
From CLI it seems that SCRIPT_FILENAME = usr/bin/local/wp which will break totally the home_path and also our htaccess path.

Scope a solution ✅

A possible solution is that from CLI to map the get_home_path() without any SCRIPT_FILENAME and modify also flush_rocket_htaccess() function to accept the full path to htaccess file and bypass the default get_home_path()

@wp-media/php what do you think? Did I missed something?

Estimate the effort ✅

Effort [S]

@Sidlegionair @crystinutzaa Can you retry this issue with v1.2 of the CLI?

One of the changes to fix #22 Could be also fixing this issue.