I need to set up a composer.json with server requirements (e.g. php >= 5.6, lib-xml, etc). There are some examples in composer documentation, but what I need is a method to get a composer alias (ext-xxx, lib-yyy, etc) for a given PHP extension or library (e.g. php7.1-curl - Ubuntu package name).
Partial answer
composer show -p
Gives a list of extensions/libraries installed on the current system. So the solution is:
On a local linux/unix, install the library/extension in question (eg. apt install php-curl)
Filter the list of libraries recognized by composer to find the right result
composer show -p | grep curl
Related
I found there are two options to install PHP package globally in Linux (Ubuntu 16.04):
Using composer:
composer global require symfony/finder
The package will be located at ~/.config/composer/vendor/
Using apt-get:
apt-get install php-symfony-finder
The package will be located at /usr/share/php/
This directory /usr/share/php/ is also in default PHPs include_path (I have PHP 7.2)
There are several questions I have:
Why would I want to install package globally ?
I know it's useful to install php tools globally, like phpunit - It has binary file and it allows you to run tests everywhere, so you don't have to install it in every project.
But what about symfony/finder for example ? What is particular use of this package installed globally ?
What is the difference between 1 and 2 option ?
Does it have any different use cases or different effects ?
Why would I want to install package globally ?
Normally, these are dependencies you want to use in almost every project, because they are available at a system level you can use them without duplicating their dependencies in every application you create.
For example, in my case I have php_md, php_cs for code formatting, phpunit for testing.
What is the difference between 1 and 2 option ?
Both are package managers, they make sure every package installed has the correct dependencies, so their core functionality is similar.
Now, they have several differences:
Their focus in the packages they manage, composer is specific for php based packages but apt-get is for Linux and more system level oriented.
Their package database, composer uses packagist and apt-get uses a selection of repositories and ppas (you can find them in /var/lib/apt/lists/).
The package selection, since composer is specialized in php you can expect a wider variety in anything php related.
In conclusion, you can clearly make it work with both, but I would recommend you to keep everything php related on composer, unifying them under the same manager.
Any other difference or correction I've overlooked is welcome.
I don't know if this question has been asked, because searching finds results mostly about moving the libraries installation directory.
I have a globally installed composer command. Is there a way to run, for example, composer install in a different directory than current, i.e. to specify the directory in which I would like tu run the command?
E.g. being in /home/someuser, I would like to acquire the same result as in running composer install it inside /home/someuser/myproject. Of course, one way would be to simply change the current directory, run composer and go back.
Try composer install -h. There you'll find an option --working-dir (or -d). And that's what you're looking for.
Then run:
composer install --working-dir=/home/someuser/myproject
You can find more in composer docs.
Depending on your operating system, the = might need to be removed:
composer install --working-dir /home/someuser/myproject
In addition to the above answer from Tomáš Votruba i had to append the = charachter on OSX. So the full command would be:
composer install -d=/home/someuser/myproject
My first post on SO so was unable to simply add this as a comment.
This works for me, PHP 7.3 on ubuntu 18.04
Install
composer install --working-dir=/your_composer_dir
Update
composer update --working-dir=/your_composer_dir
I tried what others said, but it was giving me: Invalid working directory specified 'PATH' does not exist. Although it was my working dir that contained composer.json!
I don't know why anyway, but this worked for me (only for gnu/linux users):
composer --working-dir=$(pwd)
And by the way, if you had run composer -h, it would've told you the solution:
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
I am using a Windows machine with PHPStorm (terminal) and this worked for me.
composer install --working-dir /home/someuser/myproject
My Linux OS machines require me to use
composer install --working-dir=/home/someuser/myproject
Note: You may be able to substitute ~/ for /home/someuser/ if your path is super long.
Run:
cd /home/mysites/google.com
Then run:
composer require facebook/graph-sdk
Above steps will open up the directory named (google.com) and install facebook Graph SDK there.
Am actually in need to achieve converting integers into words in my application and i ran into the use of Pear but i seems not to understand what exactly they want me to do because where i got the information (http://www.techrepublic.com/article/converting-numbers-to-words-in-php/) assumes that its is already set in my computer. So please i need a clear guide on how to set it up in my server. I run WAMP (Apache version 2.4.4/Php version 5.4.16).
How to install PEAR on a WAMPServer PHP Version
Create a new folder called PEAR below the folder containing the version of PHP you want to install PEAR extension into. eg c:\wamp\bin\php\php.x.y.z\PEAR ( I like a UPPER case name here but it does not have to be that way )
If the file go-pear.phar does not exist in the php.x.y.z folder, get go-pear.phar from http://pear.php.net/go-pear.phar, and save it into the php.x.y.z folder, the version you are using and want to download to.
Then you have to make sure you have the php.exe file on the windows PATH
We do not want to do this permanantly as that would mess up WAMPServers ability to switch PHP versions at the click of a button So ignore any suggestions you may see, to put this on your actual Windows PATH environment variable permanantly.
So from the command line either do this :
path=%path%;c:\wamp\bin\php\phpx.y.z
( change x and y and z to the version numbers of your PHP )
Alternatively, I use a batch file which I save into a folder that is already on my windows path, lets call it phppath.bat and I add this to that file
path=%path%;c:\wamp\bin\php\phpx.y.z;
php -v
You can then start a command window anytime you like and just keyin >phppath and I have access to the php.exe in any folder I may wish to code up and run some php CLI source code.
Now from a command window make sure you are in wamp\bin\php\phpx.y.z and then keyin
CD \wamp\bin\php\php5.4.11
php go-pear.phar
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] : l
Please confirm local copy by typing 'yes' : yes
Below is a suggested file layout for your new PEAR installation. To
change individual locations, type the number in front of the
directory. Type 'all' to change all of them or simply press Enter to
accept these locations.
1. Installation base ($prefix) : c:\wamp\bin\php\php5.4.11
2. Temporary directory for processing : c:\wamp\bin\php\php5.4.11\tmp
3. Temporary directory for downloads : c:\wamp\bin\php\php5.4.11\tmp
4. Binaries directory : c:\wamp\bin\php\php5.4.11
5. PHP code directory ($php_dir) : c:\wamp\bin\php\php5.4.11\pear
6. Documentation directory : c:\wamp\bin\php\php5.4.11\docs
7. Data directory : c:\wamp\bin\php\php5.4.11\data
8. User-modifiable configuration files directory : c:\wamp\bin\php\php5.4.11\cfg
9. Public Web Files directory : c:\wamp\bin\php\php5.4.11\www
10. Tests directory : c:\wamp\bin\php\php5.4.11\tests
11. Name of configuration file : c:\wamp\bin\php\php5.4.11\pear.ini
12. Path to CLI php.exe : c:\wamp\bin\php\php5.4.11
1-12, 'all' or Enter to continue:
Beginning install...
Configuration written to D:\wamp\bin\php\php5.4.11\pear.ini...
Initialized registry...
Preparing to install...
installing phar://c:/wamp/bin/php/php5.4.11/PEAR/go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.7.tar...
installing phar://c:/wamp/bin/php/php5.4.11/PEAR/go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.3.0.tar...
installing phar://c:/wamp/bin/php/php5.4.11/PEAR/go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.9.4.tar...
installing phar://c:/wamp/bin/php/php5.4.11/PEAR/go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar...
installing phar://c:/wamp/bin/php/php5.4.11/PEAR/go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.2.1.tar...
install ok: channel://pear.php.net/Archive_Tar-1.3.7
install ok: channel://pear.php.net/Console_Getopt-1.3.0
install ok: channel://pear.php.net/Structures_Graph-1.0.4
install ok: channel://pear.php.net/XML_Util-1.2.1
install ok: channel://pear.php.net/PEAR-1.9.4
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
PEAR: To install optional features use "pear install pear/PEAR#featurename"
******************************************************************************
WARNING! The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<c:\wamp\bin\php\php5.4.11\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.
Would you like to alter php.ini <c:\wamp\bin\php\php5.4.11\php.ini>? [Y/n] : n
Please look over your php.ini file to make sure
c:\wamp\bin\php\php5.4.11\pear is in your include_path.
Current include path : .;c:\wamp\bin\php\php5.4.11\PEAR
Configured directory : c:\wamp\bin\php\php5.4.11\pear
Currently used php.ini (guess) : c:\wamp\bin\php\php5.4.11\php.ini
Press Enter to continue:
** WARNING! Old version found at c:\wamp\bin\php\php5.4.11, please remove it or be sure to use the new c:\wamp\bin\php\php5.4.11\pear.bat command
The 'pear' command is now at your service at c:\wamp\bin\php\php5.4.11\pear.bat
TEST THAT IS WORKS
>pear
Should show you something like this
C:\wamp\bin\php\php5.4.11>pear
Commands:
build Build an Extension From C Source
bundle Unpacks a Pecl Package
channel-add Add a Channel
channel-alias Specify an alias to a channel name
channel-delete Remove a Channel From the List
channel-discover Initialize a Channel from its server
channel-info Retrieve Information on a Channel
channel-login Connects and authenticates to remote channel server
channel-logout Logs out from the remote channel server
channel-update Update an Existing Channel
clear-cache Clear Web Services Cache
config-create Create a Default configuration file
config-get Show One Setting
config-help Show Information About Setting
config-set Change Setting
config-show Show All Settings
convert Convert a package.xml 1.0 to package.xml 2.0 format
cvsdiff Run a "cvs diff" for all files in a package
cvstag Set CVS Release Tag
download Download Package
download-all Downloads each available package from the default channel
info Display information about a package
install Install Package
list List Installed Packages In The Default Channel
list-all List All Packages
list-channels List Available Channels
list-files List Files In Installed Package
list-upgrades List Available Upgrades
login Connects and authenticates to remote server [Deprecated in favor of channel-login]
logout Logs out from the remote server [Deprecated in favor of channel-logout]
makerpm Builds an RPM spec file from a PEAR package
package Build Package
package-dependencies Show package dependencies
package-validate Validate Package Consistency
pickle Build PECL Package
remote-info Information About Remote Packages
remote-list List Remote Packages
run-scripts Run Post-Install Scripts bundled with a package
run-tests Run Regression Tests
search Search remote package database
shell-test Shell Script Test
sign Sign a package distribution file
svntag Set SVN Release Tag
uninstall Un-install Package
update-channels Update the Channel List
upgrade Upgrade Package
upgrade-all Upgrade All Packages [Deprecated in favor of calling upgrade with no parameters]
Usage: pear [options] command [command-options] <parameters>
Type "pear help options" to list all options.
Type "pear help shortcuts" to list all command shortcuts.
Type "pear help <command>" to get the help for the specified command.
C:\wamp\bin\php\php5.4.11>pear list-channels
REGISTERED CHANNELS:
====================
CHANNEL ALIAS SUMMARY
doc.php.net phpdocs PHP Documentation Team
pear.php.net pear PHP Extension and Application
Repository
pecl.php.net pecl PHP Extension Community Library
__uri __uri Pseudo-channel for static packages
My client cannot install anything besides what is available via Debian packages, and so installing Composer is not an option (unless a Laravel / Composer package exists).
The best solution would be if the client could just unzip the project along with all of its (Laravel, Composer) dependencies and it would just work.
Is something like this possible to achieve? How?
The best solution would be if the client could just unzip the project
along with all of its (Laravel, Composer) dependencies and it would
just work.
Yes - this will work
Is something like this possible to achieve? How?
Like you said - if you have the project running on your directory - just zip it up (including the /vendors folder) - and they can unzip it. There is no need to "install" Laravel.
Once unzipped - the client should still be able to run php artisan migrate to do the database table migrations
Edit: actually - why cant they just run
php -r "readfile('https://getcomposer.org/installer');" | php
or
curl -sS https://getcomposer.org/installer | php
Its not a package - but its installed via PHP? See composer install docs for more info.
I'm working on a project that'll use PEAR packages. Because you never know what version of the PEAR package will be installed on your hosting provider (and especially because I require a patch to have been applied to one of the packages), I'd like to put the PEAR source for my project right into SVN, so other developers can immediately have the dependencies.
But everything related to PEAR seems to have absolute directories! Running "pear config-create . pear.conf" to set up a new PEAR directory even fails with the error message:
Root directory must be an absolute path
I checked out the pear config files on some other servers and they, too, seem to have absolute paths.
Whenever a developer checks this out to his own machine, or we export it all to a server, we don't know what the absolute path will be.
Is there any way to set this up?
I couldn't get my Hosting provider to install the PEAR libraries I wanted. Here's how I made PEAR part of my source tree.
1. Create a remote.conf file
Creating your remote.conf is a little different than in the manual. Lets say I want to install PEAR in vendor/PEAR of a project. You would do it like this:
#from the root of the project
$ cd vendor ; mkdir PEAR ; cd PEAR
$ pear config-create <absolute path to project>/vendor/PEAR/ remote.conf
2.Update the channels
$ pear -c remote.conf channel-update pear.php.net
3. install PEAR
$ pear -c remote.conf install --alldeps pear
4. install any other libraries
$ pear -c remote.conf install --alldeps <libname>
Voila... PEAR is part of the source tree.
The Catches:
Even though the paths in remote.conf are absolute the libraries themselves will still work. It's just updating that won't work from anywhere. You will need to update it from the same path that it was created from -- in the above case, from vendor/PEAR.
Some libraries don't like being outside the path, so you may have to add vendor/PEAR to the path (I've got code, just ask if you need.)
If you have PHP 5.3.1 use Pyrus, the PEAR2 installer. The pyrus managed installations can be moved where ever you like.
Download pyrus -
$> wget http://pear2.php.net/pyrus.phar
Create a directory to store your pyrus-installed packages:
$> mkdir mylibs
Install packages -
$> php pyrus.phar mylibs install pear/Net_URL
Your installed package is now at mylibs/php/Net/URL.php
Note that we passed the mylibs directory to indicate what directory to install to, as well as the channel name 'pear' (the default in pyrus is pear2.php.net). For convenience, the pyrus.phar file can be executed from cli if you chmod +x it.
You can move the mylibs directory wherever you'd like. Even commit it to your repository.
Lots of docs on the PEAR website.
I'm note entirely sure if this answers your question, but you can specify the location for the PEAR repository on the commandline, so you can create a local repository, using:
pear install --force --installroot=/path/to/my/pear/ PEAR
Then you can install additional packages using:
pear install --installroot=/path/to/my/pear/ SomePackage
To use the local repo from within your app, you have to make sure that the include_path points to the local repo, rather than the default (globally installed) repository. So you'd want it to look like this:
include_path = ".:/path/to/my/pear/usr/share/php"
Re :
Actually, he wants to avoid the absolute paths so that the solution can be checked out from many machines without depending on the path each one has the repository installed.
-- Carlos Lima
Seems you're right. In that case, I would advice that you don't check the PEAR repository into your SVN repository, but rather use a deploy script to install/update the repository at the server. Just make sure to install a particular version. (You do have an automated deploy, right?)