0

I'm having trouble to run a bash file using PHP.

PHP File :

chdir('/var/www/PATH/inc/bash/');
exec('./status.sh argument, $output);

Bash File :

#!/bin/bash
echo 'test' >> /var/www/PATH/inc/bashOutput/test.txt

PHP File (ls -al handler.func.php) :

-rw-r--r-- 1 root root 461 Jul  5 11:35 handler.func.php

Bash File (ls -al status.sh) :

-rwxr-xr-x 1 root root 255 Jul  5 11:39 status.sh

Script is working using through root with SSH.

I'm not a pro on Linux. But I think it's a problem come with the file owner.

But I have already done some damages in the past with "chown" so If it is indead the problem I would prefer some guidance from more experienced people.

Thanks for you help, Konorr.

Bugs
  • 4,491
  • 9
  • 32
  • 41
Konorr
  • 1
  • 1

2 Answers2

0

Script is working using through root with SSH. There is the problem. When a PHP script run via a web request it usually runs as the user www-data. In anycase <?php exec('./status.sh argument, $output);?> in a security hole. Most server admins would have this disabled.

Your other option is to put sudo in your exec function exec('sudo bash /var/www/PATH/inc/bash/status.sh'). Along with running the script with an absolute path bash /var/www/PATH/inc/bash/status.sh

Why can't you run a cron on your script?

MontrealDevOne
  • 1,034
  • 3
  • 17
  • 30
0

Thanks for you answer but unfortunatly it didn't worked for me.

I search a litle more about file owners.

I did few changes

I made in these change :

chown -R www-data:www-data /var/www/PATH
usermod -a -G www-data user
chgrp -R www-data /var/www/PATH
chmod 2750 /var/www/PATH
chmod 2750 /var/www/PATH/inc/bash

It wasn't yet working till I removed the sudo from the EXEC function. So I don't know from which point my problem was already fixed.

I followed this article : www-data permissions?

Thanks for you time and in the hope it can help someone else.

Konorr
  • 1
  • 1
  • please make sure you `accept` your own answer (after the grace period has expired and you have collected enough points to do so), so it is properly marked as *resolved*. – umläute Jul 06 '17 at 08:20