Make WordPress Core

Opened 2 years ago

Closed 21 months ago

Last modified 21 months ago

#37220 closed defect (bug) (worksforme)

Improvement symlinks on wp-config.php

Reported by: grazianognoll Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.5.3
Component: Bootstrap/Load Keywords:
Focuses: Cc:

Description (last modified by ocean90)

Hello, i noticed working on a wordpress website that if the website is in a directory (es. /var/www/releases/3/) and the web root is pointing through a symbolic link ( so. /var/www/current/ pointing to /var/www/releases/3/ ) the function in the wordpress config is not retrieving the right directory:

if ( !defined('ABSPATH') )
	define('ABSPATH', dirname(__FILE__) . '/');

I solved manually defining ABSPATH to the right directory, but i think it would be better to fix if maybe checking if the directory is a symlink.

The problem is that from php5 __FILE__ is reporting the absolute path, so it may be better to use $_SERVER['PWD'] to retrieve the path: <?php echo $_SERVER['PWD'] ."\n"; ?> would be /var/www/current

Thanks, Emanuele.

Change History (4)

#1 @ocean90
2 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #core by jorbin. View the logs.

21 months ago

#3 @iamfriendly
21 months ago

  • Resolution set to worksforme
  • Status changed from new to closed

Hi @grazianognoll,

Thanks for the report! I've found great success in using is_link() http://php.net/manual/en/function.is-link.php and readlink() http://php.net/manual/en/function.readlink.php.

i.e. some variation of the following;

$local_url	 = 'http://mywebsite.dev';
$root_path = dirname( dirname( __FILE__ ) );
$wp_content_dir = readlink( $root_path . '/current' ) . '/content';

define( 'WP_HOME', $local_url );
define( 'WP_SITEURL', $local_url );

define( 'PLUGINDIR', 'content/plugins' );

define( 'CONTENT_DIR', '/content' );
define( 'WP_CONTENT_DIR', $wp_content_dir );
define( 'WP_CONTENT_URL', $local_url . '/content' );

Also, if you're into using symlinks with a custom deploy strategy, I highly recommend giving https://github.com/roots/bedrock a look. They push the boundaries a little so require you to have PHP 5.6.

There's definitely ways of making this work, so I'm going to close this as 'worksforme' but if you think that's not true in your case, please feel free to reply.

#4 @DrewAPicture
21 months ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.