PHP - mkdir许可在数字海洋上被拒绝

I have deployed my Laravel application on DigitalOcean (without any third party packge usage). The application is functioning fine, except for uploading of files by the users.

I have installed LEMP stack by following the guide of DevMarketer (YouTube playlist).

Scenario:

I want to upload the file and store in my public directory. But, doing so, I get the error as Permission Denied.

Here's the code of directory that will get created it if not exist:

$path = public_path() . '/email-attachments/';

if (! file_exists($path)) {
    mkdir($path, 0775, true);
}

On SSHing on to the server as root, I ran the following command to check the permission of the files and folders:

root@host-pc:~# ls -la /var/www/laravel
total 456
drwxrwsr-x 12 www-data www-data   4096 Aug 21 09:45 .
drwxrwsr-x  4 www-data www-data   4096 Aug 18 07:13 ..
-rwxrwxr-x  1 www-data www-data    665 Aug 21 08:23 .env
-rw-rwSr--  1 www-data www-data    521 Aug 21 09:45 .env.example
-rw-rwSr--  1 www-data www-data    111 Aug 21 09:45 .gitattributes
-rw-rwSr--  1 www-data www-data    157 Aug 21 09:45 .gitignore
drwxrwsr-x  8 www-data www-data   4096 Aug 21 09:45 app
-rw-rwSr--  1 www-data www-data   1646 Aug 21 09:45 artisan
drwxrwsr-x  3 www-data www-data   4096 Aug 21 09:45 bootstrap
-rw-rwSr--  1 www-data www-data   1496 Aug 21 09:45 composer.json
-rw-rwSr--  1 www-data www-data 150371 Aug 21 09:45 composer.lock
drwxrwsr-x  2 www-data www-data   4096 Aug 21 09:45 config
drwxrwsr-x  5 www-data www-data   4096 Aug 21 09:45 database
-rw-rwSr--  1 www-data www-data   1063 Aug 21 09:45 package.json
-rw-rwSr--  1 www-data www-data   1100 Aug 21 09:45 phpunit.xml
drwxrwsr-x 10 www-data www-data   4096 Aug 21 09:45 public
-rwxrwxr-x  1 www-data www-data    440 Aug 21 06:27 queue_worker.log
drwxrwsr-x  5 www-data www-data   4096 Aug 18 07:56 resources
drwxrwsr-x  2 www-data www-data   4096 Aug 21 09:45 routes
-rw-rwSr--  1 www-data www-data    563 Aug 21 09:45 server.php
drwxrwsr-x  6 www-data www-data   4096 Aug 18 07:56 storage
drwxrwsr-x  4 www-data www-data   4096 Aug 21 09:45 tests
drwxrwsr-x 39 www-data www-data   4096 Aug 21 05:58 vendor
-rw-rwSr--  1 www-data www-data   1439 Aug 21 09:45 webpack.mix.js
-rw-rwSr--  1 www-data www-data 212974 Aug 21 09:45 yarn.lock

Following is the result of ps -ef | grep nginx

root@host-pc:~# ps -ef | grep nginx
root     14862     1  0 11:45 ?        00:00:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 14863 14862  0 11:45 ?        00:00:00 nginx: worker process
root     15489 12952  0 12:19 pts/0    00:00:00 grep --color=auto nginx

Following is the result of ps -ef | grep php

root@host-pc:~# ps -ef | grep php
root     10173  9901  0 05:05 ?        00:00:16 php /var/www/laravel/artisan queue:work --tries=5
root     10174  9901  0 05:05 ?        00:00:15 php /var/www/laravel/artisan queue:work --tries=5
root     10175  9901  0 05:05 ?        00:00:16 php /var/www/laravel/artisan queue:work --tries=5
root     10176  9901  0 05:05 ?        00:00:16 php /var/www/laravel/artisan queue:work --tries=5
root     10177  9901  0 05:05 ?        00:00:15 php /var/www/laravel/artisan queue:work --tries=5
root     10178  9901  0 05:05 ?        00:00:15 php /var/www/laravel/artisan queue:work --tries=5
root     10179  9901  0 05:05 ?        00:00:15 php /var/www/laravel/artisan queue:work --tries=5
root     10180  9901  0 05:05 ?        00:00:16 php /var/www/laravel/artisan queue:work --tries=5
root     15251     1  0 11:50 ?        00:00:00 php-fpm: master process (/etc/php/5.6/fpm/php-fpm.conf)
www-data 15255 15251  0 11:50 ?        00:00:02 php-fpm: pool www
www-data 15256 15251  0 11:50 ?        00:00:02 php-fpm: pool www
root     15495 12952  0 12:21 pts/0    00:00:00 grep --color=auto php

I don't know what is the mistake that I am doing (I know it must be a silly one), but I couldn't find the solution yet.

Please help me out with this. Thanks.

If you change this

$path = public_path() . '/email-attachments/';

To this

$path = public_path('email-attachments/');

Hopefully, This will help you.

 $path = base_path() . '/public/email-attachments';
 mkdir($path, 0755, true);