How to install Zend Framework 2 Tool with composer - php

I can't figure out how to run zf.php (Zend Framework 2 Tool) when bootstrapped with composer.
First I bootstrap composer and zftool according to the documentation:
$ mkdir tmp && cd tmp
$ curl -s https://getcomposer.org/installer | php
$ ./composer.phar require zendframework/zftool:dev-master
This works fine so far.
But when I try to run zf.php, I get errors:
$ vendor/zendframework/zftool/zf.php
PHP Warning: require_once(/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php): failed to open stream: No such file or directory in /Users/seb/tmp/vendor/zendframework/zftool/zf.php on line 13
Warning: require_once(/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php): failed to open stream: No such file or directory in /Users/seb/tmp/vendor/zendframework/zftool/zf.php on line 13
PHP Fatal error: require_once(): Failed opening required '/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php' (include_path='.:/opt/local/lib/php') in /Users/seb/tmp/vendor/zendframework/zftool/zf.php on line 13
Fatal error: require_once(): Failed opening required '/Users/seb/tmp/vendor/zendframework/zftool/vendor/autoload.php' (include_path='.:/opt/local/lib/php') in /Users/seb/tmp/vendor/zendframework/zftool/zf.php on line 13
What am I doing wrong? I'm using PHP 5.3.21 on Mac.
I also tested it on my Debian VServer with PHP 5.4, same error :(

You should copy zf.php into your root directory and run it from there.
$ mkdir tmp && cd tmp
$ curl -s https://getcomposer.org/installer | php
$ ./composer.phar require zendframework/zftool:dev-master
$ cp vendor/zendframework/zftool/zf.php .
$ php zf.php

Install Composer.phar locally
If you do not have the composer globally installed on your machine, you can install it locally in the project.
Installing Composer locally is a matter of just running the installer in your project directory (https://getcomposer.org/doc/00-intro.md).
curl -sS https://getcomposer.org/installer | php
Note: If the above fails for some reason, you can download the installer with php instead:
php -r "readfile('https://getcomposer.org/installer');" | php
Install ZF2
git clone git://github.com/zendframework/ZendSkeletonApplication.git --recursive
cd ZendSkeletonApplication
php composer.phar self-update
php composer.phar install
Install ZFTools (Installation using Composer)
php composer.phar require zendframework/zftool:dev-master
php composer.phar install
Create a symbolic link
zf.php (Zend Tool) will be installed in the vendor/bin folder. You may run it with php vendor/bin/zf.php.
ln -s vendor/zendframework/zftool/zf2.bat zftools
chmod +x zftools
./zftools
In this case, I prefer symbolic link, for updating the zftools repository, I do not need to copy the file again.
Without installation, using the PHAR file
Another alternative to using the ZF tools, without creating scripts or aliases, and download the PHAR format.
wget https://packages.zendframework.com/zftool.phar --no-check-certificate
php zftool.phar version
ZFTool - Zend Framework 2 command line Tool
The ZFTool is using Zend Framework 2.2.4
Or you can download zftool.phar and use it.
Note 1:The #akond response is very good, I'm just presenting an alternative answer I like to use.
Note 2: This example was done on a windows machine using cygwin.
Good tutorial installation (ZF2 and ZF3)
Getting started: A skeleton application
Ref:
Zend Framework Tool (ZFTool)

Related

Jenkins user cannot run composer install

I am trying to run the composer installer from Jenkins project folder as Jenkins user.
/usr/local/bin/composer install
I get the message
Content-type: text/html
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI
Composer could not find a composer.json file in /usr/local/bin
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" section
I don't know why it is looking for composer.json inside usr/local/bin.
If I run this as the root user it works. Can someone explain what I am doing wrong?
this is my environment
pwd
/var/lib/jenkins/workspace/project_staging
whoami
jenkins
You should be able to install composer using the following instructions:
curl -sS https://getcomposer.org/installer | php56
In order to avoid any issues
cd ~/bin
ln -s /usr/local/bin/php56 php
Modify your ~/.bash_profile file and change:
PATH=$PATH:$HOME/bin To `PATH=$HOME/bin:$PATH`
Then close your SSH session and start a new one, or run:
source ~/.bash_profile
Then ~/bin path will then take precedence and you will be using the correct version of PHP.

Composer Server won't load vendor file into server root

I started looking into using composer for my php project. i have MAMP Pro and would like to continue to use that for my development hosting. The problem is that I can't get composer to run anywhere accept in my /Users/***/ folder (where it runs really well). How would I get it to run in the root of my MAMP Server? I have messed with the .bash_profile file adding the following lines:
alias composer='php composer.phar'
export PATH=/Applications/MAMP/bin/php/php7.0.10/bin:$PATH
That does not work (and neither does the alias). The vendor file still shows up in the /Users/***/ folder.
Any help would be greatly appreciated!
You can do a global installation:
Since Composer works with the current working directory it is possible to install it in a system wide way.
1.Change into a directory in your path like cd /usr/local/bin
2.Get Composer curl -sS https://getcomposer.org/installer | php
3.Make the phar executable chmod a+x composer.phar
4.Change into a project directory cd /path/to/my/project
5.Use Composer as you normally would composer.phar install
Update: Sometimes you can't or don't want to download at /usr/local/bin (some have experienced user permissions issues or restricted access), in this case you can try this
Open terminal
curl -sS http://getcomposer.org/installer | php -- --filename=composer
chmod a+x composer
sudo mv composer /usr/local/bin/composer
Ok after looking at it a little bit more here's what I figured out using #Lokesh Gamot's answer and the composer site. Again, this is geared to use with MAMP.
Find the path of your development server. I would suggest putting var_dump(getcwd()); at the top of your index.php file to get the path to show up on your index page. For me, it was /Applications/MAMP/htdocs/.../web-root
Because I wanted composer in my server root, I inputted cd "/Applications/MAMP/htdocs/" into the terminal.
I then downloaded the file using curl -sS https://getcomposer.org/installer | php -- --filename=composer. This installs Composer into "/Applications/MAMP/htdocs/" as a file named composer.
When I begin a new project, I have to move the composer file into the project root using mv composer "/Applications/MAMP/htdocs/*Destination Root*" and then navigate the terminal to that same root by using: cd "/Applications/MAMP/htdocs/*Destination Root*". What I was missing was needing to move the composer file around to each root when I needed it.
After that, I can use composer using php composer. Again, thanks!

Install and integrate tcpdf in php scripts on Debian 8

I have a Debian 8 distribution and am trying to get the tcpdf php library running for generating pdf documents. I notice that it is already installed as a package when searching for it in Synaptic Package Manager. It's version 6.0.093+dfsg-1 and its location is /usr/share/doc/php-tcpdf. I looked around online for instructions and tutorials for using the library in my php scripts but haven't found anything explicit and instructive. Neither do the official sites: https://tcpdf.org/ and https://github.com/tecnickcom/tc-lib-pdf offer any setup, installation, or integration documentation.
I downloaded the TCPDF-master.zip from https://github.com/tecnickcom/TCPDF , pasted it into my /var/www/html/ directory, but when I try running one of the examples, or the index.php file, the browser just gives me the following error:
The localhost page isn’t working localhost is currently unable to handle this request. HTTP ERROR 500
The error.log file at /var/log/apache2 displays:
PHP Fatal error: Unknown: Failed opening required '/var/www/html/tcpdf/examples/example_001.php' (include_path='.:/usr/share/php:/usr/share/pear') in Unknown on line 0
I received the same errors even after installing PEAR and also when trying to run the fpdf library.
Please instruct me to follow the proper procedure on correctly using this library. Thanks.
First, install composer as described at http://www.bravo-kernel.com/2014/08/how-to-install-composer-on-debian/ . Make it globally available by running the following commands while logged in the terminal as user:
$ cd /usr/src
$ sudo apt-get install curl php5-cli
$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
If the terminal responds with the following errors:
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
a system restart might be needed due to a possibility of apt-get (or some GUI frontend to it) being halted while executing, leaving apt in a locked state.
Verify the installation:
$ composer --version
which should output:
Composer version 1.3.0 2016-12-24 00:47:03
or something similar.
Afterwards, navigate to the desired directory within terminal where you want to locally install the composer dependency. For instance: /var/www/html/ which is the web root on Debian. Input the command for installing the tcpdf php library:
composer require tecnickcom/tcpdf
as stated at https://packagist.org/packages/tecnickcom/tcpdf
All should now operate as intended.

Running Composer returns: "Could not open input file: composer.phar"

I am new to symfony2 and reading symblog. In third chapter while trying with data-fixtures I tried the command:
php composer.phar update
but I got the error:
Could not open input file: composer.phar
So I googled a little and tried
php composer.phar install
but still getting the same error. So please guide how to deal with this composer to install new extentions or bundles like data-fixtures in symfony2 using wamp.
If you followed instructions like these:
https://getcomposer.org/doc/00-intro.md
Which tell you to do the following:
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
Then it's likely that you, like me, ran those commands and didn't read the next part of the page telling you to stop referring to composer.phar by its full name and abbreviate it as an executable (that you just renamed with the mv command). So this:
$ php composer.phar update friendsofsymfony/elastica-bundle
Becomes this:
$ composer update friendsofsymfony/elastica-bundle
I had the same problem on Windows and used a different solution. I used the Composer_Setup.exe installation file supplied by the composer website and it does a global install.
After installing, make sure your PATH variable points to the directory where composer.phar is stored. This is usually C:\ProgramData\ComposerSetup\bin (ProgramData might be a hidden directory). It goes without saying, but also be sure that the PHP executable is also in your PATH variable.
You can then simply call
composer install
instead of
php composer.phar install
Background
It is helpful to know that there are two ways to install (and use) Composer: locally as a file in your project directory, or globally as a system-wide executable.
Installing Composer locally simply means that you are downloading a file (composer.phar - which is a PHP Archive) into your project directory. You will have to download it for every project that requires Composer.
Like a regular PHP file that you want to execute on the command line, you will have to run it with PHP:
php composer.phar update
Which basically tells the php executable to run the file composer.phar with update as argument.
However, if you install it globally, you can make composer itself executable, so you can call it without php (and don't have to download it for every project). In other words, you can use composer like this:
composer update
Since you are executing php composer.phar update, and you are getting the error Could not open input file: composer.phar, you probably don't have composer.phar in your current directory.
Solution
If you have Composer installed globally, simply run composer update instead of php composer.phar update.
If you don't have Composer installed yet, download the PHAR using the following command:
curl -sS https://getcomposer.org/installer | php
This will download the installer and run it using php. The installer will download the actual Composer PHAR to your current working directory, and make it executable.
To install Composer globally (I recommend this), copy the file to a location in your PATH. The exact location differs per operating system and setup, see https://getcomposer.org/doc/00-intro.md#globally for more information.
Personally, I prefer to install Composer in my home directory so I don't need sudo to install or update the composer executable (which can be a security risk). As I'm on Linux, I use the following command:
mv composer.phar ~/.local/bin/composer
If anyone else came this low on the page and still didn't find a working answer (like I did), use this:
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer.phar
$ alias composer='/usr/local/bin/composer.phar'
$ composer --version
et voila! A working composer :-)
To solve this issue the first thing you need to do is to get the last version of composer :
curl -sS https://getcomposer.org/installer | php
I recommend you to move the composer.phar file to a global “bin” directoy, in my case (OS X) the path is:
mv composer.phar /usr/local/bin/composer.phar
than you need to create an alias file for an easy access
alias composer='/usr/local/bin/composer.phar'
If everything is ok, now it is time to verify our Composer version:
composer --version
Let's make composer great again.
I found this worked as I did not have curl installed. On Windows 8 with XAMPP installed. It will add it to your local build I use .gitignore to avoid the repo
php -r "readfile('https://getcomposer.org/installer');" | php
I got it from here: https://getcomposer.org/download/
This worked for me:
composer install
Without
php composer install
Run the following in command line:
curl -sS https://getcomposer.org/installer | php
Yesterday I was trying to install Yii2 framework on Windows 10 and I have same problem(Could not open input file: composer.phar) running this command:
php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9
Issue is composer.phr file is not in current directory,you need to give full path composer.phr like
php C:\ProgramData\Composer\bin\composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9
Or you can create yii2 project using this command:
composer create-project yiisoft/yii2-app-advanced advanced 2.0.9
Or
composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9
I had the same issue. It is solved when I made composer globally available. Now I am able to tun the commands from any where in the folder.
composer update
composer require "samplelibraryyouwant"
Use this :
php -r "readfile('https://getcomposer.org/installer');" | php
Hi friends, follow the steps to fix this issue in MAC OS
Step 1: first run the command in Terminal with your project directory
$ curl -sS https://getcomposer.org/installer | php
Step 2: Move the composer.phar in your project directory
$ mv composer.phar /Applications/MAMP/htdocs/bashrushAPI/composer.phar
Step 3: Setup alias the composer
$ alias composer='/Applications/MAMP/htdocs/bashrushAPI/composer.phar'
Step 4: Check the composer version now
$ composer --version
Composer version 1.7.2 2018-08-16 16:57:12
Step 5: Confirm the project folders and file placed on bellow
$ ls
CONTRIBUTING.md docker-compose.yml templates
README.md logs tests
composer.json phpunit.xml vendor
composer.lock public
composer.phar src
Step 6: Now update composer
$ composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Step 7: Run your sample project
$ php composer.phar start
php -S localhost:8080 -t public
[Thu Sep 27 03:16:11 2018] ::1:51177 [200]: /
[Thu Sep 27 03:16:11 2018] ::1:51178 [404]: /favicon.ico - No such file or directory
Easy answer, navigate to the directory where you already have the composer.json file that you want to run (ideally your project folder) then download composer into the same folder, then instantly run the install command like so:
php composer.phar install
This will automatically find the composer.json and run your required scripts. Good luck. This stuff is a breeze for terminal wizards and totally bizarre to the rest of us
I am using windows 8.0. In my case to install or update i just use composer install or something else instead of php composer.phar. This worked for me
like
composer require google/apiclient:1.*
To googlers who installed composer via HomeBrew:
make a symbolic link for /usr/local/bin/composer
ln -s /usr/local/bin/composer /usr/local/bin/composer.phar
I got this error "Could not open input file: composer.phar" while installing Yii2 using below mentioned command.
php composer.phar create-project yiisoft/yii2-app-basic basic
Solutions which worked for me was, I changed the command to
composer create-project yiisoft/yii2-app-basic basic
I hope it help!
your composer.phar should be placed in above way.
For windows, I made composer.cmd and used the below text:
php c:\programs\php\composer.phar %*
where composer.phar is installed and c:\programs\php\ is added to my path.
Not sure why this isn't done automatically.
For Windows10 Pro, Following steps fix the issue. select properties check the Unblock program option. run the installer, run the command CMD with Admin rights. At command promp run composer --version to make sure it is globally installed. you should be able to now run composer require drush/drush This is for drush dependency using composer.
Command like this :
composer.phar require intervention/image
error: composer.phar: command not found
I solved the problem by following this process
i set the composer globally and renamed composer.phar to composer then run this command composer require intervention/image . and now it's working fine
Just open cmd as Administrator and go into your project folder and check it is working or not using composer command.
The above error is because of the composer is not accessible globally.
So you need to run "cmd" as Administrator.
This is working fine for me.
If you are using Ubuntu/Linux and you are trying to run
php composer.phar require intervention/image on your command line.
Use sudo composer require intervention/image instead. This will give you want you are looking for.
I had an issue getting a package.json's script to run composer dumpautoload.
I had the file /usr/local/bin/composer.phar, and also the file ~/.bash_profile (on OSX) contained:
alias composer="php /usr/local/bin/composer.phar"
This allowed composer to work from the command line, but it didn't allow scripts to execute composer.
The fix was this:
$ cd /usr/local/bin
$ mv composer.phar composer
$ sudo chmod +x composer // +x allows the file to be executable, such as by CLI scripts
But that yielded this error Could not open input file: /usr/local/bin/composer.phar
The fix was to update ~/.bash_profile (sudo nano ~/.bash_profile), and change the composer alias to:
alias composer="php /usr/local/bin/composer"
# ie: `.phar` extension removed
Now everything is behaving as expected.
Your composer.phar must be in Source files. I had same problem and I just cut my composer.phar into mine framework-standard-edition folder, where is my whole strong textproject.
if the composer is already install all you need is to know where the composer.phar file is (its directory) after that you move to your symfony project where you have the composer.json and from that directory you execute your composer.phar file. In windows here is what you have to do.
symfony project directory_where_composer.json_is>php the_directory_where_composer.phar_is/composer update
That's all
use two steps .
curl -sS https://getcomposer.org/installer | php
sudo php composer.phar update
You can do
curl -sS https://getcomposer.org/installer | php
The -sS flag meaning don't show progress, do show errors
and then
php composer.phar install
from:
How do I get cURL to not show the progress bar?
https://packagist.org/
I've reach to this problem when trying to install composer on a Window 7 machine from http://getcomposer.org/download page. As there was an existing compose version (provided by acquia Dev Desktop tool) the installation fails and the only chance was to fix this issue manually. (or to remove Dev Desktop tool composer).
Anyway the error message is quite straightforward (Could not open input file: composer.phar), we should then tell the system where the file is located.
Edit composer.bat file and should look like:
#SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;%PATH%
php.exe composer.phar %*
See that composer.phar doesn´t have a file path. When standing in a different folder than the one where composer.phar is located the system won´t be able to find it. So, just complete the composer.phar file path:
#SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;;%PATH%
SET composerScript=composer.phar
php.exe "%~dp0%composerScript%" %*
Reopen your window console and that should do the trick.
EDIT: this has an issue because it always uses %~dp0%composerScript%
folder as composer execution. Then all configurations are done in that
folder (besides standing on your current project folder) and not in your project folder.
So far I haven't found a was to make a manual composer installation to
work globally on Windows. Perhaps you should go ahead with composer for windows installation mentioned above.
Do not access the composer by
composer composer.pher install
use
composer install
You can just try this command if you're already installed the Composer :
composer update
or if you want add some bundle to your composer try this :
composer require "/../"

How can I fix the ZF tool in the Zend Server for windows?

I just downloaded Zend Server Community Edition for windows and found that it did not include the ZF utility included in the tutorials. I downloaded and unzipped the Zend Framework(version 1.7.8, because version 1.8 would not download properly). This includes the zf.bat utility which is meant to generate the basic project files. Unfortunately, neither seem to include the CodeGenerator package which is required for the tool to operate. The error I receive is:
H:\zend>zf
Warning: require_once(Zend/CodeGenerator/Php/File.php): failed to open stream: N
o such file or directory in D:\Simon\code\zend\ZendServer\share\ZendFramework\in
cubator\library\Zend\Tool\Project\Context\Zf\ControllerFile.php on line 4
Fatal error: require_once(): Failed opening required 'Zend/CodeGenerator/Php/Fil
e.php' (include_path='D:\Simon\code\zend\ZendServer\share\ZendFramework\incubato
r\library;D:\Simon\code\zend\ZendServer\share\ZendFramework\library;.;D:\Simon\c
ode\zend\ZendServer\share\ZendFramework\library') in D:\Simon\code\zend\ZendServ
er\share\ZendFramework\incubator\library\Zend\Tool\Project\Context\Zf\Controller
File.php on line 4
I have been searching around and found a few discussions. Some other have had the same problem, and fixed it by checking out the latest svn with the following commands:
cd $PATH_TO_ZF/ZendFramework-1.7.7
cp -r incubator/library/Zend/Tool/ library/Zend/
cp -r incubator/library/Zend/Reflection/ library/Zend/
cd library/Zend/Tool
mkdir CodeGenerator
cd CodeGenerator
svn co http://framework.zend.com/svn/framework/standard/incubator/library/Zend/CodeGenerator .
cd ..
find . | grep -v .svn | xargs perl -pi -e "s|Zend/CodeGenerator|Zend/Tool/CodeGenerator|g"
find . | grep -v .svn | xargs perl -pi -e "s|Zend_CodeGenerator|Zend_Tool_CodeGenerator|g"
Unfortunately, the latest svn doesn't have CodeGenerator either.
In the intervening time since I wrote this question and submitting it, I discovered a potential workaround. Once the msi installer for the Zend server has run its course, issue the following commands from a cmd prompt:
cd <wherever you installed the server>\ZendServer\share
rd /S /Q ZendFramework
mkdir ZendFramework
cd ZendFramework
svn co http://framework.zend.com/svn/framework/standard/trunk/ .
Then, make sure that
<wherever you installed the server>\ZendServer\share\ZendFramework\bin
Is in your PATH environment variable. The zf command now seems to work.

Categories