Jump to content

PHP Exec Function Doesn't work with cd Ubuntu Command


unemployment

Recommended Posts

Yes, "cd" does not change the working dir of PHP, but the "instance" of the shell that gets invoked using "exec". And each execution is a separate instance.

Also, any particular reason why you're trying to use shell commands instead of the built-in PHP commands like glob?

Edited by Christian F.
Link to comment
Share on other sites

Try to run a shell_exec() php function instead of exec(), it should work. 

 

Exemple:

$test = shell_exec('cd /var/www/mysite.com/mysite.com', $output);
echo $test;

If you want to list another directories where apache does not have permissions:

//create a copy of catalogDB to attach
$cd  = shell_exec("chmod 755 /home/user/Downloads -R; cd /home/user/Downloads; ls -la .");

echo $cd; 
Link to comment
Share on other sites

Hey guys... I change my script around and for some reason it doesn't seem to be working any more. Do you know why?
 

$this->log(getcwd());
          
//chdir('/mysite.com/mysite.com');
shell_exec('cd /var/www/mysite.com/mysite.com', $output);
         
$this->log(getcwd());


The out put for that is:

2013-04-12 12:21:57-04:00 --- INFO: /var/www/deploy
2013-04-12 12:21:57-04:00 --- INFO: /var/www/deploy

 

I don't receive an noticeable errors.  I also tried the chdir function but that kills my script and the second log won't occur.  Any ideas?

Edited by unemployment
Link to comment
Share on other sites

I've already done that using the below code, but it doesn't work:

 

$this->log('Enter Execute');
//$this->log($this->_directory);
// Make sure we're in the right directory

//chdir($this->_directory);
$this->log(getcwd());

//chdir('/mysite.com/mysite.com');
shell_exec('cd /var/www/mysite.com/mysite.com', $output);

$this->log(getcwd());

$this->log('Changing working directory... ');

// Update the local repository
exec('git pull '.$this->_remote.' '.$this->_branch, $output);
$this->log('Pulling in changes... '.implode(' ', $output));

// Secure the .git directory
exec('chmod -R og-rx .git');
$this->log('Securing .git directory... ');

$this->log('Deployment successful.');
Edited by unemployment
Link to comment
Share on other sites

This is my script with the real directory:

$this->log('Enter Execute');
//$this->log($this->_directory);
// Make sure we're in the right directory

//chdir($this->_directory);
$this->log(getcwd());

//chdir('/trekeffect.com/trekeffect.com');
shell_exec('cd /var/www/trekeffect.com/trekeffect.com', $output);

$this->log(getcwd());

$this->log('Changing working directory... ');

// Update the local repository
exec('git pull '.$this->_remote.' '.$this->_branch, $output);
$this->log('Pulling in changes... '.implode(' ', $output));

// Secure the .git directory
exec('chmod -R og-rx .git');
$this->log('Securing .git directory... ');

if (is_callable($this->post_deploy))
{
  call_user_func($this->post_deploy, $this->_data);
}

$this->log('Deployment successful.');
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.