Where should I install Composer? - composer-php

Just wondering where I should install Composer. It kind of wrecked my environment last time. I'm running XAMPP and i'm looking to use it within some Framework sites. So to me the XAMPP folder itself seems appropriate. Would that be correct? The main thing for me is that it doesn't alter any environment paths or the such.
Any advice would be great.

The main aspect is that you'd probably want to run Composer easily in the command shell. This implies that Composer has to be in any directory mentioned in the path variable.
Have a look at your current path, pick a convenient directory, and put the composer.phar file there.
If you don't like that, you could also create a batch file that does run PHP with that phar file in a different location, and passes all the other command line arguments to it.

Related

Refactoring Composer executable file for portability

Installing Composer locally puts a file named composer in your directory. I have taken to copying this file into each of my projects that uses Composer, so that I can run php composer in each folder.
Since this results in a lot of needlessly-repeated code, I want to refactor the composer file into something minimal. The most logical solution would be to refer to a class that resides in the vendor folder. Why is there so much code in the composer file anyway? I'd prefer not to put the code into my own libraries if I don't have to.
For comparison, here's a sample of code in a typical phpunit file:
require_once 'my_bootstrap.php';
spl_autoload_register(array(MyBootstrap::class,'autoload'));
// Do some other stuff here.
\PHPUnit_TextUI_Command::main();
I want to reduce the composer file in each project to something like this.
I do not want to install Composer globally. I want each project to be an environment unto itself and not have to instruct another developer to install anything other than PHP.

Laravel installation tutorial says to add ~/.composer/vendor/bin to my $PATH, but it doesn't exist

I've tried a couple of methods to install laravel, including this command:
composer global require "laravel/installer=~1.1"
As far as I can tell, it installs. Certainly it creates a number of directories and files, including an app directory...
When I run laravel, I get command not found. Googling, I find that I should add ~/.composer/vendor/bin to my $PATH. The problem is that I don't have that directory. I do have ~/.composer/cache, but the cache directory is the only one I have in ~/.composer.
Any ideas on what to do? Am I missing a step? I've read a half dozen tutorials now on installing laravel. :-/
Sometimes Laravel is in the path ~/.config/composer/vendor/bin path. Try adding that path. But first make sure to go to that path and verify there is laravel.

PHPUnit - How to add vendor/bin into path?

I installed PHPUnit with composer. Everytime I run it, I have to call vendor/bin/phpunit. How can I put vendor/bin into path, so that next time I only need to call phpunit to run it?
You could add the current directory into your path.
For Linux/Mac add the following into your .bash_profile, Windows would be similar, alter the line below and add it into your PATH.
# include the current `vendor/bin` folder (Notice the `.` - This means current directory)
PATH="./vendor/bin:$PATH"
Remember to restart your terminal or resource your bash_profile.
Now you should be able to run: phpunit and it will automatically look for it within ./vendor/bin and if it exists it will execute using that.
If you are running on Homestead (or some other Linux/Ubuntu system):
alias p='vendor/bin/phpunit'
Then you can just type p and it will run your tests
If you are using Homestead - you can add this alias to your aliases file so it is always there.
Another easy solution, from the composer documentation, is to set your bin-dir setting to ./. This will install the binary in your root directory.
"config": {
"bin-dir": "./"
}
Then you can just run ./phpunit. I typically set bin-dir to bin, then type bin/phpunit. It's short enough for me.
If you already have phpunit installed, you will need to delete the vendor/phpunit directory and rerun composer install before composer will move the binary.

Installing Zend Framework 2 on XAMPP in Windows

I know this question may have appeared few times here and in the internet. But still I feel it is not clear for somebody who wanted to enter into the world of frameworks. I have followed these links Rob Allens Tutorial, ZF Quick Tutorial.
But some how I feel it is not quite clear with the installation part. I have a windows system basically Vista with the newest version of XAMPP installed. I have downloaded the latest version of ZFSkeletonApplication from this link ZFSkeletonApp, extracted the skeleton contents, renamed the folder to zendframework and moved it to xampp folder i.e now ZF skeleton is in c:\xampp\zendframework.
So until here everything seems clear and easy, from here I am some how lost with the configurations. Can some one elaborate the things from here how to install the Zf and make it work, like changes in the include paths, .htaccess files and so on. Please do remember that I have windows with XAMPP on it. If some one can guide me exactly for this set up, it would be helpful.
P.S. It would be good if one can provide info about the changes which I need to make with examples consisting of paths, so that I am not lost, for example like you can find .htaccess file here(ex pathname), changes in .htaccess file should be so and so.
Thanks
For future references, i also made a big post on how to install ZF2 on a windows xampp environment right here Install ZF2 on Windows Xampp
OK, i have done this on multiple systems now. For a home system the following steps work quite well:
Download msysGit and install it to any directory
Run the git-cmd.bat from the msysGit-Folder
Move into the directory you want i.e. C:\xampp\htdocs\ (this is done via cd dirname or cd .. to go up a level, change partition with D: and hit enter)
Run the following command. The <OptionalFolderName> would be the name of a Sub-Directory of htdocs, if you skip this, the folder will get named ZendSkeletonApplication
git clone git://github.com/zendframework/ZendSkeletonApplication.git <OptionalFolderName>
Possible Trouble Scenario (fatal:unable to connect to github.com)
Once again at workplaces, pretty often the default port (9418) for the git-protocol is blocked. If this is the case for you, then you should try one of the following Commands
git clone https://github.com/zendframework/ZendSkeletonApplication.git <OptionalFolderName>
git clone git#github.com:zendframework/ZendSkeletonApplication.git <OptionalFolderName>
Now you are not done yet. The skeleton Application is installed, but the framework is still missing, here some people might run into the first problems, but this actually is quite easy.
We're still at the command line interface
cd <OptionalFolderName> or cd ZendSkeletonApplication depending on what you did earlier
php composer.phar self-update
php composer.phar install (this might take a while)
So, this is the part where lots of things can happen. I have two scenarios happened to me:
Scenario #1 No directory write permissions
This is easily handled by running the command line interface with administrator privileges
Scenario #2 Working behind a router (i.e. at work)
Personally i didn't have to do much to get this working, but the line might change depending on your proxy. Personally i did the following at the command line interface
SET HTTP_PROXY=http://proxy.domain.tld:8080 you might also be good with
SET HTTP_PROXY=proxy.domain.tld:8080 don't ask me why, but i needed the http://
With all those done, you should have an almost running ZendSkeletonApplication. The other part is how to set up your virtual host, but i won't go into detail on this, as that's even ZF1 Stuff and everyone should be familiar with that by now, if not, there's good resources to learn out there.
I hope i could be of help to you.
Setbacks have to install in Windows, but I ended up finding a solution. From ZF2 to install on windows via git, for this is the only use that simulates msysGit git linux on windows, for it is only access the tutorial: http://zf2.com.br/tutoriais/post/instalando-o-git-no-windows-para-fazer-a-instalacao-do-zf2-somente-no-comando-do-windows-via-composer
Since I had lot dependency extension problems (mostly .dll files) with old version of XAMPP, so first thing I did was made sure I uninstall all previous versions of PHP already present on my system as well as old XAMPP. Then installed latest XAMPP v3.2.2 (using latest XAMPP 3.2.2-32-bit on Win-7-64-bit). Then followed installation steps in XAMPP Documentation under title Start a New Zend Framework 2 Project.
I had issues while installing composer also with old-XAMPP, but somehow those errors didn't appear during composer installation this time. And, I successfully installed ZEND till I typed http://localhost:8081/myapp/ (I renamed my ZendSkeletonAppliction folder as myapp as per documentation) into my browser to access the same and met the error which said:
Fatal error: Uncaught RuntimeException: Unable to load ZF2. Run php composer.phar install or define a ZF2_PATH environment variable. in C:\xampp\apps\myapp\htdocs\init_autoloader.php:51
Stack trace:
#0 C:\xampp\apps\myapp\htdocs\public\index.php(18): require()
#1 {main} thrown in C:\xampp\apps\myapp\htdocs\init_autoloader.php on line 51
Composer.phar was not even present the first time I downloaded ZendSkeletonApplication‐master.zip from Github (there was only composer.json and composer.lock files present). Anyhow I didn't need them since I followed XAMPP Doc which doesn't call composer.phar in command line:
composer create‐project ‐s dev zendframework/skeleton‐application path/to/install
I am not that tech-savvy to know how to 'define a ZF2_PATH environment variable' correctly, so I wasted time looking for solution online, couldn't find any (which is when I stumbled on this forum which also turned out not to have a solution for my query). In the end, in a fit of depression and anxiety, serendipity happened. All I did was as per XAMPP's ZEND documentation I right-clicked inside C:\xampp\apps\myapp\htdocs folder and clicked 'Composer Install' which reinstalled the Zend files from cache. Then refreshed http://localhost:8081/myapp/ and the Zend intro page appeared.
I just did it like that:
D:\web_dev\zendapp>C:\PHP\php.exe composer.phar self-update
it worked perfectly

Zend_Tool problem

This is the third time I'm installing zend studio and zend server now these two are installed succesfully (after half a day). But when I'm trying to create a new project I always get this zf error...
`
*************** ZF ERROR ****************
In order to run the zf command, you need to ensure that Zend Framework
is inside your include_path. There are a variety of ways that you can
ensure that this zf command line tool knows where the Zend Framework
library is on your system, but not all of them can be described here.
The easiest way to get the zf command running is to give it the include
path via an environment variable ZEND_TOOL_INCLUDE_PATH or
ZEND_TOOL_INCLUDE_PATH_PREPEND with the proper include path to use,
then run the command "zf --setup". This command is designed to create
a storage location for your user, as well as create the zf.ini file
that the zf command will consult in order to run properly on your
system.
Example you would run:
$ ZEND_TOOL_INCLUDE_PATH=/path/to/library zf --setup
Your are encourged to read more in the link that follows.
Zend_Tool & CLI Setup Information
(available via the command line "zf --info")
* Home directory found in environment variable HOMEPATH with value \Users\admin
* Storage directory assumed in home directory at location \Users\admin/.zf/
* Storage directory does not exist at \Users\admin/.zf/
* Config file assumed in home directory at location \Users\admin/.zf.ini
* Config file does not exist at \Users\admin/.zf.ini
To change the setup of this tool, run: "zf --setup"
ok (took 0:04.038)
`
I've already set the ZF_INCLUDE_PATH via command line with a new zend-framework library.
I never had a clean install with anything related to zend.
Could someone help me with this?
Thanks
I presume from the paths you are working on a windows machine. Zend Studio uses the zend tool (zf.bat in windows) to create a project. To make it work you must have properly installed the zend tool, i.e. you must be able to open a console (WINDOWS+R, type cmd, type enter) and successfully run the zf command.
In your case probably is a path issue, that you can resolve following the instructions here: http://framework.zend.com/manual/en/zend.tool.framework.clitool.html#zend.tool.framework.clitool.setup-windows
In particular:
The most common setup in the Windows Win32 environment, is to copy the zf.bat and zf.php into the same directory as your PHP binary. This can generally be found in one of the following places:
C:\PHP
C:\Program Files\ZendServer\bin\
C:\WAMP\PHP\bin
You should be able to run php.exe on the command line. If you are not able to, first check the documentation that came with your PHP distribution, or ensure that the path to php.exe is in your Windows PATH environment variable.
The next order of business is to ensure that Zend Framework library is set up correctly inside of the system PHP include_path. To find out where your include_path is located, you can type php -i and look for the include_path variable, or more succinctly execute php -i | grep include_path if you have Cygwin setup with grep available. Once you have found where your include_path is located (this will generally be something like C:\PHP\pear, C:\PHP\share, C:\Program%20Files\ZendServer\share or similar), ensure that the contents of the library/ directory are put inside your include_path specified directory.
If you are running on Ubuntu or Debian--or maybe Linux in general--it now seems you must create the environment variable ZEND_TOOL_INCLUDE_PATH. Having zend framework in your include_path (or copying zend framework to you existing include_path) no longer seems to work.
To manually install the latest version zend framework on Ubuntu/Debian, this is what I did after downloading ZF and extracting it to ~/temp
sudo cp -R ~/temp/ZendFramework-1.11.11/library/Zend /usr/share/php
sudo cp -R ~/temp/ZendFramework-1.11.11/extras/library/ZendX /usr/share/php
sudo cp ~/temp/ZendFramework-1.11.11/bin/zf.sh /usr/bin
sudo cp ~/temp/ZendFramework-1.11.11/bin/zf.php /usr/bin
Next edit /etc/environment, if you want other programs, like Netbeans, to be able to invoke zf.sh. Edit ~/.pam_environment, if you want only the current user to execute zf.sh. Add this line:
ZEND_TOOL_INCLUDE_PATH=/usr/share/php
You may need to log out and log back in after doing this.

Resources