Create directory (mkdir) with PHP 7.3 in Centos 7

Asked

Viewed 85 times

1

The shell command works normal via SSH, but PHP does not execute:

$cmd = '/bin/bash /usr/local/nginx/html/pHpServer-PG/api/dir.bash';
echo $cmd;
shell_exec($cmd);

BASH:

#!/bin/bash
/usr/bin/sudo mkdir -p /usr/local/nginx/html/nome_da_pasta

permissions

drwxrwxrwx.  8 ec2-user ec2-user  104 May  8 21:56 .
drwxr-xr-x. 12 ec2-user root      183 May  8 12:02 ..
drwxrwxrwx.  4 ec2-user ec2-user 4.0K May  8 21:31 admin
drwxrwxrwx.  4 ec2-user ec2-user 4.0K May  9 01:04 cliente
drwxrwxrwx.  3 ec2-user ec2-user 4.0K May  8 21:31 loja
drwxrwxrwx.  3 ec2-user ec2-user   17 May  8 12:20 pHpServer
drwxrwxrwx.  3 ec2-user ec2-user   17 May  8 12:09 pHpServer-ADm
drwxrwxrwx.  3 ec2-user ec2-user   17 May  8 12:15 pHpServer-PG

Note: I am using an AWS EC2 instance. The error log was this:

mkdir(): Permission denied

The user of php-fpm is the 'Nginx'.

  • 3

    It is no longer simple to use the mkdir of PHP?

  • Check if the user running php has sudo permission.

  • read: https://answall.com/questions/211599/php-mkdir-vs-chmod?rq=1

  • @Andersoncarloswoss unable to use mkdir other than the fatal error in php-fpm

  • @Felipekusk And it wouldn’t be interesting to understand/solve the fatal error?

  • @Andersoncarloswoss only in last case pq goes from work dmais the server and all modified with openresty Nginx etc only if can not do with bash msm I will start to enable the log to start looking

  • 1

    @David already tried all this stack post before arriving at bash

  • But what is the mistake that gives? That there is a lot of face XY problem.

  • @Andersoncarloswoss he does not run bash via php, but ssh works mormal

  • But what about the mistake you make using mkdir?

  • @Andersoncarloswoss will enable Aki logs to see it from, fatal error in php-fpm, I will analyze here and come back with the error

  • @Andersoncarloswoss aew the error log was as follows: mkdir(): Permission denied, php-fpm user and Nginx'

  • 1

    @Andersoncarloswoss and sister gave, thanks

  • 1

    See? Much easier than writing a script for this :D

  • @Andersoncarloswoss put this as an answer :D

Show 10 more comments

1 answer

0


I solved it this way:

// create folder

$dir = '/usr/local/openresty/nginx/html/nome_da_pasta';
mkdir($dir, 0777, true);

// error log

if (!@mkdir($dir)) {
    $error = error_get_last();
    echo $error['message'];
}

Release permission

chcon -R -t httpd_sys_rw_content_t /usr/local/openresty/nginx/html
  • Please edit the question to add details. The answer field is to answer the question, not the post itself.

  • Felipe, if this was the solution, want to mark as solved by clicking with the "V" green next to the post.

  • @Bacco can only be marked after 2 days.

  • 1

    @Bacco fought for correction

Browser other questions tagged

You are not signed in. Login or sign up in order to post.