Red Virus
Red Virus

Reputation: 1707

Running shell script from terminal works but doesn't work when running from PHP shell_exec

I've just started with shell scripts a week ago so please be easy on me. When I run create.sh from the terminal, everything works great as expected. However when I execute the same script create.sh from create.php it doesn't work.

I'm executing my PHP script from the web browser by visiting the URL: http://192.168.8.108:8083/create.php

create.php – This file is responsible for running the create.sh file

echo shell_exec('/usr/local/panel/bin/create.sh');

create.sh – This file creates a directory under /var/www. The permission

#!/bin/bash
sudo mkdir -p /var/www/example.com

Upvotes: 0

Views: 143

Answers (1)

Zamrony P. Juhara
Zamrony P. Juhara

Reputation: 5262

You need to make sure that user who run php script has correct permission. If script create.php run as apache then you need to make sure apache user has write access to /var/www directory.

Upvotes: 1

Related Questions