How can I composer update on OpenShift? - php

I am trying to use Slim on OpenShift with a free node. I can run composer update from the SSH sessions without any problem.
The only problem is every time I want to commit files through git I have to go to the console and run composer install again. My question is there is any easy way to workaround this? I tried a BASH script in /project/.openshift/action_hooks/post_deploy but the server is not creating the vendor folder under runtime/repo

I always do it via action hooks:
Inside my project directory I have a script called by /project/.openshift/action_hooks/post_deploy where post_deploy is a bash script.
Here goes what I have been using:
#!/bin/bash
export MY_PHPCOMPOSER=$OPENSHIFT_DATA_DIR/composer.phar
# if composer not exists, download
if [ ! -f $MY_PHPCOMPOSER ]; then
cd $OPENSHIFT_DATA_DIR
echo "Downloading composer..."
php -r "readfile('https://getcomposer.org/installer');" | php
fi
$MY_PHPCOMPOSER -n -q self-update
cd $OPENSHIFT_REPO_DIR
# install
php -dmemory_limit=1G $MY_PHPCOMPOSER install
So post_deploy script will perform every time which you push your repo to openshit. It work like a charm!
Side note
Since not always the OpenShift composer's version is updated it's safe
to download a new composer copy and use it.
Also, don't forget adjusting permissions settings.
Helpful links
Openshift builds
Openshift Default Build Lifecycle

I know that my answer is late but according to the Openshift documentation you can enable composer install after each build by just creating a marker file:
touch .openshift/markers/use_composer

Related

Why despite "drush" being installed via `composer global install` during image build, I cannot find the tool from within a running PHP script?

I am developing a PHP web application inside of a Docker container. Using volumes: inside of my docker-compose.yml file, I have specified a local directory so that any files generated are dumped and persist after the container is destroyed.
volumes:
- ./docroot:/var/www/html
Inside my Dockerfile, I RUN a command that installs a command line management tool:
RUN curl -sS https://getcomposer.org/installer | php && \
mv composer.phar /usr/local/bin/composer && \
ln -s /root/.composer/vendor/bin/drush /usr/local/bin/drush
RUN composer global require drush/drush:8.3.3 && \
composer global update
When the container comes up, I can use docker-compose exec -it <container> bash to get inside the container, and everything works fine. drush is in my path, and I can use it globally throughout the container to manage the app.
Now here is the strange part. Part of my application is that I have to run that command from a PHP script inside the container to help automatically manage some of the build process.
Using php, I run exec('drush dbupdate', $output, $retval); $retval returns a exit status of 127, or command not found and $output is empty. If I switch up the exec to use the full path I get an exit status 126.
If I go back into the container, I can run that command just fine. Note all other cli commands work as expected with exec (ls, whoami, etc but which drush returns exist status 1)
What am I missing? Why can I use it with no problems manually, but PHP exec() can't find it? passthru(), shell_exec(), and others have the same behavior.
composer global install will not install the command "globally" for all users, but "globally" as in "for all projects".
Generally, these packages are installed in the home directory for the user executing the command (e.g. ~/.composer), and if they are available in your path is because ~/.composer/vendor/bin is added to the session path.
But when you run composer global require (while building the image) or when you "log in" to the running container (using exec [...] bash) the user involved is root. But when your PHP script runs, it's being executed by another user (presumably www-data). And for that user, ~/.composer does not contain anything.
Maybe do not install drush using composer, but rather download the PHAR file directly or something like that while you are building the image, and put it in /usr/local/bin.
If you are using Drupal >= 8, the recommended way of installing Drush is not as a "global" dependency, but as "project" dependency, so that the appropriate drush version is installed. This comes straight from the docs:
It is recommended that Drupal 8 sites be built using Composer, with Drush listed as a dependency. That project already includes Drush in its composer.json. If your Composer project doesn't yet depend on Drush, run composer require drush/drush to add it. After this step, you may call Drush via vendor/bin/drush

How can I install composer in live server cpanel

I want to use php spreadsheet package and from their site, I was told to install composer on cpanel but have met little success on the internet trying to figure out how to do it.
Please, who can put me through on how to install composer on liveserver
You can use SSH for this (alternatively using cron jobs to run the commands will also work - way more tedious)
Login to your cPanel account via SSH
Make directory for your composer (can also be used for other executables that you might store)
mkdir ~/composer
cd ~/composer
Download composer
wget https://getcomposer.org/download/1.6.5/composer.phar
Change the name of composer and make it executable
mv composer{.phar,}
chmod +x composer
You will now be able to call composer by
php ~/composer/composer install
But it's more convenient to have it run by just invoking composer in your terminal. For this add the ~/composer directory to your $PATH. I'm using VIM for text editing so
vim ~/.bashrc
Append those two lines at the bottom
PATH=~/composer:$PATH
export PATH
Exit and login via SSH again - you will be able to freely call composer in your terminal

how to create autoload under vendor directory for php rabbitmq

I m new to php and rabbitmq in debian(Linux). I have installed xampp, rabbitmq and also installed composer.phar in project directory using below command
/opt/lampp/htdocs/rabbitmq_demo# curl -s https://getcomposer.org/installer | /opt/lampp/bin/php
Now I use Composer to install the dependencies of the project using below command
composer.phar install
but it thrown an error as below
bash: php: command not found
I have preferred the link https://getcomposer.org/doc/00-intro.md
I want to prepare autoload.php
Please help me to create autoload under vendor directory.
You do not have a php cli program installed on your computer or it is not in your current $PATH variable. Please install PHP first or correct your $PATH environment variable.
Once you have this, run the composer.phar install again. This will download all dependencies listed in your composer.json file. Once the program completes, you will have a file ``vendor/autoload.php`. You can just require this file at the beginning of your own script and everything will be taken care of.
You need to add the path to the PHP command line (CLI) in the XAMPP install, to your bash environment. (You'd think the installer would do this!)
The XAMPP PHP CLI on Debian is at /opt/lampp/bin/php
So you need to add /opt/lampp/bin to your $PATH environment variable.
See this answer for the various options in modifying your path depending on who you want to be able to run PHP.
/etc/login.defs
/etc/environment
/etc/profile
~/.bashrc
In one of those files, you append to the path thus:
PATH=$PATH:/opt/lampp/bin
and re-login.

How do I install Composer on a shared hosting?

I have these things:
the file http://api.odtu.lu/composer.phar
http://api.odtu.lu/phpinfo.php
ftp access
cPanel
Cron jobs on FreeBSD
PHP, Perl, CGI-BIN, Python, Curl.
How can I install Composer? (My aim is to install Restler)
Edit: I do not have SSH access.
This tutorial worked for me, resolving my issues with /usr/local/bin permission issues and php-cli (which composer requires, and may aliased differently on shared hosting).
First run these commands to download and install composer:
cd ~
mkdir bin
mkdir bin/composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar bin/composer
Determine the location of your php-cli (needed later on):
which php-cli
(If the above fails, use which php)
It should return the path, such as /usr/bin/php-cli, /usr/php/54/usr/bin/php-cli, etc.
edit ~/.bashrc and make sure this line is at the top, adding it if it is not:
[ -z "$PS1" ] && return
and then add this alias to the bottom (using the php-cli path that you determined earlier):
alias composer="/usr/bin/php-cli ~/bin/composer/composer.phar"
Finish with these commands:
source ~/.bashrc
composer --version
It depends on the host, but you probably simply can't (you can't on my shared host on Rackspace Cloud Sites - I asked them).
What you can do is set up an environment on your dev machine that roughly matches your shared host, and do all of your management through the command line locally. Then when everything is set (you've pulled in all the dependencies, updated, managed with git, etc.) you can "push" that to your shared host over (s)FTP.
I have successfully installed Composer (and Laravel) on my shared hosting with only FTP access:
Download and install PHPShell on a shared hosting
In PHPShell's config.php add a user and an alias:
php = "php -d suhosin.executor.include.whitelist=phar"
Log in to PHPShell and type: curl -sS https://getcomposer.org/installer | php
When successfully installed, run Composer: php composer.phar
You can do it that way:
Create a directory where you want to install composer (let's say /home/your_username/composer)
Go to this directory - cd /home/your_username/composer
Then run the following command:
php -r "readfile('https://getcomposer.org/installer');" | php
After that if you want to run composer, you can do it this way (in this caseyou must be in the composer's dir): php composer.phar
As a next step, you can do this:
alias composer="/home/your_username/composer/composer.phar".
And run commands like you do it normally: $ composer install
Hope that helps
I was able to install composer on HostGator's shared hosting. Logged in to SSH with Putty, right after login you should be in your home directory, which is usually /home/username, where username is your username obviously. Then ran the curl command posted by #niutech above. This downloaded the composer to my home directory and it's now accessible and working well.
SIMPLE SOLUTION (tested on Red Hat):
run command: curl -sS https://getcomposer.org/installer | php
to use it: php composer.phar
SYSTEM WIDE SOLLUTION (tested on Red Hat):
run command: mv composer.phar /usr/local/bin/composer
to use it: composer update
now you can call composer from any directory.
Source: http://www.agix.com.au/install-composer-on-centosredhat/
Most of the time you can't - depending on the host. You can contact the support team where your hosting is subscribed to, and if they confirmed that it is really not allowed, you can just set up the composer on your dev machine, and commit and push all dependencies to your live server using Git or whatever you prefer.

error: git was not found - installing laravel with composer windows

I'm getting an error saying:
failed to clone https://github.com/php-fig/log.git, git was not found, check that it is installed and in your PATH env.
'git' is not recognized as and internal or external command, operable program or batch file
when I try and run composer create-project laravel/laravel learning-laravel.
I installed the git GUI which also comes with a command line shell, but I don't know why its not recognising the command (I'm issuing the create-project command in the normal windows command line prompt).
I also tried running the command from the git shell, which worked, but when I tried php artisan serve it gave me an error saying CLI has stopped working.
Does anyone know how to fix the git error? I'd rather use the windows command shell instead of the git one as it can then go into my wamp/www file
You need to add the directory you installed git to to your PATH environment variable.
Right click on Computer.
Click Advanced System Settings
Click Environment Variables inside the Advanced Menu
Under System Variables, scroll to PATH
Add ;"C:\path\to\git\bin";"C:\path\to\git\cmd"
Test the git command in the command prompt to see if it worked. Git is usually located in Program Files or Program Files(x86).
There is an easier (but temporal) way to add a path variable in Windows.
Paste this in your command prompt:
SET PATH=%PATH%;C:\Program Files\Git\bin
This will work for the rest of the command prompt session. Don't forget installing Git before this.
You'll need to add git to your system PATH if you want to use it in regular command prompt.
Here's a guide on modifying your system path in Windows:
http://www.computerhope.com/issues/ch000549.htm
you need to uninstall git and reinstall ( or update ) in the options you need to change from git bash only to allow git to be added to command line as well, also since it then adds it to your path you may or may not need to restart your computer
I was having some issues using git on Windows. I found this information only and it worked for me.
http://ccn.ucla.edu/wiki/index.php/Setting_Up_and_Using_Git#Windows

Categories