demboz11
demboz11

Reputation: 937

Run BASH script from .PHP file

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?

Upvotes: 1

Views: 875

Answers (1)

Duane Lortie
Duane Lortie

Reputation: 1260

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

Upvotes: 2

Related Questions