php composer open_basedir restriction, how do I set the home paths? - php

I have installed php and composer on a Windows Vista 64 machine. I am having a devil of a time getting Composer to accept a directive to use a specified directory other than the default C:\Users\\AppData\Roaming\Composer.
I tried to set up a config.json file viz:
{
"config": {
"COMPOSER_HOME": "c:\inetpub\wwwroot\PHPcomposer\",
"COMPOSER_CACHE_DIR": "c:\inetpub\wwwroot\PHPcomposer\"
}
}
and this was completely ignored. even added cache-dir for fun.
I tried altering the composer.json viz:
{
"require": {
"symfony/validator": "2.1.*",
"doctrine/dbal": "2.2.*",
"monolog/monolog": "dev-master",
"jtreminio/test-extensions": "dev-master"
},
"minimum-stability": "dev",
"config": {
"COMPOSER_HOME": "c:/inetpub/wwwroot/PHPcomposer/",
"cache-dir": "c:/inetpub/wwwroot/PHPcomposer/",
"COMPOSER_CACHE_DIR": "c:/inetpub/wwwroot/PHPcomposer/"
}
}
and still I am getting an open_basedir restriction in effect message referring to
C:\Users\<user>\AppData\Roaming\Composer
I also did a iisreset, just in case iis was caching stuff.
So, any clues as to where I am going wrong. I know I can alter php.ini, but that to me is violating the security that php is offering. I would prefer to tell Composer to behave and do what I tell it to do.
Here is the command line I used and the result of it, the same error occurs regardless of any settings in config.phar or the "config" section in composer.phar. The php.ini has open_basedir = "C:\inetpub\wwwroot":
C:\inetpub\wwwroot\PHPcomposer>composer install
[ErrorException]
file_exists(): open_basedir restriction in effect.
File(C:/Users/Stuart/AppData/Roaming/Composer/.htaccess) is not
within the allowed path(s): (C:\inetpub\wwwroot)
install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev]
[--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress]
[-v|vv|vvv|--verbose] [-o|--optimize-autoloader]

You need to Create a directory c:\pathTo\composer and download composer.phar into it from here
Then setup COMPOSER_HOME and COMPOSER_CACHE_DIR before running php, in a batch file:
composer.bat
#ECHO off
SET cwd=%cd%
PUSHD "c:\pathTo\php-5.4.28"
SET COMPOSER_HOME=c:\pathTo\composer
SET COMPOSER_CACHE_DIR=c:\pathTo\composer
"c:\pathTo\php-5.4.28\php.exe" -c "c:\pathTo\phpIniDir" -ddisable_functions="" -ddisable_classes="" -n "c:\pathTo\composer\composer.phar" --working-dir="%cwd%" %*
POPD

Related

How to use `prefer-dist` command line composer option inside the composer.json file, so that it is not a one time per command but a lasting setting?

How to use a prefer-dist command line composer option inside the composer.json file, so that it is not a one time per command setting but a lasting setting inside a composer.json file throughout the project libraries installations?
Reference:
https://github.com/composer/composer/issues/6798
As picked up from the documentation, composer exactly states, literal wording at the time being (should be listed the option preferred-install with listed values):
"preferred-install# Defaults to auto and can be any of source, dist or auto. This option allows you to set the install method Composer will prefer to use. Can optionally be a hash of patterns for more granular install preferences."
{
"config": {
"preferred-install": {
"my-organization/stable-package": "dist",
"my-organization/*": "source",
"partner-organization/*": "auto",
"*": "dist"
}
}
}
Reference link:
https://getcomposer.org/doc/06-config.md#preferred-install

Trying to run heroku locally and get a error 'vendor' is not a command

I am trying to run heroku locally using the command
heroku local
However, it returns:
[OKAY] Loaded ENV .env File as KEY=VALUE Format
'vendor' is not recognized as an internal or external command, operable program or batch file.
[DONE] Killing all proccess with signal null
Exited with exit code 1
I am using Heroku PHP within Windows 7
In my PATH environmental variable, I have both:
./vendor/bin and C:\Users\user-name\AppData\Roaming\Composer\vendor\bin
(The last one is an empty folder)
I searched for anything similar but I couldn't find.
Any thoughts on it?
Thanks in advance
Update
The error was in my Procfile:
web: vendor/bin/heroku-php-apache2 public/
Then I change all slashes to backslashes ():
web: vendor\bin\heroku-php-apache2 public\
Now its working but I am getting this error:
../heroku/heroku-buildpack-php/bin/heroku-php-apache2: line 196: php-fpm: command not found
This program requires PHP 5.5.11 or newer; check your 'php-fpm' command.
I think there is something wrong related to my composer.
The source file for heroku-php-apache2 can be found here.
The line 196 is presented below.
196: { php-fpm -n -v | php -n -r 'exit((int)version_compare(preg_replace("#PHP (\S+) \(fpm-fcgi\).+$#sm", "\\1", file_get_contents("php://stdin")), "5.5.11", "<"));'; } || { echo "This program requires PHP 5.5.11 or newer; check your 'php-fpm' command." >&2; exit 1; }
My composer.json file is:
{
"require" : {
"ext-mcrypt": "*",
"facebook/php-sdk-v4" : "~5.0",
"google/apiclient": "2.0"
},
"require-dev": {
"mashape/unirest-php": "3.*",
"heroku/heroku-buildpack-php": "*"
}
}
I tried to specific require php in composer.json but it didn't changed. Any thoughts on that?
Thank you in advance.
Years later, I've faced this same issue.
Fixed by removing vendor/ and running composer install again.
Then I've faced the same php-fpm error and to fix that I created a symbolic link from /usr/sbin/php-fpm7.4 -> /usr/sbin/php-fpm.
Hope that becomes helpful to orthers in the future!

PHP: MDB2 error - call to undefined function

I have error in my old project based od MDB2 and PHP 5.4:
PHP Fatal error: Call to undefined function: MDB2_Driver_pgsql::raiseError(). in /path/to/project/vendor/pear-pear.php.net/MDB2/MDB2.php on line 1936
Dependencies loaded via composer:
"require": {
"pear-pear.php.net/Validate": "0.7.0",
"pear-pear.php.net/Validate_PL": "0.5.1",
"pear-pear.php.net/HTML_Quickform": "*",
"pear-pear.php.net/HTML_Table": "*",
"pear-pear.php.net/MDB2": "*",
"pear-pear.php.net/MDB2_Driver_pgsql": "*",
"pear-pear.php.net/OLE": "1.0.0RC1",
"pear-pear.php.net/Spreadsheet_Excel_Writer": "0.9.1",
"pear-pear.php.net/File_SearchReplace": "*",
And I don't change anything in this code. Anyone had this problem? :)
This error is solved by installing PEAR-1.9.5
I've spent some time to find easy way to downgrade PEAR version.
It's easy to do by running terminal command:
pear install -f PEAR-1.9.5
Hope this will help someone to save extra time.

Laravel 4: Class 'MongoClient' Not Found

I have Laravel 4 installed on WAMP and it works great with a MySQL backend.
I have successfully setup second virtual host and would like to use a MongoDB backend. After searching around I found out that Laravel does not natively connect to MongoDB and I found https://github.com/jenssegers/Laravel-MongoDB and I have been trying to set it up but I can't seem to get it right. Obviously I must be doing something wrong and I am hoping someone can help me identify what it is that I am not doing right.
I edited composer.json per the instructions:
............
"license": "MIT",
"require": {
"laravel/framework": "4.1.*",
"jenssegers/mongodb": "*"
},
"autoload": {
.........
Then I ran composer update. It installed monolog 1.9.1 and swiftmailer v5.2.0 - whatever these are - successfully (a few days ago) but then threw an error after that. Today I tried to run composer update again, and it updated the two to 1.10.0 and v5.2.1 respectively and then encountered the same error. Now when I try composer update it consistently throws the same error:
Nothing to install or update
Generating autoload files
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","me
ssage":"Class 'MongoClient' not found","file":"C:\\wamp\\www\\laravel\\vendor\\j
enssegers\\mongodb\\src\\Jenssegers\\Mongodb\\Connection.php","line":132}}Script
php artisan clear-compiled handling the post-update-cmd event returned with an
error
[RuntimeException]
Error Output:
update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock]
[--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-
dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [
packagesN]
What I have tried:
I have downloaded and installed the php_mongo.dll by placing it in the php ext folder and enabling it in php.ini:
; added for mongoDB connections
extension=php_mongo.dll
But this did not help.
NOTE: I would not have been able to resolve the issue completely without #Hassan 's help -- please see comments under #Hassan 's answer.
I'll provide this answer in the hopes that it may help someone else who may experience the same issue. I thought it better to give it as an answer so that it stands out.
Further search lead me here: https://github.com/jenssegers/Laravel-MongoDB/issues/36
Then here: https://github.com/leroy-merlin-br/mongolid-laravel#troubleshooting
The following command and output indicates the location of php.ini that I should have updated with the php_mongo.dll extension:
$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => C:\Windows
Loaded Configuration File => C:\wamp\bin\php\php5.5.12\php.ini
The WAMP tray icon however points to C:\wamp\bin\apache2.4.9\bin\php.ini -- which is what I had updated. I also checked if PHP in the CLI environment is importing the driver properly by running the following command with the output shown:
$ php -i | grep 'Mongo'
MongoDB Support => enabled
After updating the correct php.ini, I restarted apache and tried again composer update again. The error was different -- authentication -- as the username, password and database were wrong. Once those were corrected, the update completed without incident.
Your composer file looks fine, as is probably everything else. Try a "composer dumpautoload", from the docs:
If you need to update the autoloader because of new classes in a classmap package for example, you can use "dump-autoload" to do that without having to go through an install or update.
This should fix that error, after which you'll need to change your adapter in app/config/database.php to use mongodb like so:
'default' => 'mongodb',
And add mongodb to your connections too:
'connections' => array(
...
'mongodb' => array(
'driver' => 'mongodb',
'host' => 'localhost',
'port' => 27017,
'username' => '',
'password' => '',
'database' => 'test'
),
),

Warning: failed to open stream: No such file or directory in C:\wamp\www\laravel\bootstrap\autoload.php on line 17

Environement
Windows 7
WAMP server
PHP 5.3.13
Apache 2.2.12
MySQL 5.5.24
Laravel 4.1
I installed laravel, trying to run the URL
http://localhost/laravel/public
autoload.php
define('LARAVEL_START', microtime(true));
require __DIR__.'/../vendor/autoload.php';
if (file_exists($compiled = __DIR__.'/compiled.php')){
require $compiled;
}
Illuminate\Support\ClassLoader::register();
if (is_dir($workbench = __DIR__.'/../workbench')){
Illuminate\Workbench\Starter::start($workbench);
}
I am facing the following errors:
Warning: require(C:\wamp\www\laravel\bootstrap/../vendor/autoload.php) [function.require]: failed to open stream: No such file or directory in C:\wamp\www\laravel\bootstrap\autoload.php on line 17
and
Fatal error: require() [function.require]: Failed opening required 'C:\wamp\www\laravel\bootstrap/../vendor/autoload.php' (include_path='.;C:\php\pear') in C:\wamp\www\laravel\bootstrap\autoload.php on line 17
Go to the current Project folder
C:\wamp\www\laravelProjectFolder>
and type composer install in command prompt and press ENTER key.
composer install
Then the vendor directory will be downloaded in the current project of laravel.
Now refresh the screen.
Simply make your storage folder writable. This can be found in your app directory
In your terminal use this command
chmod +w <directory> or chmod a+w <directory>
Make sure you navigate to the directory containing the directory you want to make writable or you point to that path.
go to your project folder via cmd. run the following command
composer update
it will install missing vendor folder and files in your project.
but in some cases it gives error like " Your configuration does not allow connection to bla bla bla.."
for that go to your composer.json file,
change "secure-http": true to "secure-http": false
but in some cases (as was in my case) you may not find such line in your file. for that do the following action:
change "config": {
"preferred-install": "dist"
}
to
"config": {
"preferred-install": "dist",
"secure-http": false
}
and run again composer update command.
hope this will solve problem of many persons. :)
You are trying to include:
C:\wamp\www\laravel\bootstrap/../vendor/autoload.php
and the error gives
No such file or directory in
C:\wamp\www\laravel\bootstrap\autoload.php on line 17
so you need to check your directory layout. Is there a directory vendor in lavarel with a file autoload.php in it?
and you should either have / in your pathnames or \ but not mixed both.

Categories