How to install Requests for PHP in Ubuntu? - php

How to install Requests for PHP (http://requests.ryanmccue.info/) on Ubuntu 14.04?
I have downloaded package with command:
$ wget https://github.com/rmccue/Requests/tarball/master -O - | tar xzv
In Phyton next step would be:
$ sudo python setup.py install
What command would I use for PHP?

If you install via composer, which I recommend you do, you can then include it just by including the 'autoload.php' that composer generates for you. Usually from your project root
require 'vendor/autoload.php'
but that will depend on the structure of your project. Then you're freely able to use
Requests::get($args); // or, of course, any of the other functions
from within your project.

Unless it's a compiled PHP extension, there is no installation step for PHP libraries. You download the files, you put them in a folder, you require the file you just downloaded. Typically you make those dependencies part of your PHP project instead of installing them "globally". Composer was created to simplify that process and help you manage dependencies. If you don't use it, it's up to you where to put those files and where to require them from.

Related

composer itself is managed by composer?

Maybe just a stupid question.
After I download/clone composer source code from github.com, how can I run it or compile it into a phar file?
When running "php bin/composer -v", it shows such errors:
php bin/composer -v
You must set up the project dependencies using `composer install`
See https://getcomposer.org/download/ for instructions on installing Composer
Is it said that I must download another composer.phar file and run "php composer.phar install" first?
I think it is a recursive way, "composer" itself is managed by composer :(
At first: if someone wants just to use composer, they must not install it from GitHub, just follow the installation guide: https://getcomposer.org/download/
OK, back to the question.
"composer" itself is managed by composer
Yes, and why do you think it is bad?
See the official documentation for contributors. It encourages exactly that way:
Run git clone https://github.com/composer/composer.git
Download the composer.phar executable
Run Composer to get the dependencies: cd composer && php ../composer.phar install
Then you can actually use composer by launching bin/composer, or you can compile it into phar by bin/compile.
If you wonder how are composer binaries actually built, you can see it in their Travis config. They just grab previous composer release provided by Travis, and build new composer release with it.
Composer's job is to locate and install dependencies for a particular project. Everything it does could be done by hand, mostly simply by placing files in the right location, and referencing a series of autoloaders.
In order to build Composer from scratch, you need certain code that is outside of the main Composer repository, such as command-line and logging helpers. You could download all of these manually, but the natural way is to use an existing install of Composer to fetch them.
This is only necessary if you are working on Composer itself, because once you have a successful build, you can produce a PHAR file, which contains all the required code including those third-party dependencies. These are the files distributed as official releases, and are all most people need; the tool even has a self-update command which downloads a new PHAR file and overwrites the one you ran.
This kind of bootstrapping - using an existing build of a tool as part of its own build process - is actually quite common. There are some parts of PHP itself which are generated using a PHP script, and I believe the first feature-complete C++ compiler was written in C++.

cs-cart add on giving error cscart-sdk is not recognized

I have developed a cs cart add on, But when I make a zip of it and try to upload it from gui it gives wrong structure data
so after little research I got that, I have to follow some steps of given in following url.
https://github.com/cscart/sdk
But after successful installation of composer, When I run the command
cscart-sdk command:name
It gives me error
cscart-sdk is not recognized as an internal or external command
I am very new to cscart add-on development
There seems to be something wrong with your composer install, please follow this tutorial (this is where cscart also relates to)
Installation - Linux / Unix / OSX#
Downloading the Composer Executable#
Composer offers a convenient installer that you can execute directly from the commandline. Feel free to download this file or review it on GitHub if you wish to know more about the inner workings of the installer. The source is plain PHP.
There are in short, two ways to install Composer. Locally as part of your project, or globally as a system wide executable.
Locally#
Installing Composer locally is a matter of just running the installer in your project directory. See the Download page for instructions.
The installer will just check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things.
Now just run php composer.phar in order to run Composer.
You can install Composer to a specific directory by using the --install-dir option and additionally (re)name it as well using the --filename option. When running the installer when following the Download page instructions add the following parameters:
php composer-setup.php --install-dir=bin --filename=composer
Now just run php bin/composer in order to run Composer.
Globally#
You can place the Composer PHAR anywhere you wish. If you put it in a directory that is part of your PATH, you can access it globally. On unixy systems you can even make it executable and invoke it without directly using the php interpreter.
After running the installer following the Download page instructions you can run this to move composer.phar to a directory that is in your path:
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, you may need to run it again with sudo.
Note: On some versions of OSX the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create the directory manually before proceeding: mkdir -p /usr/local/bin.
Note: For information on changing your PATH, please read the Wikipedia article and/or use Google.
Now just run composer in order to run Composer instead of php composer.phar.

How to get vendor folder in github project

Ive downloaded a helper library of an API written in PHP from GITHUB, but when I download the .zip file it doesnt contain vendor folder, but everywhere in the code it is seeking some files from vendor folder-which is error in running.
Can you help me how to get these? new to the system.
If you're working with PHP and you can't find a vendor/ directory that you expect to see, that PHP codebase probably uses Composer:
Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.
One surefire way to know that a project uses Composer (aside from reading its documentation) is to see if there are composer.json and composer.lock files (probably) in the root of the repository. These files define the project's dependencies.
To generate the vendor/ directory,
install Composer,
there are a few ways to do this, and it is OS-dependent, but something like curl -sS https://getcomposer.org/installer | php should work if you're on Linux or OSX,
open a terminal and cd into the project directory,
run composer install,
depending on how you installed Composer, you may have to run php composer.phar install instead,
wait for Composer to do its thing.
Composer will download your dependencies, putting the code into vendor/, and generate an autoloader class that hooks everything together. Depending on what the dependencies are it might also do other things, like linking all CLI binaries to vendor/bin/.

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

Xampp / Composer / Zend Framework 2 Installation issues

Ok, so I have a composer.json file, a composer.lock file, and a composer.phar file. All the info I need to install Zend Framework I believe is in the .json file, however I have no idea what I'm doing with composer, and have no idea how to use the .phar file. If someone out there can help me out, I would be super great-full. I've been reading tutorials, and watching videos but I'm fairly new to the technical side of php. I've never worked with libraries, or command prompts, so this is all WAY over head.
Here is a start:
http://getcomposer.org/doc/00-intro.md
Step one: Download composer.phar
$ curl -sS https://getcomposer.org/installer | php
Step Two:
$ php composer.phar install
That will download all the file dependencies outlined in the composer.json file.
A couple notes:
Above assumes you are using a bash prompt (Linux or cygwin on windows) If your not using linux you can download composer.phar from getcomposer.org.
You have php in your system path meaning that when you type php in your command line it will run the php executable/binary.

Categories