Nexmo / vonage-php-nexmo-bridge

Polyfill for letting Nexmo namespaced code run under the Vonage PHP SDK
BSD 3-Clause "New" or "Revised" License
39 stars 3 forks source link

Conflict with php open_basedir configuration #1

Open pgdavidApodis opened 3 years ago

pgdavidApodis commented 3 years ago

When COMPOSER_VENDOR_DIR is not set (it is not by default), the package generates a php warning, if php open_basedir configuration is set.

Warning: file_exists(): open_basedir restriction in effect. File(/autoload.php) is not within the allowed path(s): (/xxx) in /yyy/vendor/vonage/nexmo-bridge/src/Autoloader.php on line 69

Existance of COMPOSER_VENDOR_DIR should be checked first in src/Autoload.php

private static function getClassLoader() : ClassLoader
{
if (file_exists(getenv('COMPOSER_VENDOR_DIR') . '/autoload.php')) {
    return include getenv('COMPOSER_VENDOR_DIR') . '/autoload.php';
}
if (file_exists(__DIR__ . '/../../../autoload.php')) {
    return include __DIR__ . '/../../../autoload.php';
}
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
    return include __DIR__ . '/../vendor/autoload.php';
}

throw new RuntimeException('Cannot detect composer autoload. Please run composer install');
}

First check should be replaced with :

if (getenv('COMPOSER_VENDOR_DIR') && file_exists(getenv('COMPOSER_VENDOR_DIR') . '/autoload.php'))
natsumework commented 3 years ago

I meet the same problem.

sca1235 commented 3 years ago

Same issue

KRens commented 2 years ago

+1 Same issue. Your solution fixes it, someone please merge this in.

nawidhaidari commented 1 year ago

Hello KRens, how did you users/change this to get it working. I have this error AH01071: Got error 'PHP message: PHP Warning: file_exists(): open_basedir restriction in effect. File(/autoload.php) is not within the allowed path(s): (/var/www/vhosts/MySite.com/:/tmp/) in /var/www/vhosts/MySite.com/httpdocs/vendor/vonage/nexmo-bridge/src/Autoloader.php on line 69', referer: https://mysite.com/ and dont know how to get this fixed if you could please help.

Thank you,

KRens commented 1 year ago

THe first post written by pgdavidApodis contains the solution already. Just replace 1 line of code in src/Autoload.php:

if (file_exists(getenv('COMPOSER_VENDOR_DIR') . '/autoload.php')) { with: if (getenv('COMPOSER_VENDOR_DIR') && file_exists(getenv('COMPOSER_VENDOR_DIR') . '/autoload.php')) {

nawidhaidari commented 1 year ago

Thank you @KRens. It did the trick. I added it to the autoloader.php because there were no if conditions in autoload.php.

LucaRed commented 1 year ago

This has been fixed by #2, so the issue can be closed.