Installing WordPress is pretty straightforward and needs no further clarification here. But getting Permalinks to work – well that is a different story. That is not well documented. Permalinks are those nice-looking URLs you can optionally create for your blog postings in WordPress. I myself like this style: WPROOT/YYYY/MM/nice-title/.
When you try to activate that you’ll see it wants to put a .htaccess file in your blog top-level directory, which you may not have permission to write to from your admin account. I do not because I feel that is a more secure way to run the server – as a user who cannot write to the HTML directories. Fortunately, it generates the desired contents of the .htaccess file, which is characteristically inscrutable like most things in Apache server (I’m not a big fan of Apache). So it will look something like this (bear in mind my WordPress blog was put in the /blog directory).
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> |
The main point is that it relies on the mod_rewrite module in apache2, which probably won’t work for you under a straight-up Ubuntu LAMP installation for two reasons. And if you dig around you’ll quickly latch onto one or the other reason, but not both.
You need to activate mod_rewrite.
You need to enable mod_rewrite in your conf file.
To activate mod_rewrite run
sudo a2enmod rewrite
(of course I’m assuming you have root access). This stands for, more-or-less, Apache2 enable module rewrite. Note what it does, it creates symlinks from the /etc/apache2/mods-enabled directory for each module which has been enabled. By default, mod_rewrite is NOT enabled in Ubuntu server 10.10, for some reason.
In your Apache configuration file (yours may be /etc/apache2/sites-enabled/000-default or another file in that directory) you’ll probably have this statement in your Directory section that pertains to your WordPress document root:
AllowOverride none
You will need to change it to
AllowOverride All
For instance, for me with my WordPress blog root at /var/www/blog, my Apache configuration file now looks like this:
<VirtualHost *:80> ... <Directory /var/www/blog> AllowOverride All </Directory> ... |
Restart Apache, make sure those .htaccess lines are in your blog’s main directory, and you should be good to go.
5 replies on “WordPress, Apache2, Permalinks and mod_rewrite under Ubuntu”
Read your page like a person who came to you not knowing. Seems great till you read this:
“In your conf file you’ll probably have this statement in your Directory”
Look back through your page… have you ever mentioned this “Conf file” or “Directory” before? What are they? Where are they?
I knw it’s been a long time, but your page still comes up… and still just adds to the confusion.
I modified that sentence and added an example. I assume there could be a lot of variability in Apache configurations and I am far from an expert, so I don’t know if this makes it any more clear. But I tried.
i found your example, which cause me a headache and uploaded three times…
I solved it….
exactly like you say
Override All !!
I just can’t make it work.
Hello John,
thank you so much for this post, it solved my trouble with permalinks.
Cheers,
Imre