Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am running CentOS 6.4 and I have installed Wordpress on it. (along with LAMP)

Now the problem is, that I cannot make any write changes to any files in the wordpress editor: eg. header.php, style.css etc. Wordpress says the following where the 'update' button is suppose to be: You need to make this file writable before you can save your changes.

Notes:

  • Now Apache is running as the root user (default)
  • Here are the permissions on the themes folder where all the above mentioned files lie:

    drwxrwxr-x. 5 root bluegig 4096 Jul 7 17:32 themes

    drwxrwxr-x. 3 root apache 4096 Jul 7 23:15 uploads

I ran the chmod 775 command on both 'themes' and 'uploads', Now doing a chmod 777 gets me write permissions, but I don't believe that is very safe... Is there any other/better way of doing it?

(bluegig is the name of my domain, don't know why that is there...)

What I can do:

  • I can read and execute in Wordpress
  • I can upload files into the uploads folder from within wordpress

I cannot:

  • Make any changes to files within wordpress (via the editor)
  • How do I enable write permissions so that I can modify files in wordpress?

Note, I did not log into an ftp account from within WP.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

The installation of Apache may appears to be running as root but in actuality it's running as the user apache. You can check this by looking in this file:

$ grep "^User" /etc/httpd/conf/httpd.conf
User apache

Your entire wordpress directory should likely be owned by this user if you're planning on managing the installation using wordpress through the web UI.

I usually create a separate directory for wordpress like this:

$ pwd
/var/www
$ ls -l | grep wordpress
drwxr-xr-x. 5 apache apache    4096 Apr 25 19:27 wordpress

Here's the contents of the wordpress directory just so you can see it:

-rw-r--r--. 1 apache apache      395 Jan  8  2012 index.php
-rw-r--r--. 1 apache apache  5009441 Jan 23 13:40 latest.tar.gz
-rw-r--r--. 1 apache apache    19929 May  6  2012 license.txt
-rw-r--r--. 1 apache apache     9177 Jan 25 11:25 readme.html
-rw-r--r--. 1 apache apache     4663 Nov 17  2012 wp-activate.php
drwxr-xr-x. 9 apache apache     4096 Dec 11  2012 wp-admin
-rw-r--r--. 1 apache apache      271 Jan  8  2012 wp-blog-header.php
-rw-r--r--. 1 apache apache     3522 Apr 10  2012 wp-comments-post.php
-rw-rw-rw-. 1 apache apache     3466 Jan 23 17:15 wp-config.php
-rw-r--r--. 1 apache apache     3177 Nov  1  2010 wp-config-sample.php
drwxr-xr-x. 7 apache apache     4096 Apr 24 20:15 wp-content
-rw-r--r--. 1 apache apache     2718 Sep 23  2012 wp-cron.php
drwxr-xr-x. 9 apache apache     4096 Dec 11  2012 wp-includes
-rw-r--r--. 1 apache apache     1997 Oct 23  2010 wp-links-opml.php
-rw-r--r--. 1 apache apache     2408 Oct 26  2012 wp-load.php
-rw-r--r--. 1 apache apache    29310 Nov 30  2012 wp-login.php
-rw-r--r--. 1 apache apache     7723 Sep 25  2012 wp-mail.php
-rw-r--r--. 1 apache apache     9899 Nov 22  2012 wp-settings.php
-rw-r--r--. 1 apache apache    18219 Sep 11  2012 wp-signup.php
-rw-r--r--. 1 apache apache     3700 Jan  8  2012 wp-trackback.php
-rw-r--r--. 1 apache apache     2719 Sep 11  2012 xmlrpc.php

I usually also manage any Apache configs related to wordpress in it's own wordpress.conf file under this directory,/etc/httpd/conf.d/`.

# wordpress.conf
Alias / "/var/www/wordpress/"
<Directory "/var/www/wordpress/">
Order Deny,Allow
Deny from all
#Allow from 127.0.0.1 192.168.1
Allow from all
AllowOverride all
</Directory>
#RewriteLog "/var/www/wordpress/rewrite.log"
#RewriteLogLevel 3
share|improve this answer
    
Thank you slm, this is very helpful. I will try it out and let you know. Couple of questions: apache apache - Does that refer to the user apache and group apache? If I assign apache as the owner, what command do I need to issue so that apache alone is the owner and not bluegig eg. chmod 775 wp-content ? Also, What command do I use to make the apache user the owner - chown apache wp-content? –  DextrousDave Jul 9 '13 at 11:31
    
chmod -R apache.apache wordpress will change the user/group to apache for the entire directory wordpress. Permissions should be 775, so that only the user apache and group apache can access the directory. –  slm Jul 9 '13 at 11:33
    
thanks slm. You say only apache group and user will be able to access the folder - do you mean write access?...But certainly public must be able to view the files, how else will they see the website over port 80 on a web browser? –  DextrousDave Jul 9 '13 at 12:07
    
@DextrousDave - the file permissions don't really have anything to do with someone accessing a page through the webserver. Remember that the webserver is a process that opens the files, reading them in and then serves them to browsers as they connect to the server. The permissions are only in play when someone is directly logging into the server as a given user on the system. –  slm Jul 9 '13 at 13:34
    
of course, that makes sense. Just had a blonde moment.Thank you very much. I managed to make apache the owner and I added him to the bluegig group. Now I have write access inside wordpress. –  DextrousDave Jul 9 '13 at 14:39

(bluegig is the name of my domain, don't know why that is there...)

It would appear there's a group named blugig too somehow. You can confirm this:

grep bluegig /etc/group

Using the group permissions is one way to avoid using, eg., 777. You probably want scripts runs by a server to be readable and executable by it, but not writable; but you do want write permissions on them for some unprivileged admin/devel user (dave). Since the server runs as apache, if the file is owned by a group apache is not part of but dave is, and the permissions are 775, that's what you'll get (apache can read and execute, dave can read write execute).

If the line from /etc/group does not mention apache, then you could use bluegig as the group, or you could create a new one (groupadd). To put yourself in a group:

usermod -a -G bluegig dave

Your login name will now appear at the end of the bluegig entry in /etc/group, and you will be have the same permissions as the bluegig group.

share|improve this answer
    
Useless Use of Cat! Boo! :( –  rahmu Jul 9 '13 at 10:02
    
Point taken, lol. –  goldilocks Jul 9 '13 at 10:03
    
@rahmu - stickler 8-) –  slm Jul 9 '13 at 10:13
    
Thank you, I appreciate your help. I managed to make apache the owner and I added him to the bluegig group. Now I have write access inside wordpress. –  DextrousDave Jul 9 '13 at 14:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.