Simple video uploading website, file uploaded from PHP handler not mirrored onto Nginx (Docker – Nginx + PHP-FPM FastCGI)

I have a class project where I have created docker containers to host a website that will be using PHP for backend logic. Currently, my NGINX container is configured to use the PHP-FPM container as it’s PHP handler.

The problem I am running into is where I am actually uploading the video file. Basically, when I (user on the website) upload the video file, using an upload box that calls PHP code move_uploaded_file the file can be seen in the ‘uploaded’ folder inside the PHP container. When I go to the NGINX container, the file is not there. I don’t know if I am missing some sort of configuration option where files created from PHP code will get mirrored onto the NGINX file directory?

If I restart the containers, the file now seems to show up in the NGINX container as well. The problem is when I try to view the file through the website, (embed tag), I get a 403 error back. I assume this has something to do with the user that PHP uploaded the file as?

So basically, I can upload a file which the PHP handlers deals with just fine. But I have to restart all the containers just for it to show up on the webserver. Then I have to open a terminal, and mess with the permissions, usually giving it chmod 777 to get it to play. I am wondering if there is something I am doing wrong?

Thanks and here is some of the relevant code.

ini_set("post_max_size", "50000000");

#echo 'Current script owner: ' . get_current_user();
$allowedExts = array("mp4", "mpg", "mpeg", "mov", "avi", "flv", "wmv");
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
if (in_array($extension, $allowedExts)){

    if (file_exists("uploaded/".$name)){
        echo $name . " already exists";
        $moved = move_uploaded_file($temp,"uploaded/".$name);
        echo $_SERVER['PHP_AUTH_USER'];
        chmod('uploaded/'.$name, 777);
        #exec('chmod 777 '.$_SERVER['DOCUMENT_ROOT'].'/uploaded/'.$name);
        #if ( $moved ){
            #echo "Successfully uploaded";  For debugging
            #echo "Not uploaded because of error #".$_FILES['file']['error']; For debugging
        $url = "http://localhost/uploaded/$name";
        if($statement = $mysqli->prepare("SELECT UserID from users where Username=?")){
                    die("Error - Issue executing prepared statement: " . mysqli_error($mysqli));
                if($res = $statement->get_result()){
                    $row = $res->fetch_assoc();
                    if($res->num_rows != 1){
                        die("False - User could not be found???");
                        $userID = $row['UserID'];
                $currDate = strval(date("M,d,Y h:i:s A"));
                if($statement = $mysqli->prepare("INSERT INTO video (UserID, URL, Name, UploadDate) VALUES(?,?,?,?)")){
                    if($statement->bind_param("isss", $userID, $url, $name, $currDate)){
                            die("Error - Issue executing sql video upload" . mysqli_error($mysqli));
                            header( "Location: /upload.php?message=File%20uploaded%3A%20".$name);
        chmod($_SERVER['DOCUMENT_ROOT'].'/uploaded/'.$name, 777);




server {
    listen       80;
    #listen       443 ssl http2;
    #listen [::]:443 ssl http2;
    server_name  localhost;
    root /usr/share/nginx/html;
    #ssl_certificate /etc/nginx/conf.d/armbook.crt;
    #ssl_certificate_key /etc/nginx/conf.d/armbook.key;
    #ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    #ssl_ciphers         HIGH:!aNULL:!MD5;
    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    client_max_body_size 100M;
    access_log /var/log/nginx-access.log;

location / {
    root   /usr/share/nginx/html;
    index  index.php;

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;

# proxy the PHP scripts to Apache listening on
#location ~ .php$ {
#    proxy_pass;

# pass the PHP scripts to FastCGI server listening on
location ~ .php$ {
    root   /usr/share/nginx/html;
    fastcgi_split_path_info ^(.+.php)(/.+)$;
    fastcgi_pass   php:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
    fastcgi_param  PHP_VALUE "upload_max_filesize=128M n post_max_size=128M";
    include        fastcgi_params;

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#location ~ /.ht {
#    deny  all;


Source: StackOverflow