Add PEAR packages to Subversion repository? - php

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?)

Related

Running composer in a different directory than current

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.

Using Composer PHP on Shared Space

I'm using Bluehost and do have access to SSH, thankfully. I've also set my PHP to 5.4 in the Control Panel settings. Now, here's the two big questions that I can't seem to grasp: how do I install Composer and furthermore, after installing Composer, how do I get the dependencies included?
In this case, I am attempting to use the official Tumblr PHP Library, which has dependencies -- all of which can be found on Packagist.
I've referred to this question in which the OP is using HostGator. I have attempted to install Composer in a similar fashion and have done so with seemingly successful results. The issue, however, is that I don't know where to install it on Bluehost so I now have Composer installed in several random places on the server simply because I don't know how to navigate to find where to put it in this shared space.
I know this is the issue (i.e. it's installed in the wrong place) because when I use the composer phar files and syntax to install the packages, I get errors saying the commands don't exist.
I really hate asking for hand-holding assistance, but if someone could walk me through the proper installation of Composer on a shared space and the proper installation of a Composer package from Packagist on the same shared space, it would be much appreciated. I've dug through the Composer documentation and can't seem to find a proper guide -- if one can even exist -- for this case. At this point, I'm wondering if it's going to be different for every web host.
Once you install composer as mentioned by KLVTZ. In the bluehost environment, use the php-cli instead of php.
php-cli composer.phar install
When installing composer, the biggest problem I ran into was that Bluehost's command line php was 5.2 and composer needs 5.3+.
Fortunately, Bluehost does give you access to 5.4. You can find it at
/ramdisk/php/54/bin/php54-cli
I ended up setting up an alias to call composer.phar using the above php command and it's worked great. You can see more details on how to install composer on bluehost.
You should probably not use Composer on the remote host, but instead install it on the local machine that is used to upload your project to Bluehost. There you can manage all the stuff that is needed to fetch the dependencies, which might include having the ZIP extension enabled or having a ZIP program available, having GIT or Mercurial installed if you have to grab a version from a branch, and so on.
All these dependencies of using Composer might not be available on that remote host, and frankly: You really do not want to install these development tools on a production machine anyway, I think. Any software that potentially helps an attacker shouldn't be present if it can be avoided.
The issue, however, is that I don't know where to install it on Bluehost...
In order to fix this problem, you need to figure out where exactly your project folder is. Composer needs to be installed in that folder. If you have access to a UNIX shell, I recommend that you change your directory to that project folder
cd $_SERVER['DOCUMENT_ROOT']/project_folder/
Generally, your remote server will follow the same file directory tree as that on your local machine. However, if you are unsure as to how your file structure may be organized, you can always print working directory of your local machine:
pwd
After you have successfully located the correct file path on your shared space, simply install composer:
curl -sS https://getcomposer.org/installer | php
This will report back something like:
All settings correct for using Composer
Downloading...
Composer successfully installed to: /var/www/my_project/composer.phar
Use it: php composer.phar
You now have access to your composer.phar in your project. Let me know if you need any further help.
One problem on Bluehost is that the php command on Bluehost does not execute php-cli. So I "bypass" that by having my own php script earlier in the PATH and then forwarding the arguments to php-cli. In the same process I made script named composer which calls php-cli composer.phar directly.
So, this setup has worked for me on Bluehost:
In ~/bin I have the composer.phar and two bash scripts called php and composer. In ~/.bash_profile I have prepended ~/bin to my PATH.
~/bin/php looks as follows:
#!/bin/bash
php-cli "$#"
~/bin/composerlooks as follows:
#!/bin/bash
php-cli ~/bin/composer.phar "$#"
And the additions to ~/.bash_profile are these:
PATH=$HOME/bin:$PATH
PATH=$PATH:$HOME/.composer/vendor/bin
export PATH
(I have also added ~/.composer/vendor/bin as can be seen, this is handy for global access for some composed applications (for me that is laravel)).
Remember to source ~/.bash_profile. (Or reconnect)
I think you should do something like this.
In console
echo $PATH
Use one of these pathes
mv composer.phar {selected path}/composer
chmod +x {selected path}/composer
Now you can simply call composer everywhere
If you have composer installed in your root directory (under public_html), might be something related to PHP version. As Bluehost when chosing PHP version "Be aware that this only modifies your ~/public_html/php.ini file. If you choose to use PHP 5.4, you'll want to make sure your crons use "/usr/php/54/usr/bin/php" instead, as otherwise it will use PHP 5.2."
So you can try with the command
/usr/php/54/usr/bin/php-cli composer.phar install

How do I use terminal to install plugins and libraries for PHP (MAMP)?

Can you walk me through the installation of a library for php, specifically what each terminal command does?
I have been learning web development for 6 months and it is time I need the console / terminal. I can't find any beginner walkthrough of using the terminal to add libraries and plugins to PHP. There are a lot of tutorials for specific steps or errors, but none start to finish.
If you want specifics to make your example concrete, here is what I am trying to install:
The library I am installing: http://code.google.com/p/phpquery/.
My directory for PHP on MAMP: /Applications/MAMP/bin/php/php5.3.6/bin
Thanks!
Don
edit:
I figured out my specific issue, but I don't think I really understand what I did, so I can't repeat it by myself in any other situation. This thread can help a lot of new terminal users including myself. The type of response I am looking for would go like this:
Step 1: Open your terminal. (This is an alternative way to navigate and execute commands on files on your computer).
Step 2: Find out where MAMP is installed however you like. Then go to your terminal, and type in cd followed by the path. cd stands for current directory and tells your terminal where it should execute its commands. The command you use will be very similar to this cd /Applications/MAMP. This will make your current directory MAMP.
Step 3: You are adding a library to PHP. So you need to go to the PHP folder in MAMP.... (please help us from this part!)
I just checked and it is available in pear channels.
# this is from their site
pear channel-discover phpquery-pear.appspot.com
pear install phpquery/phpQuery
Of course, for Mac using MAMP, you would use commands like this:
/Applications/MAMP/bin/php5/bin/pear install [package]
So for PHPQuery, try this:
/Applications/MAMP/bin/php5/bin/pear channel-discover phpquery-pear.appspot.com
/Applications/MAMP/bin/php5/bin/pear install phpquery/phpQuery
Same method should apply to pecl extensions as well.
EDIT
I personally just installed it on mine to test, here were my results:
$ /Applications/MAMP/bin/php5/bin/pear channel-discover phpquery-pear.appspot.com
Adding Channel "phpquery-pear.appspot.com" succeeded
Discovery of channel "phpquery-pear.appspot.com" succeeded
$ /Applications/MAMP/bin/php5/bin/pear install phpquery/phpQuery
downloading phpQuery-0.9.5.386-pear.tgz ...
Starting to download phpQuery-0.9.5.386-pear.tgz (100,990 bytes)
......................done: 100,990 bytes
install ok: channel://phpquery-pear.appspot.com/phpQuery-0.9.5.386
This should work with any PEAR or PECL extension. Check out this page for a list of PEAR packages.
EDIT 2
Make sure /Applications/MAMP/bin/php5/lib/php is in your include path! That is where phpQuery.php will be located once you've downloaded the PEAR packages properly with MAMP.
EDIT 3
Per cshu's comment, he mentioned that these packages are no longer maintained and that you should use this instead:
$ /Applications/MAMP/bin/php5/bin/pear channel-discover pear.querypath.org
$ /Applications/MAMP/bin/php5/bin/pear install querypath/QueryPath

Where is PHPUnit?

Resolved!
I uninstalled phpunit from pear and then reinstalled it again. I believe I was using the wrong/old/not enough sources before installing. Works like a charm!
So I'm trying to set up PEAR & PHPUnit. I was following http://www.newmediacampaigns.com/page/install-pear-phpunit-xdebug-on-macosx-snow-leopard but after I installed pear I had a different directory structure in /usr/local. Regardless, I was able run the phpunit install. But now I'm lost and asking for help before I make a bigger mess :)
pear config-show says:
PEAR directory php_dir /usr/local/share/pear
And my php.ini file (and confirmed in phpinfo() says:
include_path=".:/usr/local/share/pear"
So that's good, right? But now what? I get
Failed opening required 'PHPUnit/Framework.php' (include_path='.:/usr/local/share/pear')
If I try to include it in the php. And I have no idea where the binary might be to run it from the command line.
Inside /usr/local/share/pear/PHPUnit there are two directories "Extensions" and "Framework"
It sometimes happen that the install fails on PHPUnit specifically, but succeeds on the dependencies, so it only looks like the install was succesfull.
Try this when installing
pear install --force --alldeps phpunit/PHPUnit
The --force option will force the install of PHPUnit, even if all the dependencies can't be met. In my case there was a missing dependency for the dom PHP extension which blocked the installation even though the PHP_Invoker package could be used instead.
The --alldeps option makes sure that all of the dependencies got installed.
Check for a bin directory in the pear install, something along the lines of /usr/local/share/pear/bin/ - your install is different than mine..
You could also try searching for the binary -
find /usr/local/share/pear -name 'phpunit'

Is my PEAR package installation okay?

I want to install PEAR's Mail package. I went through the Terminal and installed Mail and its dependencies. The files were saved to my /usr/lib/php directory. In that lib directory I also have a 'PEAR' directory but my new packages weren't saved there. Do I need to drop the new packages into the PEAR directory or is it okay to let them sit in the usr/lib/php dir where they were installed?
You should install the package the official way via the installer:
pear install mail
It takes care of putting the files in the right directories.

Categories