1

Bash file:

#!/bin/bash
mkdir /var/www/html/bash

PHP file:

<?php
exec("/var/www/html/bash.sh");
?>

After I enter localhost/phpfile.php /var/www/html/bash directory Is not created. I tried shell_exec command no results as well. What I'm doing wrong?

7
  • 2
    Does the PHP user have permissions to create directories? Commented Nov 7, 2016 at 18:51
  • -rw-r--r-- 1 root root 40 Nov 7 18:47 phpfile.php -rwxrwxrwx 1 root root 39 Nov 7 18:46 bashfile.sh files are in root group so they should have it. Am I wrong? Commented Nov 7, 2016 at 18:55
  • PHP is not a user in the root group. Commented Nov 7, 2016 at 18:57
  • 1
    First find the user for Apache sudo ps aux |grep apache or sudo ps aux |grep httpd On my server I get www-data So, to allow it to create directories, I chmod the parent folder 775, then chgrp www-data /parentdir ps chmod and chgrp will also need to be done via sudo Commented Nov 7, 2016 at 18:59
  • @JayBlanchard can you tell me how to do it? Or maybe you could give me a link, where I can read more about it. Commented Nov 7, 2016 at 18:59

1 Answer 1

2

It's likely failing because Apache does not have write permissions within your ./var/www/html directory. To give Apache the necessary permissions, try this...

First find the user for Apache sudo ps aux |grep apache or sudo ps aux |grep httpd

On my server I get www-data So, to allow it to create directories, I chmod the parent folder 775, sudo chmod 775 /var/www/html

Then, change the group owner to the user that runs apache (www-data in my case)

sudo chgrp www-data /var/www/html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.