Composer killed while updating - php

I got a problem, I tried to install a new package to my Laravel 4 project.
But when I run php composer.phar update I get this:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Killed
I have looked for the problem in the Internet and saw that the memory is the problem, I think I don't have enough RAM available, I've checked this I have about 411mb free.
Does composer really need more RAM?

The "Killed" message usually means your process consumed too much memory, so you may simply need to add more memory to your system if possible. At the time of writing this answer, I've had to increase my virtual machine's memory to at least 768MB in order to get composer update to work in some situations.
However, if you're doing this on a live server, you shouldn't be using composer update at all. What you should instead do is:
Run composer update in a local environment (such as directly on your physical laptop/desktop, or a docker container/VM running on your laptop/desktop) where memory limitations shouldn't be as severe.
Upload or git push the composer.lock file.
Run composer install on the live server.
composer install will then read from the .lock file, fetching the exact same versions every time rather than finding the latest versions of every package. This makes your app less likely to break, and composer uses less memory.
Read more here: https://getcomposer.org/doc/01-basic-usage.md#installing-with-composer-lock
Alternatively, you can upload the entire vendor directory to the server, bypassing the need to run composer install at all, but then you should run composer dump-autoload --optimize.

If like me, you are using some micro VM lacking of memory, creating a swap file does the trick:
#Check free memory before
free -m
mkdir -p /var/_swap_
cd /var/_swap_
#Here, 2G ~ 2GB of swap memory. Feel free to add MORE
sudo fallocate -l 2G swapfile
chmod 600 swapfile
mkswap swapfile
swapon swapfile
#Automatically mount this swap partition at startup
echo "/var/_swap_/swapfile none swap sw 0 0" >> /etc/fstab
#Check free memory after
free -m
As several comments pointed out, don't forget to add sudo if you don't work as root.
btw, feel free to select another location/filename/size for the file.
/var is probably not the best place, but I don't know which place would be, and rarely care since tiny servers are mostly used for testing purposes.

Unfortuantely composer requires a lot of RAM & processing power. Here are a few things that I did, which combined, made the process bearable. This was on my cloud playpen env.
You may be simply running out of RAM. Enable swap: https://www.digitalocean.com/community/search?q=add+swap (note: I think best practice is to add a seperate partition. Digitalocean's guide is appropriate for their environment)
service mysql stop (kill your DB/mem-hog services to free some RAM - don't forget to start it again!)
use a secondary terminal session running top to watch memory/swap consumption until process is complete.
composer.phar update --prefer-dist -vvv (verbose output [still hangs at some points when working] and use distro zip files). Maybe try a --dry-run too?
Composer is apparently know to run slower in older versions of PHP (e.g. 5.3x). It was still slow in 5.5.9 for me...

DigitalOcean fix that does not require extra memory - activating swap, here is an example for 1gb:
in terminal run below
/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
The above solution will work until the next reboot, after that the swap would have to be reactivated. To persist it between the reboots add the swap file to fstab:
sudo nano /etc/fstab
open the above file add add below line to the file
/var/swap.1 swap swap sw 0 0
now restart the server. Composer require works fine.

I've got this error when I ran composer install inside my PHP DOCKER container,
It's a memory issue.
Solved by increasing SWAP memory in DOCKER PREFERENCES from 512MB to 1.5GB
To do that:
Docker -> Preferences -> Rousources

Increase the memory limit for composer
php -d memory_limit=4G /usr/local/bin/composer update

Run composer self-update and composer clearcache
remove vendor and composer.lock
restart your local environment and then run
php -d memory_limit=-1 /usr/local/bin/composer install

If you're using docker you can use COMPOSER_PROCESS_TIMEOUT
environment:
COMPOSER_MEMORY_LIMIT: -1
COMPOSER_PROCESS_TIMEOUT: 2000 #seconds
Also in big projects composer needs more RAM than 2GB, you can check that with ps -aux while it is running.
You will have to add it manually inside docker options, nothing else will help.

Here's how I succeeded in installing maatwebsite\excel package from composer in Laravel Framework:
I download composer.json file and composer.lock file from my remote server.
I run composer update from local command prompt (then wait until all the install process finished).
Upload composer.lock file to remote server.
run composer install on remote server (then wait until all process finished).
DONE

composer 2 update have reduced the memory usage
composer self-update
composer update
composer require xxx

Fix for AWS ec2 Ubuntu Server Php Memory Value Upgrade For Magento 2.3.X
Php 7.2 / 7.3
nginx
ubuntu
composer 1.X
mariaDB
magento 2.3.X
Error : Updating dependencies (including require-dev)
Killed
for
Ram Must at least 4GB
Change instance type to suitable or Upgrade Ram
Php Memory Value change
Server Restart
Try to install the same package again
PHP value update
may locate under '/etc/php/7.2/fpm/php.ini'
depend on your server and PHP fpm X.XX version
Using Seed command 'change as your server requires'
on my case >> /etc/php/7.2/fpm/php.ini
memory limit type as "3.5G" or "3500MB"
Php 7.2.X
sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.2/fpm/php.ini
Php 7.3.X
sudo sed -i "s/memory_limit = .*/memory_limit = 3.5G/" /etc/php/7.3/fpm/php.ini
Test if applied on 'free -h' command
free -h
Install-Package Again#
Install extension via Composer
go to your Magento 2 installation directory
cd /var/www/html/
with 'superuser' privileges
sudo su
Start installation
composer require XXXXXX/XXXXXXX
Enable Module s
php bin/magento module:enable XXXXXX/XXXXXXX
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
Restart
sudo reboot
Enjioy

I was facing this same issue on my ec2 instance, following steps worked for me :
Copied composer.lock file from my local environment to ec2.
then run sudo composer install and its simply installed all the dependencies for my project.

I solved it maintaining the below steps in my ubuntu server. Hope it will works for you.
Stop my apache server
sudo service apache2 stop
Run composer update
sudo composer update
Start my apache server
sudo service apache2 start

php -d memory_limit=5G composer.phar update

I get this problem caused for a package that don't update correctly with wildcards, I use directly the last version and it works finally.
"l3/cas-bundle": "~1.0" -------> "l3/cas-bundle": "1.1.13"

Solved on Laravel/Homestead (Vagrant Windows)
Edit Homestead.yaml and increase memory from 2048 to 4096
vagrant up
vagrant ssh
Install Symfony with this line on the folder you choose (must be without files)
COMPOSER_MEMORY_LIMIT=-1 composer create-project symfony/website-skeleton . -s dev

I was using:
Virtualbox
4096 Gb RAM
2 CPU
10 GB HDD (500 MB swap)
Ubuntu 20.04
Running:
composer update in a laravel 8 project folder
I didn't set the swap for the virtual machine, so Virtualbox created a 500Mb swap space, which was NOT enough.
So composer was using 4Gb of RAM plus swap.
I gave more swap space to the VM and then it worked.
As the picture below, composer used all my RAM + 2GB of swap
System Monitor

You can try setting preferred-install to "dist" in Composer config.

I was getting this error in a local Docker environment. I solved it by simply restarting Docker.

Related

Unable to run Laravel Composer Update - RAM and Swap file limitation - VPS

I recently subscribed to hostinger vps with 1GB ram. But i cannot run composer update.
[ErrorException]
proc_open(): fork failed - Cannot allocate memory
The problem is i cannot run composer update because of the RAM limitation. I tried setting the ram limit to 512m to 768m to -1 but it still doesnt work. I still get the RAM error Issue.
php -d memory_limit=512M /usr/local/bin/composer update
php -d memory_limit=768M /usr/local/bin/composer update
php -d memory_limit=-1 /usr/local/bin/composer update
I also tried the swap file but unfortunately, hostinger doesn't allow swap files. i cannot use the swapon command.
swapon: /swapfile: swapon failed: Operation not permitted
I am looking for help on the options so that I can run a laravel project on the vps with 1GB ram.
I tried all the suggestions on the docs but none helped.
https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors
I am really in a bind here. Any help is greatly appreciated.
As pointed out by #apokryfos , running
composer update
on the development machine then committing the updated composer.lock file and then running
composer install
on the live server resolved the problem.
Thanks to all who answered.

Php artisan command Run out memory with 32Gb of RAM

I have in DigitalOcean a droplet of 32Gb ram with 12 CPU (resize for occasion)
I run php artisan command (laravel 4.2) which never ran. What could be happening?
And the error message after more than 10 minutes:
I answer my own question, with the help of #aynber and #MartinBarker
I solved the problem droping the current database, updating composer (composer update in my local and pushing composer.lock which contain the updates to the server, in the server run composer install with sudo (is not recommendable use sudo with composer.) and runing sudo php artisan.
then edit the php.ini file and increase your memory limit

Composer update memory limit

I need to run composer update at my hosting so I log in with ssh and try to run the following command inside /www folder where I have Laravel and composer installation:
composer update
I get this error:
I'm in contact with my hosting provider, they told me to run the command:
php -d memory_limit=512M composer update
I ran this command but I got: "Could not open file: composer"
What to do? What is the solution here?
Set it to use as much memory as it wants with:
COMPOSER_MEMORY_LIMIT=-1 composer update
When you run composer update, the OS will look into the configured paths and try to locate an executable file with that name.
When running php composer update, the composer string is treated as a parameter to PHP, which is not searched in any paths. You have to provide the full path in order to run it.
Running which composer will tell you where the OS finds the composer executable, and then you simply use the full path in the PHP command:
$>which composer
/usr/local/bin/composer
$>php -d memory_limit=512M /usr/local/bin/composer update
...
Note that 512MB might be too few. My perception is that it will happily take 1GB or more, depending on the number of dependencies you use and the variety of versions that you theoretically allow, i.e. if you allow Symfony ~2.3, then you make Composer deal with a lot more possible versions compared to using ~2.7.
Also note that running Composer on the production machine is not the best idea. You would have to have access to Github, maybe provide access credentials, have VCS tools installed, and you will easily break your site if any of the remote hosting servers is offline during your update. It is a better idea to use Composer on a deployment system that does all the preparation, and then moves all the files onto the production server.
Update
It's the year 2020 now, and the way Composer manages its memory has changed quite a bit. The most important thing is that Composer will increase the memory limit by itself if it encounters a limit set too low. This however immediately triggers the problem of running out of memory on machines that have too few memory installed. You can make Composer use less memory by setting the environment variable like COMPOSER_MEMORY_LIMIT=512M, but this will create problems if Composer would need more memory to correctly operate.
My main point remains true: Do not run Composer on machines that have too few memory installed. You potentially need 1.5 GB of free memory to be able to update everything.
The best solution for me is
COMPOSER_MEMORY_LIMIT=-1 composer require <package-name>
mentioned by #realtebo
I am facing problems with composer because it consumes all the available memory, and then, the process get killed ( actualy, the output message is "Killed")
So, I was looking for a solution to limit composer memory usage.
I tried ( from #Sven answers )
$ php -d memory_limit=512M /usr/local/bin/composer update
But it didn't work because
"Composer internally increases the memory_limit to 1.5G."
-> Thats from composer oficial website.
Then I found a command that works :
$ COMPOSER_MEMORY_LIMIT=512M php composer.phar update
Althought, in my case 512mb is not enough !
Source : https://www.agileana.com/blog/composer-memory-limit-troubleshooting/
I had to combine COMPOSER_MEMORY_LIMIT and memory_limit in the command line:
On Windows:
set COMPOSER_MEMORY_LIMIT=99999999999&& php -d memory_limit=-1 composer.phar update
On Linux:
export COMPOSER_MEMORY_LIMIT=99999999999 && php -d memory_limit=-1 composer.phar update
If there's enough memory composer would internally consume it and run without any problem. No need to specifically tell the composer to do it.
Have you tried to increase your swap memory, coz it worked for me. I increased the swap memory to 4096Mb (4GB) and now it all looks great to me.
first use "sudo free" to see available memory and swap memory. and configure swap as,
For Debian:
sudo fallocate -l 4G /swapfile
sudo dd if=/dev/zero of=/swapfile bs=4096k count=1048
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
to make it permenant add this to /etc/fstab file, /swapfile swap swap defaults 0 0
For CentOS :
[root#myserver]:/# cd /var
[root#myserver]:/var# touch swap.img
[root#myserver]:/var# chmod 600 swap.img
[root#myserver]:/var# mkswap /var/swap.img
[root#myserver]:/var# dd if=/dev/zero of=/var/swap.img bs=4096k count=1000
[root#myserver]:/var# mkswap /var/swap.img
[root#myserver]:/var# swapon /var/swap.img
you can increase your swap memory by changin bs= 1024k or 2048k or 8096k
depending on your physical volume size.
use 'swapon' and swapoff commands to see the difference.
check 'swappiness' (60 should do good,)
cat /proc/sys/vm/swappiness
You can change the memory_limit value in your php.ini
Try increasing the limit in your php.ini file
Use -1 for unlimited or define an explicit value like 2G
memory_limit = -1
Note: Composer internally increases the memory_limit to 1.5G.
Read the documentation getcomposer.org
I made this on Windows 10 and worked with me:
php -d memory_limit=-1 C:/ProgramData/ComposerSetup/bin/composer.phar update
You can change xx Value that you want
memory_limit=XX
On MAC OS High Siera I ran the below:
MacBook-Pro:asiu jack$ php --ini
Returned:
Configuration File (php.ini) Path: /usr/local/etc/php/7.4
Loaded Configuration File: /usr/local/etc/php/7.4/php.ini
Scan for additional .ini files in: /usr/local/etc/php/7.4/conf.d
Additional .ini files parsed: /usr/local/etc/php/7.4/conf.d/ext-
opcache.ini,
/usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
All answers above are setting the loaded config which does update, but notice additional .ini files parsed has php-memory-limits.ini as a separate file. You have to update this file memeory limit as well. same way open in text editor and change to somehting like 2G. The output on memory limit failure should tell you how much memory it needs to run, just set it to higher than that or -1 for unlimited.
COMPOSER_MEMORY_LIMIT=-1 composer update --ignore-platform-reqs
This error can occur especially when you are updating large libraries or libraries with a lot of dependencies. Composer can be quite memory hungry.
Be sure that your composer itself is updated to the latest version:
php composer.phar --self-update
You can increase the memory limit for composer temporarily by adding the composer memory limit environment variable:
COMPOSER_MEMORY_LIMIT=128MB php composer.phar update
Use the format “128M” for megabyte or “2G” for gigabyte. You can use the value “-1” to ignore the memory limit completely.
Another way would be to increase the PHP memory limit:
php -d memory_limit=512M composer.phar update ...
<C:\>set COMPOSER_MEMORY_LIMIT=-1
<C:\>composer install exhausted/packages
For Laravel
Step 1. Open your terminal
step 2. cd into your laravel directory
step 3. Type the command which composer, in your laravel directory and note the directory in which composer resides.
step 4. run the command php -d memory_limit=-1 /opt/cpanel/bin/composer update (you can also run the code if it works for you)
(change /opt/cpanel/bin/composer to the directory path returned in step 3 )
Problem solved
How large is your aws server? If it only has 1gb of ram, setting the memory limit of 2gb in php.ini won't help.
If you can't/don't want to also increase the server side to get more RAM available, you can enable SWAP as well.
See here for how to enable swap. It enables 4gb, although I typically only do 1GB myself.
Source: Got from laracast site
I'm running Laravel 6 with Homestead and also ran into this problem. As suggested here in the other answers you can prefix COMPOSER_MEMORY_LIMIT=-1 to a single command and run the command normally. If you'd like to update your PHP config to always allow unlimited memory follow these steps.
vagrant up
vagrant ssh
php --version # 7.4
php --ini # Shows path to the php.ini file that's loaded
cd /etc/php/7.4/cli # your PHP version. Each PHP version has a folder
sudo vi php.ini
Add memory_limit=-1 to your php.ini file. If you're having trouble using Vim or making edits to the php.ini file check this answer about how to edit the php.ini file with Vim. The file should look something like this:
; Maximum amount of memory a script may consume
; http://php.net/memory-limit
memory_limit = -1
Note that this could eat up infinite amount of memory on your machine. Probably not a good idea for production lol. With Laravel Valet had to follow this article and update the memory value here:
sudo vi /usr/local/etc/php/7.4/conf.d/php-memory-limits.ini
Then restart the server with Valet:
valet restart
This answer was also helpful for changing the config with Laravel Valet on Mac so the changes take effect.
For those who use Laravel Homestead
Write this on Homestead.yaml
variables:
- key: COMPOSER_MEMORY_LIMIT
value: -1
In my case none of the answers helped. Finally it turned out, that changing to a 64 bit version of PHP (M$ Windows) fixed the problem immediately. I did not change any settings - it just worked.
Go to your php ini file
set memory_limit = -1
In Windows 10 (Git bash), i had to use this
php -d memory_limit=-1 C:\\composer\\composer.phar install
Its fixed in later composer versions.
On Windows I had to uninstall composer then download+install latest version https://getcomposer.org/download/
Now running composer update works!
First of all, try to update composer:
composer self-update
For some reason composer v1.0 doesn't works fine, in my case I had to update composer, after that I can execute:
composer update
In my case it needed higher permissions along with this memory limit increase.
sudo COMPOSER_MEMORY_LIMIT=2G php /opt/bitnami/php/bin/composer.phar update

Composer install/update not working

I have a problem with Composer Package Manager. System is Ubuntu 12.04. I just can't make it work. I pulled my git project and try to run 'composer install', but it seems that nothing actually happens. I just get an information
Installing dependencies (including require-dev)
then nothing actually happens. This is my log from this command run with -vvv parameter:
here
Does anyone have any idea what can be wrong ? I tried to clear cache, it did not help. I am sure this repo works well as I pulled it to my Windows machine and it downloaded everything just fine. 'composer diagnose' also returned OK.
Thanks for any tips.
In first place You should try clearing composer cache.
rm -rf ~/.composer/cache
But more probably it's issue connected with available memory. Increasing memory_limit should help.
Try to view a verbose report:
composer install -vvv
or:
composer update -vvv
If last line shows that process is killed, you need to increase your swap memory:
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
swapon -s
if it continues killing the process, you need to increase 512k to 1024k or maybe 2048k
I had this issue and realised I had xdebug enabled. Disabling it fixed the issue for me.
Try with this one and make sure that the composer.json file exist in your project directory.
COMPOSER=composer.json composer update
Though similar answer has already been posted above but still , if composer install / update is not working try doing composer diagnose..
please refer..
https://getcomposer.org/doc/articles/troubleshooting.md
worked for me after updating my composer..
also sometimes internet might be the issue..
Happy Coding! :D

Continuous Integration using composer

I have a PHP project in which I load packages through Composer. I also run Continious Integration using Jenkins, on a dedicated CI server. Once every hour, Jenkins queries my repository for changes, and if present, if executes a test run.
First step of the testrun is making a fresh checkout of the repository, and performing a build of the application, using Phing. One of the steps of the build is performing an
composer install
Since Jenkins always works with a fresh checkout, composer will always fetch all packages on every test run, even if none of the packages have been changed since the previous run. This has a couple of disadvantages:
It takes a relativally long time to complete a test run (composer needs to fetch for example Zend Framework, which is rather large
It put unnecessary strain on the packagist server, if new packages are fetched every hour
If, for some reason, the composer install fails, so does my test run.
I was thinking of possibly storing the packages that composer fetches on a central spot at the CI server, so Jenkins would be able to access the packages at that location for every test run. Of course, now I have to rewrite part of my application to handle the fact that the vendor folder is in a different location when on the CI server. Secondly, I have to tell Jenkins to keep track of changes on the composer.lock file, to see if he needs to run composer anyway. I'm afraid none of those two things are really trivial.
Does anyone have any suggestions of a other/better way to do this, or is it the best option to just fetch all packages through composer on every test run. Admiditally, it's the best way to make sure you always use the correct packages, but it sortof feels like a waste of bandwith, certainly in later stages of development, when the list of packages will hardly change anymore.
One way to speed it up is to use composer install --prefer-dist which only downloads zips even for dev packages. This is preferred for unique builds since it skips the whole history of the project.
As for sparing packagist, don't worry about it too much, one build every hour isn't going to make a huge difference compared to all the open source libs that build on travis at every commit.
One thing you could do is to store vendors in a location outside of project's workspace in jenkins so that it remains between the builds. You not necessarily need to change your application. Just update the build script so that it creates a symbolic link to the vendors location.
I use capifony for deployment and it uses this approach to keep the vendors between releases.
One thing to note is that Composer caches packages that it downloads. So once they are downloaded the first time, they should work even if Packagist is down (not 100% sure), and network bandwidth spared (100% sure).
Second thing is: why are you running tests by doing a fresh checkout of the repository? It is entirely possible to keep a copy of your code in the workspace in Jenkins, and just make sure you wipe on every test run the caches, logs and other artifacts. This will speed up not only composer install, but also the git pulls, especially for big repos!
Side note: for our own Jenkins platform, where workspaces are not cleaned between tests, the main drawback we found with composer is the sheer amount of disk space taken by having the full vendor dir in each workspace. I tried to work around this by using symlinks and sharing the vendors (named based on hashes of composer.lock), but then composer autoloader had a bit of problems finding where to load classes from...
Steps to install zf2 project on Jenkins
mkdir /path/to/your/project
1. Install the composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, run the mv line again with sudo.
A quick copy-paste version including sudo:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
create a composer.json file in the root directory of the project
add all the pacakages you require
{
"name": "amarjitsingh",
"description": "amarjitsingh",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://domain.com/",
"require": {
"php": ">=5.5",
"zendframework/zendframework": "~2.5",
"phpoffice/phpword": "dev-master",
"doctrine/doctrine-orm-module": "0.7.0",
"imagine/Imagine": "0.5.*",
"zf-commons/zfc-user": "dev-master"
},
"autoload" : {
"psr.0" : "/module"
}
}
run 'composer install' to install these packages.
set up git on your machine
if you are using ubuntu you can set up GIT using the folowing commands
sudo apt-get update
sudo apt-get install git
Set Up Git
git config --global user.name "Your Name"
git config --global user.email "youremail#domain.com"
check the config list
git config --list
once you have setup GIT then c
cd /path/to/your/project
. once you have packes installed the create a '.gitignore' file in the dcument
root and add 'vendor' inside it.
git init
git remote add origin https://username#bitbucket.org/username/zf2ci.git
apply below command to ADD, COMMIT, AND PUSH the files
git add .
git commit -m 'Initial commit with contributors'
git push -u origin master
git pull
using cloud you can use AWS . I am using digital ocean
1 create a droplet
2.name it as you wish , in mycase it is zf2ci
3. choose a package
4. choose the OS my cas eis Ubuntu 14.04
5. In applications tab choose LAMP
6 once you done with that you will get IP address, username root and password.
7. login the ip by using the putty
8. user root
9. password pass
10. once you get into it it will prompt to you to change the password
11. goto web root eg /var/www/html
12. install GIT
13. apt-get install git
14. clone the repo
15. git clone https://username#bitbucket.org/username/zf2ci.git
16. install composer on this machine
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, run the mv line again with sudo.
A quick copy-paste version including sudo:
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
goto app path /var/ww/html/zf2ci
run 'composer install --no-dev' we are installing it with no dev option becuasae we only install well tested code on app server
Step3
Create a Jenkins server
1. set up another droplet for Jenkins
2. image ubuntu
3.install Lamp
install Jenkns
Installing Jenkins
Before we can install Jenkins, we have to add the key and source list to apt. This is done in 2 steps, first we'll add the key.
1.1
wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -
Secondly, we'll create a sources list for Jenkins.
1.2
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
1.3
Now, we only have to update apt's cache before we can install Jenkins.
apt-get update
1.4
As the cache has been updated we can proceed installing Jenkins. Note that Jenkins has a big bunch of dependencies, so it might take a few moments to install them all.
apt-get install jenkins
1.5 open the ip with port 8080
eg http://127.0.0.1:8080
1.6 install git on jenkins server
sudo apt-get update
sudo apt-get install git
1.7 install composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
1.8 enable user authentication
1.9
enable bitbucket plugin for Jenkins
1.9.1
Manage Jenkins->Manage Plugins->Bitbucket Plugin->download and install
1.9.2
create job
create job->
project name(eg. zf2ci)->
source code management (git) provide ssh url(git#bitbucket.org:username/zf2ci.git)->
branches to built (*/master) this is the branch where each time any user commits and merge the code with Master branch -Jenkins gets invoked
1.9.3
Build Triggers
choose the option(build when a chnage is pushed) this will wok when we make a POST hook on bit bucket
1.9.4
Build->Execute shell
composer install
./vendor/bin/phpunit ./tests
our tests sits intests dir
1.9.5
set a ssh key pair
login to jenkins Serevr through putty
su jenkins
cd
ls -la( check what is in the jenkins home directory)
ssh-kegen -t rsa (dsa by default but choose rsa key ,it is faster)
press enter(on path)
press enter(leave the pass phrase empty , the whole point here is to avoid passwords in the automated jobs)
pres enter
cd .ssh
ls -la (you will find id_rsa.pub) file there
cat id_rsa.pub
(select all and copy the contents of the file)
1.9.6
goto bitbucket
switch to the repo zf2ci
goto settings
click deployment keys->add key
add label (jenkins)
key*(paste the the contents of the id_rsa.pub)file here
save key
summary
`zf2ci->settings->deployment keys->add key->type` label and paste id_rsa.pub key->save
1.9.7
register POST hook for repo
Settings->
Integrations->
Hooks->
POST(search for POST Hook)->
Add the url /IP of the Jenkins Server) (`172.62.235.100:8080/bitbucket-hook/`)
(the body of the post contanis information about the repository, branch, list of recent commits, user)
1.9.8
login to Jenkins server
su jenkinks
cd
cd .ssh
git ls-remote -h ssh://git#bitbucket.org:username/zf2ci.git HEAD
1.9.9
save project on Jenkins
1.9.10
add the following command in the
Execute Shell->command
[rsync -y -vrzhe "ssh -o StrictMostKeyChecking=no" --exclude vendor/ . root#ipaddress:/var/www/html/zf2ci( of app server)]
ssh root#ipaddress<<EOF
cd /var/www/html/zf2ci
composer install --no-dev
EOF

Categories