Had an issue on a WordPress site after I changed the permalinks to “
%postname%” from the default. Immediately after the change, all my wonderful posts gave 404 when I clicked on them.
So I researched it a bit and found some good recommendations (make sure
mod_rewrite is present, check permissions on
.htaccess). Initially it looked like a simple fix – the
.htaccess file needed to be populated (I didn’t allow the web server daemon write access to that file or the site’s directory). So I added the recommended code to that file directly (by the way, that file needs to be in
DocumentRoot for your site). However, that still didn’t fix it.
So I poked around some more and a couple of sites recommended checking
AllowOverride and similar settings. In my
AllowOverride was set to None.
My sites are in a separate file in
/etc/httpd/conf.d so I opened that file and added the following under the
VirtualHost section for that site:
AllowOverride Options FileInfo
(I obfuscated the path above, so in your file, whether
/etc/httpd/conf/httpd.conf or a site-specific file in
/etc/httpd/conf.d, Directory will certainly not be “
/site/home“). You can set
All, but do so at your own risk.
Then I bounced httpd and ta-da, it worked.
So, in summary:
-Check to make sure your web server loads
.htaccess (found in your site’s root, DocumentRoot) to writable so WordPress can modify it, OR modify it yourself by pasting in the code that WordPress shows you
-In your site’s config (either
/etc/httpd/conf/httpd.conf or your site-specific file in
AllowOverride Options FileInfo
-Bounce the web service
Had a real adventure getting a WordPress site going on a CentOS 5.8 LAMP server. It came down to two major areas: packages and permissions.
I asked the hosting provider to install pretty much just the base package group, knowing we could easily add on from there without having a lot of extra fluff. After a fair amount of troubleshooting (and very patient help from the site developer), I ended up installing the list below. Some of them may be unnecessary in the end, and many were pulled in as dependencies, but we got there.
Also, I had to run ‘
pecl install imagick‘. Newer versions of WordPress require PHP 5.2 and newer. CentOS provides 5.1 by default, but Red Hat back-ported 5.3 as php53 to accommodate the fact that so many things need it. One major discovery was that image resizing will break without ‘gd’ support. This came thru the php53-gd package, as well as the ImageMagic stuff.
Permissions, ownership, etc.
Like many web hosting setups, the apache user needs to be able to read directories, execute files, and in some cases write things. After lots of trial and error, we settled on these principles:
- The directory
wp-content (and its subdirectories) is owned by the site user, and is in the apache group
- The site owner is a member of the apache group as an additional group (i.e.
usermod -a -G apache user). You could also just make the apache group the primary group of the site user (
usermod -g apache user).
- All directories under wp-content are setgid (
chmod g+s), and are mode 775.
- All files are mode 664 (644 if you’re a bit paranoid, and for all .php files, but keep an eye out for things that break).