Can I use composer without installing it? - php

I've noticed on a lot of open source user systems, like UserFrosting or Drupal they some how use composer, without the user actually having to install composer on to there server. I was just wondering how would I be able to do this, I've had a look around and can't find anyway of just using the files.
Thank you.

Yes, you could simply download the composer.phar file, and run it from CLI like:
cd ~/
wget https://getcomposer.org/composer.phar
php composer.phar [command]
You'll need at least PHP v5.6.x and the mcrypt extension installed for the CLI SAPI.

Related

Install Composer without curl (local)

I have to run a Laravel Project on a customers Server, Mcrypt is already installed but I can't run "composer install" because composer is missing. Problem here is, that I can't run
curl -sS https://getcomposer.org/installer | php
because I don't get a connection to other server "outside".
So does anybody know, if I can save the file local and upload it with FTP and run it?
Already tried to save the /installer as a file and run it with "asdf | php" but it didn't work. I also downloaded the composer.phar file but how do I run the .phar file?
Thanks!!
Downloading the composer phar file as you have done is a sufficient alternative.
Usage:
php composer.phar command
Docs: https://getcomposer.org/doc/01-basic-usage.md
However, I am fairly sure composer depends on curl, at least as far as updating/installing packages goes. So if you're intending to use those features you'll need curl anyway.*
*citation needed.
edit:
I am currently looking through the composer source and I can't yet find a reference to curl. It appears to use stream_context_create, and the manual page for that method doesn't mention curl either. So maybe it'll work without curl...

having problems with the shopify php api when looking for the shopify_api

PHP API using: https://github.com/sandeepshetty/shopify_api
I have PHP 5.3.27 installed
I installed Composer (by going to
the website and using their install.exe)
It mentions that
"This will download shopify_api into the
vendor/sandeepshetty/shopify_api directory."
But I do not see the folders or files anywhere on the computer.
The plugin author is saying that if you download Composer with the instructions he provided (via Terminal), then Composer will autoload those files for you. Unfortunately, though easier, simply going to the source URL for the Composer tool won't do that for you.
First, make sure you have created the composer.json file and stored it in your project directory. Then, log into your server or system via the command line (Terminal for Mac OS, Putty for Windows). Cd into your project directory, and install by entering these commands:
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar install

composer and php installation conflict for laravel 4 artisan

hi i start working Laravel 4, i have finished the installation process with composer, but when try to use artisan it always give a message
Laravel requires the Mcrypt PHP extension
i have checked with php_info() it shows me Mcrypt PHP extension is enabled, after searching on web i have found some solutions, if i apply those then composer stops working viceversa . i am using XAMPP for development if i use which php command in terminal it show me path /usr/bin/php but my development php is in /Applications/XAMPP/xamppfiles/bin, i have extend the $PATH using .bash_profile
export XAMPP_PHP=/Applications/XAMPP/xamppfiles/bin
export PATH="$XAMPP_PHP:$PATH"
after this artisan start work great but composer stops its working if i type composer command in terminal it show ???? output, now i want composer, php and artisan work perfect just looking for good settings
I solved this problem with a workaround. Instead of changing the $PATH variable, on /usr/bin/ I created a symbolic link to XAMPP's PHP:
cd /usr/bin/
ln -s /Applications/XAMPP/xamppfiles/bin/php phpx
'phpx' is the name I gave to run php on XAMPP (pick the name you prefer - obviously it needs to be different than 'php'). This way I can run artisan using 'phpx' (XAMPP version) which has mcrypt. For example:
phpx artisan key:generate
And if you need to run composer, you run php (mac version):
php composer.phar install
It's a workaround, I'm not proud of it, but it's working.
The best solution would be to install mcrypt on your mac (use this tutorial), mysql and use mac's php. But as a lot of developers (including me) still rely on XAMPP, this workaround may be enough for testing.
If it outputs ???? it most likely means you have detect_unicode = On in your php.ini. This must be off because it breaks phar files.

Running shell commands from PHP - With root permissions or sudo

I'll explain what I'm trying to do, because someone might have a much better and completely different approach to this.
I'm trying to install FFMPEG, but not just install it, I'm making an automated installer that installs some PHP scripts and also FFMPEG if it's not already installed.
I can't find any automated PHP scripts that can install FFMPEG, so I'm guessing this is more difficuilt than I thought.
I had 3 options to do this:
Build from source on the server using the exec function, this
requires root permissions.
Find a pre-compiled binary of FFMPEG, easily done, and I did it, but
then I realised it didn't have the correct codecs so wasn't working.
Use YUM or APT-GET to install FFMPEG, this would be great but it
requires root permissions.
So, how can I either:
Use YUM/APT-GET from PHP and set sudo
OR
Install codecs for FFMPEG after it has been compiled. Using the pre-compiled binaries that I found, if it were possible then I could just install the missing codecs (lame mp3 I think. Maybe others too). Or do the codecs need to be built into the binary.
I think the prefered option is to use YUM/APT-GET as my targets are mostly Centos 5 and maybe Ubuntu aswell.
sudo in php is a lot easier if you use SSH. Among other things you can make use of "expect" to wait for the appropriate prompts. If there's a way to do that with the built in exec() or system() I'm not aware of it.
If you end up compiling from source or installing from a repo you can handle the install processs through this project that allows PHP to obtain and interact with a real Bash shell. Get it here: https://github.com/merlinthemagic/MTS
After downloading you would simply use the following code:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1 = $shell->exeCmd('yum -y install FFMPEG');
//the return will be a string containing the return of the command
echo $return1;
You will need to deal with the edge cases when i.e. there is a GPG key that need to be accepted or dependencies are conflicting. But the project lets you script all Bash interaction.

Installing PEAR without access to Internet

I need to install PEAR on a server which does not have outsite access to the net. There is no go-pear.bat in the php folder and even if it had go-pear.bat i think it needs access to the net.
I looked an the Installing PEAR from a local copy from the PEAR website. But it needs PEAR to be already installed for it to work.
So do any of you guys know how to install PEAR without access to internet?
You don't need PEAR installed on the webhost, just on your local machine.
The two main approches are
Track your dependencies manually, and copy all the appropriate files to the server yourself
With pear installed on your local machine, do pear install -R/my/root_dir -a PEAR. This will install the PEAR package and all dependencies to the specified root directory. Copy this installation to your webhost.
I think it's possible to use pear to manage an installation via FTP also. I never tried.
You should also have a look at "pear help" and "pear help install".
There is a way to do this if you are on Windows and have the PHP installer.
You can select, during the PHP installation time, the PEAR option under extension menu when selecting the components for PHP installation in order to install PEAR package.
If you already have PHP installed, you just have to click on the installer to choose "modify", and choose the correct option.
http://lh4.ggpht.com/_SDci0Pf3tzU/SgBXLClDWEI/AAAAAAAAEuI/TgnBA_SEHFs/s400/pear%20install.jpg
I wrote an article on this very subject:
http://christian.roy.name/blog/install-pear-without-network-no-internet-accessoffline
It will allow you to use the pear command as well.
Create temporary folder that I will get ride of later.
mkdir pear-temp
cd pear-temp
Upload all the PEAR packages to that temp folder (using SFTP, FTP, Whatever).
If you use a USB key, then you copy them all like this:
cp /mnt/usb/*.tgz ./
Extract the core packages in a separate folder.
mkdir lib
tar x -C lib -zf PEAR-*.tgz
tar x -C lib -zf Console_Getopt-*.tgz
tar x -C lib -zf Archive_Tar-*.tgz
tar x -C lib -zf Structures_Graph-*.tgz
This bash function is to be able to set the include_path joined by colons.
function join() {
local IFS=$1
shift
echo "$*"
}
pear requires output buffering and needs to load all the core packages from the lib folder.
PHPOPT="-d output_buffering=1 -d include_path=.:$(join ':' lib/*)"
First we setup our configuration file.
php $PHPOPT lib/PEAR-*/scripts/pearcmd.php config-create $HOME/ $HOME/.pearrc
Now we install ALL our packages. Make sure you have all the required dependencies as well.
php $PHPOPT lib/PEAR-*/scripts/pearcmd.php install -o -O *.tgz
Cleanup
cd ..
rm -Rf pear-temp
Put pear in your path:
PATH="$PATH:$HOME/pear"
Edit your .profile or .bashrc if you want this to be permanent.
Edit your php.ini too or add it using set_include_path() function, whichever :)
Drink to sucess!

Categories