how to create folder on amazon ec2 linux aws serve

2019-09-21 07:37发布

$structure = '/upload';
if (!mkdir($structure, 0, true)) {
    die('Failed to create folders...');
}

this is my code, but i m not been able to create directory.it shows me the error Failed to create folders.

2条回答
闹够了就滚
2楼-- · 2019-09-21 07:57

First ssh to your ec2 instance and change the ownership and permission of your web root folder, assuming your web root folder is located in /var/www/html you can do the following:

sudo chown -R /var/www/html apache.apache

The code above will make apache the owner of the web root direction and it's contents

sudo chmod -R 0775 /var/www/html

The code above sets the necessary permission for the web root folder and contents, you should edit as needed.

After that run your code you should be able to create the folder.

查看更多
爷的心禁止访问
3楼-- · 2019-09-21 08:11

I don't think you can create folders in the root directory with PHP as it does not have the permission to do that.

However, what you probably could do, is to create a folder in the root directory through an ssh terminal and use that folder for your application

sudo mkdir /myApp

Next, set write permissions to myApp folder

 sudo chmod -R 777 myApp

subsequently, you would be able to create your "uploads" folder in /myApp

查看更多
登录 后发表回答