Folder is not writable php

The directory is not writable by the Web process

Поставил на сервер nginx + php7.0-fpm+mysql, все работает, залил на сервер сайт и получаю ошибку:

The directory is not writable by the Web process: /var/www/site.ru/web/assets

Фреймворк Yii2, так понимаю ему не хватает прав для записи, в php www.conf стоят данные:

user = dogmar group = dogmar listen.owner = dogmar listen.group = dogmar listen.mode = 0777 

В командной строке прописал:

chown -R dogmar:dogmar /var/www/site.ru/web/assets 

Пожалуйста подскажите, куда копать?

Ответы (3 шт):

У папки assets должны быть права на запись, сделайте chmod 777 /var/www/site.ru/web/assets

chown -R dogmar:dogmar /var/www/site.ru/web/assets 

если и после того, как вы сменили владельца каталога (и всего его содержимого), ошибка присутствует, вероятно, у каталога (и, возможно, содержимого) нет бита, разрешающего запись. добавьте его:

$ sudo chmod -R ug+w,o-w /var/www/site.ru/web/assets 
  • ug+w — добавить бит записи для владельца и его группы (user и group)
  • o-w — убрать бит записи для всех остальных (others) — на всякий случай. не помешает.

У меня тоже была такая проблема, но я решал ее через php init.

введите сюда описание изображения

Как вы видите на фото, таким образом даются права на запись папкам

 chmod 0777 backend/runtime chmod 0777 backend/web/assets chmod 0777 console/runtime chmod 0777 frontend/runtime chmod 0777 frontend/web/assets 

Источник

is_writable

Returns true if the filename exists and is writable. The filename argument may be a directory name allowing you to check if a directory is writable.

Keep in mind that PHP may be accessing the file as the user id that the web server runs as (often ‘nobody’).

Parameters

The filename being checked.

Return Values

Returns true if the filename exists and is writable.

Errors/Exceptions

Upon failure, an E_WARNING is emitted.

Examples

Example #1 is_writable() example

$filename = ‘test.txt’ ;
if ( is_writable ( $filename )) echo ‘The file is writable’ ;
> else echo ‘The file is not writable’ ;
>
?>

Notes

Note: The results of this function are cached. See clearstatcache() for more details.

As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to Supported Protocols and Wrappers to determine which wrappers support stat() family of functionality.

See Also

  • is_readable() — Tells whether a file exists and is readable
  • file_exists() — Checks whether a file or directory exists
  • fwrite() — Binary-safe file write

User Contributed Notes 15 notes

Be warned, that is_writable returns false for non-existent files, although they can be written to the queried path.

To Darek and F Dot: About group permissions, there is this note in the php.ini file:
; By default, Safe Mode does a UID compare check when
; opening files. If you want to relax this to a GID compare,
; then turn on safe_mode_gid.
safe_mode_gid = Off

It appears that is_writable() does not check full permissions of a file to determine whether the current user can write to it. For example, with Apache running as user ‘www’, and a member of the group ‘wheel’, is_writable() returns false on a file like

-rwxrwxr-x root wheel /etc/some.file

Check director is writable recursively. to return true, all of directory contents must be writable

function is_writable_r ( $dir ) if ( is_dir ( $dir )) if( is_writable ( $dir )) $objects = scandir ( $dir );
foreach ( $objects as $object ) if ( $object != «.» && $object != «..» ) if (! is_writable_r ( $dir . «/» . $object )) return false ;
else continue;
>
>
return true ;
>else return false ;
>

>else if( file_exists ( $dir )) return ( is_writable ( $dir ));

This file_write() function will give $filename the write permission before writing $content to it.

Note that many servers do not allow file permissions to be changed by the PHP user.

function file_write ( $filename , & $content ) <
if (! is_writable ( $filename )) if (! chmod ( $filename , 0666 )) echo «Cannot change the mode of file ( $filename )» ;
exit;
>;
>
if (! $fp = @ fopen ( $filename , «w» )) echo «Cannot open file ( $filename )» ;
exit;
>
if ( fwrite ( $fp , $content ) === FALSE ) echo «Cannot write to file ( $filename )» ;
exit;
>
if (! fclose ( $fp )) echo «Cannot close file ( $filename )» ;
exit;
>
>
?>

Regarding you might recognize your files on your web contructed by your PHP-scripts are grouped as NOBODY you can avoid this problem by setting up an FTP-Connection («ftp_connect», «ftp_raw», etc.) and use methods like «ftp_fput» to create these [instead of giving out rights so you can use the usual «unsecure» way]. This will give the files created not the GROUP NOBODY — it will give out the GROUP your FTP-Connection via your FTP-Program uses, too.

Furthermore you might want to hash the password for the FTP-Connection — then check out:
http://dev.mysql.com/doc/mysql/en/Password_hashing.html

The results of this function seems to be not cached :
Tested on linux and windows

chmod ( $s_pathFichier , 0400 );
echo ‘

' ; var_dump ( is_writable ( $s_pathFichier ));echo '

‘ ;
chmod ( $s_pathFichier , 04600 );
echo ‘

' ; var_dump ( is_writable ( $s_pathFichier ));echo '

‘ ;
exit;
?>

This function returns always false on windows, when you check an network drive.

We have two servers: one running PHP 5.0.4 and Apache 1.3.33, the other running PHP 4.3.5 and Apache 1.3.27. The PHP 4 server exhibits the behavior you are describing, with is_writable() returning ‘false’ even though the www user is in the group that owns the file, but the PHP 5 server is returning ‘true.’

This is the latest version of is__writable() I could come up with.
It can accept files or folders, but folders should end with a trailing slash! The function attempts to actually write a file, so it will correctly return true when a file/folder can be written to when the user has ACL write access to it.

function is__writable ( $path ) //will work in despite of Windows ACLs bug
//NOTE: use a trailing slash for folders.
//see http://bugs.php.net/bug.php?id=27609
//see http://bugs.php.net/bug.php?id=30931

if ( $path < strlen ( $path )- 1 >== ‘/’ ) // recursively return a temporary file path
return is__writable ( $path . uniqid ( mt_rand ()). ‘.tmp’ );
else if ( is_dir ( $path ))
return is__writable ( $path . ‘/’ . uniqid ( mt_rand ()). ‘.tmp’ );
// check tmp file for read/write capabilities
$rm = file_exists ( $path );
$f = @ fopen ( $path , ‘a’ );
if ( $f === false )
return false ;
fclose ( $f );
if (! $rm )
unlink ( $path );
return true ;
>
?>

Since looks like the Windows ACLs bug «wont fix» (see http://bugs.php.net/bug.php?id=27609) I propose this alternative function:

function is__writable ( $path )

if ( $path < strlen ( $path )- 1 >== ‘/’ )
return is__writable ( $path . uniqid ( mt_rand ()). ‘.tmp’ );

if ( file_exists ( $path )) if (!( $f = @ fopen ( $path , ‘r+’ )))
return false ;
fclose ( $f );
return true ;
>

if (!( $f = @ fopen ( $path , ‘w’ )))
return false ;
fclose ( $f );
unlink ( $path );
return true ;
>

?>

It should work both on *nix and Windows

NOTE: you must use a trailing slash to identify a directory

function is_writable(‘ftp://user. ‘) always return false. I can create/delete files, but can check is writable. Is this bug or php feature :)?

I’d like to also clarify a point on this. Even if you see 777 permissions for the directly, you may need to check your ACL, since your server’s group might not have write permissions there.

Check if a directory is writable. Work also on mounted SMB shares:

Источник

Upload folder is not writable, even when permissions are correct

Naturally, I check the permissions of the folder — and they are correct. Just to be safe, I changed it recursively to «777» (as a test, not permanently), and I still cannot upload images. How can I troubleshoot this issue?

I had to run stat -c %a /apps/wordpress/wp-content/uploads/ and then chmod -R 775 /apps/wordpress/wp-content/uploads/

Very simple, go to youe WB dashboard sitting — media — past the defult (wp-content/uploads) then press SAVE

8 Answers 8

That’s a server permission problem. According to the WP docs:

Any file that needs write access from WordPress should be owned or group-owned by the user account used by the WordPress (which may be different than the server account). For example, you may have a user account that lets you FTP files back and forth to your server, but your server itself may run using a separate user, in a separate usergroup, such as dhapache or nobody. If WordPress is running as the FTP account, that account needs to have write access, i.e., be the owner of the files, or belong to a group that has write access. In the latter case, that would mean permissions are set more permissively than default (for example, 775 rather than 755 for folders, and 664 instead of 644).

How can I troubleshoot this issue?

Ask Webfaction. Sounds like they need to give you the ability to chmod files/folders or they need to do it for you.

And, FYI, search first for a common issue like permissions; there are many answers already on WP Dev.

Источник

How to Fix: ‘Upload folder is not writable’ WordPress

WP Mantis WordPress Support

This error is commonly seen when trying to upload media or plugins and themes.

The error message may also read, “Unable to create directory…”

Most of the time, when I see this issue, it’s after a site has been moved, migrated from a developer to your account or moved from one host to another.

Here’s why it’s not working.

There is an “upload path” stored in the database so that WordPress knows where to put your files once you upload them in the WP Admin.

When you migrate a site from one hosting account to another, that upload path is not going to be the same and therefore WordPress can not “write to that path”.

How we fix this issue.

I’ll show you three ways to correct this, each require a different level of skills. However, and this is important, in some cases you will not be able to use the first option below.If you rather have a WP Geek fix this issue for you, just order a One Time Fix here!

From within the WP Admin

  1. Click on “Settings”
  2. Click on “Media”
  3. Look for “Upload Files Section”
  4. Look for “Store uploads in this folder”
  5. Replace whatever is there with “wp-content/uploads” (without the quotes)
  6. Click “Save Changes”
  7. DONE!

From the Database – More Advanced

  1. Login to phpMyAdmin
  2. Click on Database name on left
  3. Click on “wp_options” table
  4. Click on “Browse”
  5. Find the “upload_path” row
  6. Replace what is there with “wp-content/uploads”
  7. DONE!

From options.php

This provides a simplified view of the Database tables.

  1. Go to domain.com/wp-admin/options.php (replace domain.com with your domain name)
  2. Scroll down to find “upload_path”
  3. Replace what is there with “wp-content/uploads”
  4. Click “Save Changes”
  5. DONE!

Wrapping up, ‘Upload folder not writable’ fix…

After following one of the fixes above, you should be able to go and successfully upload your file.

If you have questions, or need further assistance, please use the comments or chat below.

Done-For-You Service

Want us to fix it for you!? If you don’t want to waste time with these tech issues, we’re happy to do-it-for-you! You can feel confident knowing you’ve got an expert fixing it for you!

Источник

Читайте также:  CSS цвет
Оцените статью