diff --git a/htdocs/conf/conf.php.example b/htdocs/conf/conf.php.example index e0cee5e2719..c35fec78ce7 100644 --- a/htdocs/conf/conf.php.example +++ b/htdocs/conf/conf.php.example @@ -14,9 +14,10 @@ // dolibarr_main_url_root // This parameter defines the root URL of your Dolibarr index.php page. // It must link to the htdocs directory htdocs. -// In most cases, this is autodetected but it still required to show full -// url bookmarks for some services (ie: agenda rss export url, ...) or -// when using Apache dir aliases (autodetect fails). +// In most cases, this is autodetected but it's still required +// * to show full url bookmarks for some services (ie: agenda rss export url, ...) +// * or when using Apache dir aliases (autodetect fails) +// * or when using nginx (autodetect fails) // Examples: // $dolibarr_main_url_root='http://localhost'; // $dolibarr_main_url_root='http://mydolibarrvirtualhost'; diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 7ff53d7cac6..0abe174ec07 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -145,12 +145,13 @@ if (empty($dolibarr_main_data_root)) define('DOL_CLASS_PATH', 'class/'); // Filesystem path to class dir (defined only for some code that want to be compatible with old versions without this parameter) define('DOL_DATA_ROOT', $dolibarr_main_data_root); // Filesystem data (documents) define('DOL_DOCUMENT_ROOT', $dolibarr_main_document_root); // Filesystem core php (htdocs) -// Define DOL_MAIN_URL_ROOT and DOL_URL_ROOT +// Try to autodetec DOL_MAIN_URL_ROOT and DOL_URL_ROOT. +// Note: autodetect works only in case 1, 2, 3 and 4 of phpunit test CoreTest.php. For case 5, 6, only setting value into conf.php will works. $tmp=''; $found=0; -$real_dolibarr_main_document_root=str_replace('\\','/',realpath($dolibarr_main_document_root)); // A) Ex: C:/xxx/dolibarr/htdocs -$pathroot=$_SERVER["DOCUMENT_ROOT"]; // B) Ex: C:/Program Files/wamp/www/ -$paths=explode('/',str_replace('\\','/',$_SERVER["SCRIPT_NAME"])); // C) Ex: /dolibarr/htdocs/admin/system/phpinfo.php +$real_dolibarr_main_document_root=str_replace('\\','/',realpath($dolibarr_main_document_root)); // A) Value found into config file, to say where are store htdocs files. Ex: C:/xxx/dolibarr, C:/xxx/dolibarr/htdocs +$pathroot=$_SERVER["DOCUMENT_ROOT"]; // B) Value reported by web server setup, to say where is root of web server instance. Ex: C:/xxx/dolibarr, C:/xxx/dolibarr/htdocs +$paths=explode('/',str_replace('\\','/',$_SERVER["SCRIPT_NAME"])); // C) Value reported by web server, to say full path on filesystem of a file. Ex: /dolibarr/htdocs/admin/system/phpinfo.php $concatpath=''; foreach($paths as $tmppath) // We check to find (B+start of C)=A { diff --git a/test/phpunit/CoreTest.php b/test/phpunit/CoreTest.php index fe43d3735f8..408f8038d1c 100755 --- a/test/phpunit/CoreTest.php +++ b/test/phpunit/CoreTest.php @@ -135,6 +135,7 @@ class CoreTest extends PHPUnit_Framework_TestCase global $dolibarr_main_db_type; global $dolibarr_main_db_prefix; + // Case 1: // Test for subdir dolibarr (that point to htdocs) in root directory /var/www // URL: http://localhost/dolibarrnew/admin/system/phpinfo.php $_SERVER["HTTPS"]=''; @@ -143,11 +144,9 @@ class CoreTest extends PHPUnit_Framework_TestCase $_SERVER["DOCUMENT_ROOT"]='/var/www'; $_SERVER["SCRIPT_NAME"]='/dolibarrnew/admin/system/phpinfo.php'; $expectedresult='/dolibarrnew'; - // Put this into conf.php if you want to test alt - //$dolibarr_main_url_root='http://localhost/dolibarralias'; - //$dolibarr_main_url_root_alt='http://localhost/dolibarralias/custom2'; - // Test for subdir aaa (that point to dolibarr) in root directory /var/www + // Case 2: + // Test for subdir aaa (that point to dolibarr) in root directory /var/www // URL: http://localhost/aaa/htdocs/admin/system/phpinfo.php $_SERVER["HTTPS"]=''; $_SERVER["SERVER_NAME"]='localhost'; @@ -155,10 +154,8 @@ class CoreTest extends PHPUnit_Framework_TestCase $_SERVER["DOCUMENT_ROOT"]='/var/www'; $_SERVER["SCRIPT_NAME"]='/aaa/htdocs/admin/system/phpinfo.php'; $expectedresult='/aaa/htdocs'; - // Put this into conf.php if you want to test alt - //$dolibarr_main_url_root='http://localhost/dolibarralias'; - //$dolibarr_main_url_root_alt='http://localhost/dolibarralias/custom2'; + // Case 3: // Test for virtual host localhostdolibarrnew that point to htdocs directory with // a direct document root // URL: http://localhostdolibarrnew/admin/system/phpinfo.php @@ -168,10 +165,8 @@ class CoreTest extends PHPUnit_Framework_TestCase $_SERVER["DOCUMENT_ROOT"]='/home/ldestail/workspace/dolibarr/htdocs'; $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; $expectedresult=''; - // Put this into conf.php if you want to test alt - //$dolibarr_main_url_root='http://localhost/dolibarralias'; - //$dolibarr_main_url_root_alt='http://localhost/dolibarralias/custom2'; + // Case 4: // Test for virtual host localhostdolibarrnew that point to htdocs directory with // a symbolic link // URL: http://localhostdolibarrnew/admin/system/phpinfo.php @@ -181,10 +176,8 @@ class CoreTest extends PHPUnit_Framework_TestCase $_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr'; // This is a link that point to /home/ldestail/workspace/dolibarr/htdocs $_SERVER["SCRIPT_NAME"]='/admin/system/phpinfo.php'; $expectedresult=''; - // Put this into conf.php if you want to test alt - //$dolibarr_main_url_root='http://localhost/dolibarralias'; - //$dolibarr_main_url_root_alt='http://localhost/dolibarralias/custom2'; + // Case 5: // Test for alias /dolibarralias // URL: http://localhost/dolibarralias/admin/system/phpinfo.php $_SERVER["HTTPS"]=''; @@ -195,8 +188,18 @@ class CoreTest extends PHPUnit_Framework_TestCase $expectedresult='/dolibarralias'; // Put this into conf.php because autodetect will fails in this case //$dolibarr_main_url_root='http://localhost/dolibarralias'; - //$dolibarr_main_url_root_alt='http://localhost/dolibarralias/custom2'; + // Case 6: + // Test when using nginx + // URL: https://localhost/dolibarr/admin/system/phpinfo.php + $_SERVER["HTTPS"]=''; + $_SERVER["SERVER_NAME"]='localhost'; + $_SERVER["SERVER_PORT"]='80'; + $_SERVER["DOCUMENT_ROOT"]='/var/www/dolibarr/htdocs'; + $_SERVER["SCRIPT_NAME"]='/dolibarr/admin/system/phpinfo.php'; + $expectedresult='/dolibarr'; + // Put this into conf.php because autodetect will fails in this case + //$dolibarr_main_url_root='http://localhost/dolibarr'; // Force to rerun filefunc.inc.php include dirname(__FILE__).'/../../htdocs/filefunc.inc.php';