You are not logged in.

#1 2013-10-10 19:09:31

sethradio
Member
From: /dev/null
Registered: 2012-01-16
Posts: 53
Website

PHP can't write files

It seems that PHP cannot create files in my /srv/http directory. I have a WordPress install there. (No, I don't want to use the one from the repo) It can't create it's config file. After I did that manually it can't intall plugins. Of course I could do that manually to, but I'm lazy. smile


And lo, it came to pass, that the neophyte encountered the Beplattered One and humbly posed the question, "Oh great master, is it a sin to use vi?" And St. IGNUcius didst thus reply unto him, "No, my young hacker friend, it is not a sin. It is a penance."

Offline

#2 2013-10-10 19:57:56

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,641
Website

Re: PHP can't write files

php isn't a user. What web server are you running WordPress on? Or if WordPress has it's own server, what user is it running as? Give that user write permissions on the directories it should be able to write to.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#3 2013-10-11 17:07:50

sethradio
Member
From: /dev/null
Registered: 2012-01-16
Posts: 53
Website

Re: PHP can't write files

The wbserver is Apache and its user is http. What command do I use?


And lo, it came to pass, that the neophyte encountered the Beplattered One and humbly posed the question, "Oh great master, is it a sin to use vi?" And St. IGNUcius didst thus reply unto him, "No, my young hacker friend, it is not a sin. It is a penance."

Offline

#4 2013-10-11 17:10:08

WorMzy
Administrator
From: Scotland
Registered: 2010-06-16
Posts: 12,641
Website

Re: PHP can't write files

A combination of chmod and chown, depending on what the current permissions are.

https://wiki.archlinux.org/index.php/Pe … od_command
https://wiki.archlinux.org/index.php/Pe … wn_command


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#5 2013-10-11 18:01:20

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,498

Re: PHP can't write files

sethradio wrote:

After I did that manually it can't intall plugins. Of course I could do that manually to, but I'm lazy. smile

Me too, but a little searching could have brought you this line.

define('FS_METHOD', 'direct');

add it to wp-config.php.
result?

edit:did you also chmod  I believe it's this ones

chmod 777 /srv/http/wordpress/wp-config.php
chmod 777 /srv/http/wordpress/wp-content

Last edited by qinohe (2013-10-11 18:07:49)

Offline

#6 2013-11-10 03:40:58

donniezazen
Member
From: Salt Lake City
Registered: 2011-06-24
Posts: 671
Website

Re: PHP can't write files

Permission of wordpress folder has been troubling me too.

According to WordPress [1]

Typically, all files should be owned by your user (ftp) account on your web server, and should be writable by that account. On shared hosts, files should never be owned by the webserver process itself (sometimes this is www, or apache, or nobody user).

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).

The file and folder permissions of WordPress should be the same for most users, depending on the type of installation you performed and the umask settings of your system environment at the time of install.

I don't have a ftp account and I would not want one because of security issues.  I am not sure what user are they talking about - home user, root user,  web server user (apache - http or nginx -http), etc.

Most Debian based distribution seems to chown-ing www-data:www-data. And then adding home user to www-data group. CentOS/Fedora like seems to have apache and nginx as user and group. Arch has http.

WordPress does not recommend [2] setting anything to 777.

The solution that I am thinking for my system would be following.

chown -R http:http LocationToWordPressFolder/wordpress/
usermod -aG http HomeUser

Folder permissions are 755 and file permissions are 644. That means HomeUser as a group member of http would not be able to create files/folder (group = r-x) or write to files (group = r--) inside wordpress folder.  Or will it be able to? What do you guys think?

[1] http://codex.wordpress.org/Changing_File_Permissions
[2] http://codex.wordpress.org/Changing_Fil … ers_of_777


UPATE:- After chowning folders/files with nginx owner my WordPress install wouldn't require any kind of username or password. I am not sure if it a good security or bad security practice.

Last edited by donniezazen (2013-11-10 07:30:26)

Offline

#7 2013-11-10 10:11:43

qinohe
Member
From: Netherlands
Registered: 2012-06-20
Posts: 1,498

Re: PHP can't write files

Yes, you shouldn't give '777' permissions, but '755' you're right about that.

Now, I always used 'http' as user on arch-boxes, no other user but root has access to that files, and of course the site admin, but they don't have access on the root files in for instance 'srv/http/wordpress' , so that should be 'secure'.

You can also edit .htaccess, and use Allow/Deny from, to further close down the gate.

You don't really need ftp, you can use scp from/to, to copy files , it uses ssh and provides the same security.

Offline

Board footer

Powered by FluxBB