How to start an update on a PHP server?

Is there a way to run the composer update command in our test environment?

The problem is that I do not have access to the command line.

+6
source share
3 answers

Yes. there is a solution. but this may require some server configuration ... and some of them are disabled by default due to security risks!

download composer.phar https://getcomposer.org/download/ is a PHP archive that can be extracted via Phar() and executed as a regular library.

create a new php file and put it in the public folder. those. /public/composer.php

or download https://github.com/whipsterCZ/laravel-libraries/blob/master/public/composer.php


Configuration

 <?php //TODO! Some Authorization - Whitelisted IP, Security tokens... echo '<pre> ______ / ____/___ ____ ___ ____ ____ ________ _____ / / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/ / /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ / \____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ UPDATE /_/ '; define('ROOT_DIR',realpath('../')); define('EXTRACT_DIRECTORY', ROOT_DIR. '/composer'); define('HOME_DIRECTORY', ROOT_DIR. '/composer/home'); define('COMPOSER_INITED', file_exists(ROOT_DIR.'/vendor')); set_time_limit(100); ini_set('memory_limit',-1); if (!getenv('HOME') && !getenv('COMPOSER_HOME')) { putenv("COMPOSER_HOME=".HOME_DIRECTORY); } 

Extract composer library

 if (file_exists(EXTRACT_DIRECTORY.'/vendor/autoload.php') == true) { echo "Extracted autoload already exists. Skipping phar extraction as presumably it already extracted.\n"; } else{ $composerPhar = new Phar("../composer.phar"); //php.ini set phar.readonly=0 $composerPhar->extractTo(EXTRACT_DIRECTORY); } 

composer team

 // change directory to root chdir(ROOT_DIR); //This requires the phar to have been extracted successfully. require_once (EXTRACT_DIRECTORY.'/vendor/autoload.php'); //Use the Composer classes use Composer\Console\Application; use Composer\Command\UpdateCommand; use Symfony\Component\Console\Input\ArrayInput; //Create the commands $args = array('command' => 'update'); if(!COMPOSER_INITED) { echo "This is first composer run: --no-scripts option is applies\n"; $args['--no-scripts']=true; } } $input = new ArrayInput($args); //Create the application and run it with the commands $application = new Application(); $application->setAutoExit(false); $application->setCatchExceptions(false); try { //Running commdand php.ini allow_url_fopen=1 && proc_open() function available $application->run($input); echo 'Success'; } catch (\Exception $e) { echo 'Error: '.$e->getMessage()."\n"; } 

But Better would be to run composer install , according to the composer .lock, which is the latest dependency configuration verified from the local environment

only change

$args = array('command' => 'install');

+5
source

The best idea is to NOT run Composer commands on the production server, but outside it. Have a deployment script - your code should be placed on the server anyway, and it doesn't matter if you add dependencies on the server after you have downloaded the code or before downloading.

The workflow will be this: have a local machine, check your code from the repo, run composer install , and then upload everything to the server. This sounds like a four line script to me:

 git archive master | tar -x -C /deploy/application pushd /deploy/application && composer install popd scp /deploy/application user@remoteserver :/srv/www/htdocs 

Yes, you will need some error handling if something goes wrong to stop the script from deploying a non-working site. In addition, optimizing downloads using rsync will be an offer.

+1
source

You can also do this: 1) Download the latest version of composer.phar 2) Run a command from a PHP script to do this using the downloaded composer file

This is a temporary solution, but it can work for immediate need.

-2
source

All Articles