Can't get Composer to work on Windows - php

I'm trying to use https://github.com/phpWhois/phpWhois in my PHP scripts, but can't get it to work. I'm an absolute beginner when it comes to using Composer.
This is what I tried:
Cloned the git repo locally
Installed Composer for Windows
In Powershell, navigated to the local repository
Typed composer require. Composer first asked me: Search for a package:, where I simply pressed ENTER. Then, Composer installed various packages in the vendor directory (phpunit, symfony, sebastian, etc.), and it created an autoload.php file.
But if I include that autoload.php in my example script (the basic example on the phpWhois Github main page), it generates the following error:
Fatal error: Class 'phpWhois\Whois' not found in /home/myServer/www/myApp/api/whoistest.php on line 12
Well, the Installation manual on the Github page says I should run
php composer.phar require "phpwhois/phpwhois":"~4.0"
So I tried the following in the Powershell console:
composer require "phpwhois/phpwhois":"~4.0"
[UnexpectedValueException]
Could not parse version constraint :~4.0: Invalid version string ":~4.0"
Then this:
composer require "phpwhois/phpwhois"
Problem 1
Conclusion: remove phpwhois/phpwhois dev-master
Can only install one of: phpwhois/phpwhois[dev-master, 4.2.3].
Can only install one of: phpwhois/phpwhois[dev-master, 4.2.4].
Can only install one of: phpwhois/phpwhois[v4.2.5, dev-master].
Installation request for phpwhois/phpwhois dev-master -> satisfiable by phpwhois/phpwhois[dev-master].
Installation request for phpwhois/phpwhois ^4.2 -> satisfiable by phpwhois/phpwhois[4.2.3, 4.2.4, v4.2.5].
Then this:
composer require "phpwhois/phpwhois:~4.0"
which gave the same error as above.
I tried various other syntaxes to specify the version here, but none of them worked.
Any ideas?

Ok, let's start from the beginning.
Download the latest composer.phar from getcomposer.org (scroll down to manual install).
Put it in your project root directory.
Remove all your current require statements from your composer.json.
Open a terminal and navigate to your project root.
Execute php composer.phar require phpwhois/phpwhois.
Execute php composer.phar install.
Include the autoloader in your code: require vendor/autoload.php.

Related

Setting up php-casperjs with composer

I'm having trouble setting up php-casperjs for my project. I've never used composer before, so I'm not exactly sure what I'm doing wrong.
I got xampp installed on Windows with php version 5.6.12
Here are the steps I completed so far.
Downloaded and installed composer. It launches successfully from the command prompt.
Downloaded php-casperjs and extracted composer.json and src/Casper.php into my project folder C:\xampp\htdocs\test
Navigated to the project folder in the command prompt and ran composer install command which installed 22 packages
Then I ran composer require phpcasperjs/phpcasperjs command and here I ran into problems. I get the following error message
Using version ^1.2 for phpcasperjs/phpcasperjs
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- The requested package phpcasperjs/phpcasperjs No version set (parsed as 1.0.0) is satisfiable by phpcasperjs/phpcasperjs[No version
set (parsed as 1.0.0)] but these conflict with your requirements or
minimum-stability.
Installation failed, reverting ./composer.json to its original
content.
When I run the following php code
use Browser\Casper;
$casper = new Casper();
I get Fatal error: Class 'Browser\Casper' not found in C:\xampp\htdocs\test\test.php on line 3
Step1: Go to you project directory and create a file "composer.json"
codes for composer.json
{
"require": {
"monolog/monolog": "1.0.*"
}
}
Note: You can create you composer.json with your required packages but i just created a simple composer.json file with monolog/monolog package. For your understanding you can follow my steps (this). You can remove the package monolog later on.
Now navigate to the project directory where composer.json file located
Run the following command:
composer require phpcasperjs/phpcasperjs
And you faced the above problem because of wrong or mismatched version of the intended package. Keep in mind that you always can create composer.json with your custom packages and their versions and which will be your package manager. For more detail about composer please visit Link

composer - Invalid working directory specified error

I'm trying to install the Drupal Console (https://drupalconsole.com/)
As per the instructions here:
https://hechoendrupal.gitbooks.io/drupal-console/content/en/getting/windows.html
I have Git for windows, composer, PHP, and sqlite-tools-win32-x86 all
installed.
I have defined everything as per the instructions on that page.
When I run:
$ composer global require drupal/console:#stable
I'm getting:
admin#Dxxx MINGW64 ~
$ composer global require drupal/console:#stable
Changed current directory to C:/Users/admin/AppData/Roaming/Composer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
That lead me to look into the composer settings. When i run
$ composer -d
I get:
[RuntimeException]
Invalid working directory specified, does not exist.
Looks like something is wrong with my composer installation. Any idea what?

Installing Slim 3 using Composer

Hello. Please I am new to the php slim framework. I have tried all day to download and install slim 3 through composer but haven't been successful.
Am using a windows pc. I used command prompt and downloaded composer and installed composer to the desired directory. However, when i try installing slim 3, I get an error : "installation failed, reverting ./composer.json to its original content"
[Command Prompt Error Message][Command prompt error message]
you have to load the direction page of slim frame work using this link:
https://www.slimframework.com/docs/start/installation.html
and there will be a command like this - composer require slim/slim "^3.0"
instead of using this one you have to use this...
php composer.phar require slim/slim "^3.0"
and you will get slim installed
Kick-start Slim 3 projects using a skeleton!
With Composer installed, use the cmd line to access the C:\xampp\htdocs folder, then write this command:
$ php create-project slim/slim-skeleton [my-app-name]
Command will produce composer.json and composer.lock files along with a public/ folder that can all be committed to VCS (do not commit any other folders/dependencies).
Make sure you have high enough version of PHP, and PHP is in your PATH. To check this - print "php -v " in command line (you can pretty sure run up to PHP7).
Make sure you are in the right directory for your project.
Provide complete command line output, there could be things you didn't know to be important for a good answer.
After all, you can delete composer.json and composer.lock from the directory, and try again.
I use windows with XAMPP to run a virtual apache server.
After many similar issues, I downloaded git-bash and used it instead of the windows cmd.
give it a try, and see if that can resolve your issues.
https://git-scm.com/

Google plus login functionality and composer library install

I am working on Google + login functionality for that purpose I am referring https://developers.google.com/+/quickstart/php url. I have done all the suggested instructions
Enabled google plus api
Set up the PHP quick-start app
In second step to run signin.php file they are suggesting to Install composer and run command php composer.phar install.
I have already installed Composer on my machine and it is up to date.
I am not getting how to run php composer.phar install command as the code cloned from https://github.com/googleplus/gplus-quickstart-php.git does not have composer.phar file (only have composer.json and composer.lock files)
How do I install these dependencies as when I run signin.php file
Fatal error appears as autoloader.php not found.
I am guessing that by using composer I need to download directory from https://github.com/google/google-api-php-client.git as this is written in composer.json file.
Let me know what should I do?

Could not open input file: /Users/me/composer.phar - After running source ~/.bash_profile.save

this is giving me a headache. Simply trying to install laravel 4.
So, installed composer fine and it runs correctly. The issue is that when i tryed to install laravel i was recieving this error:
- laravel/framework v4.2.9 requires php >=5.4.0 -> no matching package found.
So, I checked the PHP version that terminal was using and using:
which php
gave me the usr/local/bin location and then php -v showed that was 5.3 php.
So, following some instructions I edited the .bash_profile.save so that the path was now:
alias composer='php ~/composer.phar'
export PATH=/Applications/MAMP/bin/php/php5.5.14/bin:$PATH
^R
I then ran:
source ~/.bash_profile.save
And then again which php.
This showed the correct path BUT... when trying to use composer i recieved this error:
Could not open input file: /Users/me/composer.phar
So now im stuck. Is it because of the alias composer line? Where should that now be pointed?
Thanks, just want to get on with laravel... :)
You need to have composer in that directory below
mv composer.phar /usr/local/bin/composer
And not in your user account's root
Just get this composer.phar in the composer web site and put it in the same place where you have composer.json; this is all you need.
https://getcomposer.org/download/1.2.0/composer.phar

Categories