Asked  8 Months ago    Answers:  5   Viewed   41 times

Wondering if it's possible to execute composer from the browser with a little PHP wrapper as I don't have access to shell access to the server.

Not sure if you can do this with cURL?



Yes you can run Composer with a little PHP wrapper. All of the Composer source code is available in the Phar file, so it can be extracted and then you can run it after setting up an InputInterface to replace Composer expecting the commands to be passed in via the command line.

If you setup your directory structure like this:


Put the code below into composerExtractor.php and then run it from a web-browser, Composer should download all the libraries into:


As well as generating the class-loader files in that directory as well.



define('EXTRACT_DIRECTORY', "../var/extractedComposer");

if (file_exists(EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) {
    echo "Extracted autoload already exists. Skipping phar extraction as presumably it's already extracted.";
    $composerPhar = new Phar("Composer.phar");
    //php.ini setting phar.readonly must be set to 0

//This requires the phar to have been extracted successfully.
require_once (EXTRACT_DIRECTORY.'/vendor/autoload.php');

//Use the Composer classes
use ComposerConsoleApplication;
use ComposerCommandUpdateCommand;
use SymfonyComponentConsoleInputArrayInput;

// change out of the webroot so that the vendors file is not created in
// a place that will be visible to the intahwebz

//Create the commands
$input = new ArrayInput(array('command' => 'update'));

//Create the application and run it with the commands
$application = new Application();


Although this is possible, it's not a fantastic idea but may be necessary if you can't use a host that gives you ssh access.

I'd strongly recommend at least getting a static IP address for yourself or your office and then restricting access to just your own IP, as well as probably deleting this script after it's run on the server to prevent it being accidentally run again.

Wednesday, March 31, 2021
answered 8 Months ago

As stated in the question you already have both the versions of PHP on your system, As Laravel uses the cli version you need to enable 7.X and disable 5.X.

You can achieve that by below commands

$ sudo a2dismod php5.6 // disable the loaded version
$ sudo a2enmod php7.0 // enable the desired version
$ sudo service apache2 restart // restart apache to get it in action

For More information You can install different version of PHP using the below commands

For Apache

$ sudo apt install php5.6   [PHP 5.6]
$ sudo apt install php7.0   [PHP 7.0]
$ sudo apt install php7.1   [PHP 7.1]

For Ngix

$ sudo apt install php5.6-fpm   [PHP 5.6]
$ sudo apt install php7.0-fpm   [PHP 7.0]
$ sudo apt install php7.1-fpm   [PHP 7.1]

To install any PHP modules, simply specify the PHP version and use the auto-completion functionality to view all modules as follows.

------------ press Tab key for auto-completion ------------ 
$ sudo apt install php5.6 
$ sudo apt install php7.0 
$ sudo apt install php7.1 

Now you can install most required PHP modules as per your requirements.

------------ Install PHP Modules ------------
$ sudo apt install php5.6-cli php5.6-xml php5.6-mysql 
$ sudo apt install php7.0-cli php7.0-xml php7.0-mysql 
$ sudo apt install php7.1-cli php7.1-xml php7.1-mysql 
Wednesday, March 31, 2021
answered 8 Months ago
  1. Create some queue of jobs (database / files / writing directly to some socket).
  2. Create either a deamon (socket) or cron job which consumes those jobs.
  3. Let the worker report when a task is done in some store if needed (database / file / etc.), if you want to provide a 'success' (or failure) message later on.
Wednesday, March 31, 2021
answered 8 Months ago

The namespace for guzzle 4 is GuzzleHttp in guzzle 3 the namespace was simply Guzzle.

A composer.json of:

    "require": {
        "guzzlehttp/guzzle": "~4"

Should allow you to run a php script of:

require 'vendor/autoload.php';

use GuzzleHttpClient;

$client = new Client();

$requests = Array(
    $client->createRequest('GET', ''),
    $client->createRequest('GET', ''),
    $client->createRequest('GET', ''),


If the autoloader still fails after changing the namespace it could be that your version of composer is out of date and does not recognize PSR4 autoloading. If there is no file in vendor/composer/autoload_psr4.php try doing a composer self-update followed by a composer dump-autoload to see if the problem is resolved.

Saturday, May 29, 2021
answered 5 Months ago

If you want to talk to the process in some way, use IO.popen("php <script>"). Or you could use the backticks option (not easy with the markup here), which returns the string the process writes to stdout. If you need no communication, system "php <script>" returns you true or false wherever the command succeded and you've got no chance to communicate further.

If you have unsafe input, use Array#shelljoin to escape it.

Why not rewrite the script in ruby?

Thursday, August 5, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :