mrkeck Sharing the Love


Linux See if Process including Argument is Running

Problem I had was when run.php 13 was running it also thought run.php 1 was also running since the 13 contains 1.
Look for only processes run by root and ends with the argument matching the id

$file = '/var/www/html/run.php 1';
$isRunning = array();
exec('ps aux | grep "' . $file . '"', $isRunning);
$run = true;
    foreach($isRunning as $process){
        if( substr($process, 0, 4) == 'root'){
             $lastPart = array_pop(explode(' ', $process));
             //echo $lastPart;
           if( $lastPart == $sites[$i]['id'] ){
              $run = false;
Filed under: EC2 No Comments

PHP sudo as user with no password required

Was getting: "sudo: no tty present and no askpass program specified php"
When running:
echo shell_exec("cd /var/www/html/repo/;sudo -u ec2-user /usr/bin/git pull 2>&1");

sudo vim /etc/sudoers

sudo usermod -a -G www ec2-user
sudo usermod -a -G www apache
Puts users ec2-user and apache are part of group www

May have to restart server

Filed under: EC2, PHP No Comments

EC2 Amazon Linux LAMP Bitbucket Setup

sudo yum update -y
sudo yum install -y httpd24 php56 mysql55-server php56-mysqlnd
sudo service httpd start
sudo chkconfig httpd on
chkconfig --list httpd
sudo groupadd www
sudo usermod -a -G www ec2-user
#Log back in
sudo chown -R root:www /var/www
sudo chmod 2775 /var/www
find /var/www -type d -exec sudo chmod 2775 {} \;
find /var/www -type f -exec sudo chmod 0664 {} \;
#Enter 3 times
ssh-agent /bin/bash
ssh-add ~/.ssh/id_rsa
ssh-add -l
cat ~/.ssh/
#copy that to Bitbucket
vim ~/.ssh/config
IdentityFile ~/.ssh/id_rsa
chmod 600 ~/.ssh/config
cd /var/www/html
git clone

Filed under: EC2 No Comments

Windows 7 projectLocker Amazon EC2

Windows 7
ssh-keygen -t rsa -C "username in projectLocker"

Add public key to user in ProjectLocker

Then install SmartGit

Use SSH url from ProjectLocker
and location of private key from ssh-keygen

Use winSCP and EC2 Private Key to access server

copy projectLocker private key to /home/(user in this instance)/.ssh/

Enter passphrase

Go to EC2 using SSH and go to where you want to clone the repository
"git clone ."