Link to home
Start Free TrialLog in
Avatar of aytheta
aytheta

asked on

How do I get .htaccess working on Ubuntu: suggestions I see so far do not work

Hello,

I'm a newbie on EE (evaluation period, ahem!) and really hope this forum can crack the problem for me. I am almost moving off Ubuntu for this simple reason.

My web app relies on URL rewriting to map friendly URLs to the actual. All efforts to get it to work (asides displaying the landing page) fails with the 404-file not found error for every page that depends on the rewrite.

This is Ubuntu 10.4 and my site files placed in /home/myuser/www/dsite

Now I have no .htaccess file in /home/myuser/www/ but there is one in /home/myuser/www/dsite with the relevant contents as follows:

<quote>

RewriteBase /dsite/
RewriteEngine On
RewriteRule ^index index.php

<unquote>

Following this comes  a whole bunch of rewrite statements in the htaccess file.

In the corresponding "dsite" file in /etc/apache2/sites-enabled I have the following relevant portions:

<quote>

DocumentRoot /home/myuser/www/dsite
<Directory />
      Options FollowSymLinks
      AllowOverride All
</Directory>
<Directory /home/myuser/www/dsite/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
</Directory>

<unquote>

The allowoverrides were initially set to "none" but googling/ EE etc advised changing this to All. However it has had no effect despite apache2 restarts.

The mod_rewrite is definitely installed.

Any assistance to resolve this challenge would be greatly appreciated.

Thank you
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

In httpd.conf, look for something like below and make sure it says 'All' and not 'None'.  'None' kills Override for that path so your statement would have no effect.

Also in 'apache2.conf' make sure "AccessFileName .htaccess" is present and not commented out.
<Directory /home/*/www />
      AllowOverride All
</Directory>

Open in new window

Avatar of bimal_linux
bimal_linux

Can you paste the sample URL that throwing 404 error and relevant error_log of apache?
Avatar of aytheta

ASKER

Sorry, it was actually not a 404 error, it's a "Unable to connect: Firefox can't establish a connection to the server at..." error.

Whilst troubleshooting I switched the site used to default, dumped the files in /var/www/dsite modified the entries with "All" again restarted apache. Still same problem, the site does not open until I change the entries back to None. Below is what I have in the default sites file (in sites-enabled).

      DocumentRoot /var/www
      <Directory />
            Options FollowSymLinks
            AllowOverride All
      </Directory>
      <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
      </Directory>

The site starts working again only when I change AllowOverride to None.

Below is the error log.

[Mon Sep 20 06:05:33 2010] [info] removed PID file /var/run/apache2.pid (pid=1853)
[Mon Sep 20 06:05:33 2010] [notice] caught SIGTERM, shutting down
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/mcrypt.ini on line 1 in Unknown on line 0
[Mon Sep 20 06:05:34 2010] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.2 with Suhosin-Patch configured -- resuming normal operations
[Mon Sep 20 06:05:34 2010] [info] Server built: Apr 13 2010 19:28:27
[Mon Sep 20 06:05:34 2010] [debug] prefork.c(1013): AcceptMutex: sysvsem (default: sysvsem)
[Mon Sep 20 06:08:42 2010] [info] removed PID file /var/run/apache2.pid (pid=2219)
[Mon Sep 20 06:08:42 2010] [notice] caught SIGTERM, shutting down
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/mcrypt.ini on line 1 in Unknown on line 0
[Mon Sep 20 06:08:43 2010] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.2 with Suhosin-Patch configured -- resuming normal operations
[Mon Sep 20 06:08:43 2010] [info] Server built: Apr 13 2010 19:28:27
[Mon Sep 20 06:08:43 2010] [debug] prefork.c(1013): AcceptMutex: sysvsem (default: sysvsem)
[Mon Sep 20 06:09:40 2010] [info] removed PID file /var/run/apache2.pid (pid=2286)
[Mon Sep 20 06:09:40 2010] [notice] caught SIGTERM, shutting down
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/mcrypt.ini on line 1 in Unknown on line 0
[Mon Sep 20 06:09:40 2010] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.2 with Suhosin-Patch configured -- resuming normal operations
[Mon Sep 20 06:09:40 2010] [info] Server built: Apr 13 2010 19:28:27
[Mon Sep 20 06:09:40 2010] [debug] prefork.c(1013): AcceptMutex: sysvsem (default: sysvsem)
[Mon Sep 20 06:10:26 2010] [info] removed PID file /var/run/apache2.pid (pid=2342)
[Mon Sep 20 06:10:26 2010] [notice] caught SIGTERM, shutting down
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/mcrypt.ini on line 1 in Unknown on line 0
[Mon Sep 20 06:10:27 2010] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.2 with Suhosin-Patch configured -- resuming normal operations
[Mon Sep 20 06:10:27 2010] [info] Server built: Apr 13 2010 19:28:27
[Mon Sep 20 06:10:27 2010] [debug] prefork.c(1013): AcceptMutex: sysvsem (default: sysvsem)
[Mon Sep 20 06:10:52 2010] [error] [client 192.168.1.107] File does not exist: /var/www/favicon.ico
[Mon Sep 20 06:10:55 2010] [error] [client 192.168.1.107] File does not exist: /var/www/dsite/aboutus, referer: http://ubuntu-lamp2/dsite/
[Mon Sep 20 06:11:34 2010] [info] removed PID file /var/run/apache2.pid (pid=2390)
[Mon Sep 20 06:11:34 2010] [notice] caught SIGTERM, shutting down
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/mcrypt.ini on line 1 in Unknown on line 0
[Mon Sep 20 06:11:35 2010] [notice] Apache/2.2.14 (Ubuntu) PHP/5.3.2-1ubuntu4.2 with Suhosin-Patch configured -- resuming normal operations
[Mon Sep 20 06:11:35 2010] [info] Server built: Apr 13 2010 19:28:27
[Mon Sep 20 06:11:35 2010] [debug] prefork.c(1013): AcceptMutex: sysvsem (default: sysvsem)

Ps. DaveBalwin: httpd.conf is empty and inserting that statement in apache2.conf has no effect. Is it meant to be the the exclusion on the above settings in the site config file?
If your 'httpd.conf' is empty, then I don't know how your Apache is configured.  I'm on Ubuntu 8.04 and Apache probably wouldn't run on my system without it.  I wonder if your Apache is not installed properly.
Avatar of aytheta

ASKER

DaveBaldwin,

I think things changed for 10.04. Apache2.conf is the main config file and conf.d has become optional for further user settings.

At https://help.ubuntu.com/10.04/serverguide/C/httpd.html is says:

apache2.conf: the main Apache2 configuration file. Contains settings that are global to Apache2.

conf.d: contains configuration files which apply globally to Apache2. Other packages that use Apache2 to serve content may add files, or symlinks, to this directory.

envvars: file where Apache2 environment variables are set.

httpd.conf: historically the main Apache2 configuration file, named after the httpd daemon. The file can be used for user specific configuration options that globally effect Apache2.

"httpd.conf" is used on my system to set up 'User directories' in 'public_html'.  In 'sites-available', 'default' is for the system web directory which in my case is '/var/www/'.  It has 'AllowOverride None'.  The symlink in 'sites-available' points to that file.  I have to bring up another system that is actually using '.htaccess' but I probably won't be able to do that until tomorrow.
Avatar of aytheta

ASKER

Thanks, look forward to anything you can find.

Like I said, my "default" file in "sites-enabled" has the following:

      DocumentRoot /var/www
      <Directory />
            Options FollowSymLinks
            AllowOverride All
      </Directory>
      <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
      </Directory>

It is very strange that the site works when I change all AllowOverrides to "None" but when it is set to "All" as above, it gives a server not found errror.
Try renaming or deleting the '.htaccess' files and try 'All' again.  Make sure there is an 'index.html' in yur web root.
Avatar of aytheta

ASKER

There has always been the default index.html in the web root which is /var/www/

With the .htaccess file deleted, the site works with "All" against AllowOverrides. Of course the portions that are dependent on the rewrite rules turn up error 404.

Immediately I put back the .htaccess in the web folder, it stops working. Until I change AllowOverrides back to "None".

Please note though:

- there is no .htaccess in /var/www/
- the .htaccess is only in /var/www/dsite/ folder

Is there anything wrong with the structure I have above for the DocumentRoot statements?

Is there a requirement to have a .htaccess in /var/www as well?

Is there anyway to achieve the rewrite rules directly in php or in some other config file asides .htaccess since this is proving so tough?
Here's the page on "EnablingUseOfApacheHtaccessFiles":
https://help.ubuntu.com/community/EnablingUseOfApacheHtaccessFiles

Read the whole page.  Also, you should not be putting your files in 'sites-enabled' but in 'sites-available'.  See https://help.ubuntu.com/community/ApacheMySQLPHP#Installing%20Apache%202.

Researching this helped fix a minor problem with my Apache installation.

The best way to tell if '.htaccess' is working is to put an '.htaccess' file with just ErrorDocument statements.  It doesn't otherwise affect the operation but it can tell you whether it's working.
ErrorDocument 404 /404.html

Open in new window

Avatar of aytheta

ASKER

Thanks, will look at those docs again. I believe I already did.

As per sites-available, corresponding files are generated in sites-enabled after you run /etc/init.d/apache2 reload (or restart). I always do this so my sites-enabled has the updated info.
"sites-enabled" is supposed to be 'links' to the files in "sites-available"  but it will work to put the files in "sites-enabled".    "Ubuntu provides two small utilities that take care of this: a2ensite (apache2enable site) and a2dissite (apache2disable site)."

I pointed you to those pages because I think your default installation has gotten messed up.  The 'ErrorDocument' version is a way of telling whether '.htaccess' is working that won't block access to the files in that directory.  There are three lines that need to go in Apache2.conf as well as the per directory configs.

If there is any doubt, Apache can be a lot of trouble to set up.
ASKER CERTIFIED SOLUTION
Avatar of namaiand
namaiand
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial