mrkeck Sharing the Love

21Jun/160

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
17Jun/160

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
%www ALL = (ALL) NOPASSWD: ALL

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
16Jun/160

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
exit
#Log back in
groups
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 {} \;
ssh-keygen
#Enter 3 times
ssh-agent /bin/bash
ssh-add ~/.ssh/id_rsa
ssh-add -l
cat ~/.ssh/id_rsa.pub
#copy that to Bitbucket
vim ~/.ssh/config
"
Host bitbucket.org
IdentityFile ~/.ssh/id_rsa
"
:w
:q
chmod 600 ~/.ssh/config
cd /var/www/html
git clone git@bitbucket.org:ACCOUNT/NAME.git

Filed under: EC2 No Comments
3Sep/140

mySQL import dump file to RDS

mysql -h host.address.for.rds.server -u rdsusername -p rdsdatabase < backupfile.dump From http://stackoverflow.com/questions/11731714/how-do-i-import-a-local-mysql-db-to-rds-db-instance which is explains in more detail

Filed under: mySQL, RDS No Comments
20Jul/130

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/

ssh git-YOURS@pl2.projectlocker.com
Enter passphrase

Go to EC2 using SSH and go to where you want to clone the repository
"git clone git-yourAccount@pl23.projectlocker.com:something.git ."

Done

12Jul/130

Amazon S3 Upload Directory Including Itself Using PHP SDK

//Upload directory into s3 directory
//Ex. 2013/01/02/test.jpg
//$bucket = 'myBucket';
//$dirToUpload = '2013';
//$uploadDir = '2013';
//$client->uploadDirectory($dirToUpload, $bucket . '/' . $uploadDir);
//In S3 you have 2013/01/02/test.jpg
//If you didn't add the /directory to the bucket would get 01/02/test.jpg
 
$bucket = 'myBucket';
$dirToUpload = 'C:/someDir/localDir';
$uploadDir = 's3Dir';  //Could be the same as $dirToUpload but you can change name too
$response = $client->uploadDirectory($dirToUpload, $bucket . '/' . $uploadDir);
Filed under: Amazon, PHP, S3 No Comments