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

Red Virus

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
  • Owner: root Access: Read and Write
  • Group: root Access: Read-only
  • Public: Access: Read-only
Zamrony P. Juhara

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Altair doesn't display charts when running a script from terminal?

Shell script doesn't run properly while running from crontab

Running python script on background using PHP shell_exec

Why is this shell script not running as expected from PHP?

EXEC in SHELL script running from .bashrc in console

open terminal failed: missing or unsuitable terminal: unknown when running shell script from Java program

Why can't I run the composer script from PHP using exec, shell_exec, system?

Shell script running from cron not running python

php - running shell command using shell_exec

Git pull via PHP shell_exec( ) works from SSH shell but not from web-browser

Running script function from editor doesn't work as expected

ModuleNotFoundError when running script from Terminal

Running PHP Script from terminal with parameters

PHP Calling shell_exec on a bash script running a background process times out

ERROR: Repository not found whilst running git pull via shell_exec on php script

Running python script from shell script with newline

Tkinter NameError only when running script from shell

Shell script called from PHP does not work, but it works in command line

Running new project from WebStorm interface crashes while running from shell doesn't?

Running program and providing input from shell script

Running a Python script from the Python Shell

Running a bash script from a zsh shell

Running a java program from shell script with redirection

Running a shell script in Android from the Host

Running shell command from Gradle script

Running Grunt from OSX Automator shell script

Running shell command from python script with \n

Command not running from inside shell script

Not seeing shell prompt or input when running docker exec from a Makefile