move_uploaded_file gives “failed to open stream: Permission denied” error

前端 未结 13 2006
攒了一身酷
攒了一身酷 2020-11-22 05:36

I keep getting this error when trying to configure the upload directory with Apache 2.2 and PHP 5.3 on CentOS.

In php.ini:

upload_tmp_dir = /var/www/ht         


        
13条回答
  •  清酒与你
    2020-11-22 06:15

    This problem happens when the apache user (www-data) does not have permission to write in the folder. To solver this problem you need to put the user inside the group www-data.

    I just made this:

    Execute this php code to discover the user used by apache. After, execute the commands in the terminal:

    user@machine:/# cd /var/www/html
    
    user@machine:/var/www/html# ls -l
    

    It will return something like this:

    total of files
    
    drwxr-xr-x 7 user group size date folder
    

    I kept the user but changed the group to www-data

    chown -R user:www-data yourprojectfoldername
    
    chmod 775 yourprojectfoldername
    

提交回复
热议问题