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

前端 未结 13 2009
攒了一身酷
攒了一身酷 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:07

    I wanted to add this to the previous suggestions. If you are using a version of Linux that has SELinux enabled then you should also execute this in a shell:

    chcon -R --type httpd_sys_rw_content_t /path/to/your/directory
    

    Along with giving your web server user permissions either through group or changing of the owner of the directory.

    0 讨论(0)
  • 2020-11-22 06:07

    I ran into this related issue even after having already successfully run composer. I updated composer, and when running composer install or php composer.phar install I got:

    ...failed to open stream: Permission denied...

    It turns out after much research that the previous answers regarding changing permissions for the folder worked. They are just slightly different directories now.

    In my install, on OS X, the cache file is in /Users/[USER]/.composer/cache, and I was having trouble because the cache file was owned by root. Changing ownership of '.composer' recursively to my user solved the issue.

    This is what I did:

    sudo chown -R [USER] cache
    

    Then I ran the composer install again and voila!

    0 讨论(0)
  • 2020-11-22 06:08

    Try this

    find /var/www/html/mysite/images/ -type f -print0 | xargs -0 chmod -v 664

    0 讨论(0)
  • 2020-11-22 06:10

    If you have Mac OS X, go to the file root or the folder of your website.

    Then right-hand click on it, go to get information, go to the very bottom (Sharing & Permissions), open that, change all read-only to read and write. Make sure to open padlock, go to setting icon, and choose Apply to the enclosed items...

    0 讨论(0)
  • 2020-11-22 06:11

    Try this:

    1. open /etc/apache2/envvars

      sudo gedit /etc/apache2/envvars
      
    2. replace www-data with your your_username

      "export APACHE_RUN_USER=www-data" 
      

      replace with

      export APACHE_RUN_USER='your_username' 
      
    0 讨论(0)
  • 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 <?php echo exec('whoami'); ?> 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
    
    0 讨论(0)
提交回复
热议问题