Update composer.phar on Openshift - openshift

I have an application written in PHP using Fuelphp 1.6.3 and want to deploy it on Openshift
As the framework required composer, when I access my app at http://audit-manhthang.rhcloud.com/public/, it showed the error
Composer is not installed. Please run "php composer.phar update" in
the root to install Composer
I have Google it and found an article here: https://www.openshift.com/content/support-for-git-clone-on-the-server-aka-support-php-composerphar
I've tried to follow the instruction, create the file name deploy in .openshift/action_hooks folder and added following:
unset GIT_DIR
cd $OPENSHIFT_REPO_DIR/libs
wget -qN http://getcomposer.org/composer.phar
php composer.phar install
But it doesn't work. I have tried to revise install by update
unset GIT_DIR
cd $OPENSHIFT_REPO_DIR/libs
wget -qN http://getcomposer.org/composer.phar
php composer.phar update
But nothing change.
I use PHP 5.3 Cartridge on Openshift

When I did composer update
cd app-root/runtime/repo/php
/usr/bin/php composer.phar update
I received error like this
[RuntimeException]
/var/lib/openshift/52d3b7bd500446f4300001a5/.composer/cache/vcs does not exist and could not be created.
Composer is using $HOME variable to find root path. So to fix that I did.
export HOME=/var/lib/openshift/52d3b7bd500446f4300001a5/app-root/runtime/repo/php
and then
/usr/bin/php composer.phar update
worked.
After update was done I reverted $HOME
export HOME=/var/lib/openshift/52d3b7bd500446f4300001a5
Looks like there have been some changes how openshift works now. I know that this is quite ugly workaround. If I will find something better, I will update this answer. Still, hope this will help someone.
EDIT
Got it! :)
Create new file under .openshift directory:
.openshift/action_hooks/deploy
and mark it as executable.
#!/bin/bash
# Run composer install
cd app-root/runtime/repo/php
export HOME_ORIGIN=$HOME
export HOME=$HOME/app-root/runtime/repo/php
/usr/bin/php composer.phar install
export HOME=$HOME_ORIGIN
After that on every push composer will be updated to current composer.lock place. Perfect! :)
Also make sure vendor/ path is empty. Better add to .gitignore so it not messed up by your local setup.

Here is a slightly better solution than the others mentioned:
http://stanlemon.net/2013/03/22/composer-on-openshift/
The deploy script mentioned in the blog post:
a. downloads composer if not present and stores it in the data directory so that it persists
across git pushes
b. enables composer to use cached versions of packages in the .composer dir stored in the persistent data directory, thus decreasing the time required when doing frequent pushes
There was a small issue with the script - that the php version it was referring to was being complained as being too old by composer
remote: #!/usr/bin/env php
remote: Some settings on your machine may cause stability issues with Composer.
remote: If you encounter issues, try to change the following:
remote:
remote: Your PHP (5.3.3) is quite old, upgrading to PHP 5.3.4 or higher is recommended.
remote: Composer works with 5.3.2+ for most people, but there might be edge case issues.
So I changed the paths to use the latest present on the system
[domain.rhcloud.com action_hooks]\> php --version
PHP 5.4.16 (cli) (built: Dec 6 2013 01:17:01)
[domain.rhcloud.com 5316aa83e0b8cdb61b00023a]\> which php
/opt/rh/php54/root/usr/bin/php
The script in my .openshift/action_hooks/deploy is
#!/bin/bash
# Run composer install
cd app-root/runtime/repo/
export COMPOSER_HOME="$OPENSHIFT_DATA_DIR/.composer"
if [ ! -f "$OPENSHIFT_DATA_DIR/composer.phar" ]; then
curl -s https://getcomposer.org/installer | /opt/rh/php54/root/usr/bin/php -- --install-dir=$OPENSHIFT_DATA_DIR
else
/opt/rh/php54/root/usr/bin/php $OPENSHIFT_DATA_DIR/composer.phar self-update
fi
( unset GIT_DIR ; cd $OPENSHIFT_REPO_DIR ; /opt/rh/php54/root/usr/bin/php $OPENSHIFT_DATA_DIR/composer.phar install )
As the blog post suggests - create an empty hot_deploy file in the markers subdirectory to further speed things up by saying that the servers should not be restarted during a push -
touch .openshift/markers/hot_deploy
git add .openshift/markers/hot_deploy
git add .openshift/action_hooks/deploy
git commit -m "Speeding up composer installs across pushes"
git push origin master
And watch your git pushes be fast even when using composer.

I figure it out. With openshift, I can access via SSH and go to app-root(or something like that)/repo/php and then type /usr/bin/php composer.phar update. That's it.

For reference, OpenShift comes with built-in support for Composer. Adding the use_composer marker file, simply an empty file named use_composer, in your OpenShift project's .openshift/markers directory will automatically enable Composer install/update on deployment.
More specifically, each time you git push to your OpenShift git repo...
When in 'production' mode (default):
echo -n "Checking composer.json for Composer dependency... "
if [ -f ${OPENSHIFT_REPO_DIR}composer.json ]; then
echo
composer install --no-interaction --no-ansi --no-scripts --optimize-autoloader --working-dir=${OPENSHIFT_REPO_DIR} || \
echo -e "\nSkipping Composer errors..\n\n Please, fix the errors either locally or in development mode.\n"
if [ ! -f ${OPENSHIFT_REPO_DIR}composer.lock ]; then
echo -e $composer_lock_msg
fi
else
echo "File not found."
fi
When in 'development' mode:
if [ -f ${OPENSHIFT_REPO_DIR}composer.lock ]; then
echo "Ignoring composer.lock file (development mode)"
fi
echo -n "Checking composer.json for Composer dependency... "
if [ -f ${OPENSHIFT_REPO_DIR}composer.json ]; then
echo
composer update --no-interaction --no-ansi --no-scripts --optimize-autoloader --working-dir=${OPENSHIFT_REPO_DIR}
echo -e $composer_lock_msg
else
echo "File not found."
fi
Check out the code beginning at line #142 of the OpenShift PHP Cartridge.
Check out the Developer Portal article on enabling PHP 'development' mode for more details.
Check out the Laravel 5 QuickStart for example-use or for an easy way to get started.

I do not have enough points to comment on wormhit's answer, so I will append it here:
The zend/php-*/etc/php.ini file needed an update for OpenShift to work with the latest version of composer.phar as described here:
extension=phar.so
extension=ctype.so
Adding these extensions to it fixes PHP's complaints about composer.phar
The next fix required using relative pathing:
php composer.phar install
INSTEAD of absolute pathing:
/usr/bin/php composer.phar install
to allow the extensions to load.

Related

How to Install CakePHP Console?

I have a CakePHP 3.8 project hosted on github: https://github.com/paultrimor/pecunia
I can successfully clone the project, run composer install & configure app.php to have the application run.
However; the installation does not create a /bin directory, meaning that I cannot use the Console/Shell.
I am looking to install the Console on an existing CakePHP project
I receive the following message when I win composer install and `composer create-project --prefer-source``
> App\Console\Installer::postInstall
Set Folder Permissions ? (Default to Y) [Y,n]? n
Updated Security.salt value in config/app.php
> App\Console\Installer::postInstall
Set Folder Permissions ? (Default to Y) [Y,n]? n
No Security.salt placeholder to replace.
The first command replaces the "SALT" string to an actual hash in app.php; But, the second command tries to do the same thing, which it cannot.
Any pointers are appreciated. Thanks.
I think you already solved it looking at your repo, but the bin/ folder should be part of your repository. It will not be created with a composer install or composer update command.
If you create a new project using composer create-project cakephp/app --prefer-dist the bin/ executables will be placed. If you don't explicitly ignore it in .gitignore it will be available to all developers.
Step 1 : check PHP Version
php -v
Step 2: Install Composer
step 3: create a new CakePHP application using composer.
composer create-project --prefer-dist cakephp/app projectname
while installing it asking permission for folder just give yes
Set Folder Permissions ? (Default to Y) [Y,n]? Y
it will work.

Openshift 3 - Installing dependency from s2i/bin/assemble

I have the following file in the directory for my Openshift project which uses s2i to create a build image. This script attempts to install the cairo package.
.s2i/bin/assemble
#!/bin/bash
echo "Before assembling"
sudo yum install cairo
/usr/libexec/s2i/assemble
rc=$?
if [ $rc -eq 0 ]; then
echo "After successful assembling"
else
echo "After failed assembling"
fi
exit $rc
However, it fails with a "sudo": command not found.
This isn't a package that can be added in the requirements.txt file, and I need it for use with the WeasyPrint package. I've tried several different approaches, and this is the closest I've been able to get. (and this approach successfully builds despite the error)
Unfortunately you can't use root on open shift by default. You need to add your dependencies to DockerFile

Liquid Exception: invalid byte sequence in US-ASCII in _layouts/redirect.html

I was using gitlab build of jekyll project, all of a sudden started receiving following error. Not able to solve after a lot of trials. What to do in .gitlab-ci.yml file to resolve this (*error not appearing in local machine, both .gitlab-ci.yml and locally uses "grunt build" command).
Liquid Exception: invalid byte sequence in US-ASCII in _layouts/redirect.html
This solution worked for me.
Put:
before_script:
- apt-get update >/dev/null
- apt-get install -y locales >/dev/null
- echo "en_US UTF-8" > /etc/locale.gen
- locale-gen en_US.UTF-8
- export LANG=en_US.UTF-8
- export LANGUAGE=en_US:en
- export LC_ALL=en_US.UTF-8
In before_script directive in your .gitlab-ci.yml.
Solved this very tricky issue by following:
Disable & Re-enable GitLab CI Runner
Deleted Gemfile.lock from the Runner (Commit)
Deleted folders node_modules and bower_components
Re-compiled project using last successful .gitlab-ci.yml and GemFile
Replaced .gitlab-ci.yml and GemFile to latest versions

How to install pcre on openshift

Any idea how to get hold of pcre (and pcre-devel) libraries on OpenShift / RHEL? I can't directly install packages via yum.
For context, I am trying to install my Yesod/haskell app on openshift, and running into trouble with this pcre dependency during "cabal install".
remote: Configuring pcre-light-0.4.0.3...
remote: cabal: Missing dependency on a foreign library:
remote: * Missing C library: pcre
remote: This problem can usually be solved by installing the system package that
remote: provides this library (you may need the "-dev" version). If the library is
remote: already installed but in a non-standard location then you can use the flags
remote: --extra-include-dirs= and --extra-lib-dirs= to specify where it is.
remote: cabal: Error: some packages failed to install:
Well, I did essentially answer the question as currently titled. The starting point is the put this file in the pre_build hook of your openshift application's git repo (i.e., .openshift/action_hooks/pre_build).
https://gist.github.com/abn/7480593
I did have to add one line, shown below with the comment #AC
#!/bin/bash
# script to install pcre on openshift
# this can be called in your action_hooks to setup pcre
# useful if you want to use regex in uwsgi, or nginx
#
# NOTE:
# If scaling, make sure you call this in your pre_start* hook,
# ${OPENSHIFT_DATA_DIR} is not copied over for a new gear
PCRE_VERSION="8.33"
PCRE_NAME="pcre-${PCRE_VERSION}"
PCRE_TARBALL=${PCRE_NAME}.tar.gz
PCRE_SRC="ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/${PCRE_TARBALL}"
function setup_env()
{
if [ -z $(echo $PATH | grep "$OPENSHIFT_DATA_DIR/bin") ]; then
export PATH=$PATH:${OPENSHIFT_DATA_DIR}/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${OPENSHIFT_DATA_DIR}/lib
fi
}
function cleanup()
{
rm -rf ${OPENSHIFT_DATA_DIR}/${PCRE_TARBALL}
rm -rf ${OPENSHIFT_DATA_DIR}/${PCRE_NAME}
}
function install_pcre()
{
cd ${OPENSHIFT_DATA_DIR} #AC
wget ${PCRE_SRC}
tar xvf ${PCRE_TARBALL}
cd ${PCRE_NAME}
./configure --prefix=${OPENSHIFT_DATA_DIR}
make
make install
}
if [ ! -f "$OPENSHIFT_DATA_DIR/bin/pcre-config" ]; then
install_pcre
setup_env
cleanup
fi
So now pcre is successfully installed on my openshift gear. Mission accomplished! Well, mostly. There is still a separate problem with library paths, but I will ask that separately if RedHat/OpenShift support doesn't come back with an answer.

Deploy meanjs into cloud9 IDE

I'm starting to develop with the stack meanjs. I'm using Cloud9 as a cloud IDE (I need its team functionalities). I tried previously to install mean in my local machine successfully. My problem arise when I try to install it in my cloud9 workspace. Does anybody know how to do it? I tried this https://github.com/meanjs/mean/issues/4 but it's not working.
Thank you so much in advance.
What you need to do is just following the steps that I listed in command line. I found the solution from youtube.
https://www.youtube.com/watch?v=RQ1HqBjT890
First, you need to utilize mongoDB. Type following:
echo "export NODE_PATH=$NODE_PATH:/home/ubuntu/.nvm/v0.10.35/lib/node_modules" >> ~/.bashrc && source ~/.bashrc
mkdir data
echo 'mongod --bind_ip=$IP --dbpath=data --nojournal --rest "$#"' > mongod
chmod a+x mongod
./mongod
At this point, your mongoDB server is running. Then, you need to install node package manager, update it. Also, install yo generator.
npm install npm -g
npm update
npm install -g yo
npm install -g generator-meanjs
Then, create your project directory, create your mean app.
mkdir myMeanProject
cd myMeanProject
yo meanjs
Open a new terminal window, and run server.
cd myNewProject
grunt