Solved

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

Posted on 2010-09-19
13
1,069 Views
Last Modified: 2013-11-15
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
0
Comment
Question by:aytheta
13 Comments
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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

0
 
LVL 6

Expert Comment

by:bimal_linux
Comment Utility
Can you paste the sample URL that throwing 404 error and relevant error_log of apache?
0
 

Author Comment

by:aytheta
Comment Utility
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?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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.
0
 

Author Comment

by:aytheta
Comment Utility
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.

0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
"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.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:aytheta
Comment Utility
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.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Try renaming or deleting the '.htaccess' files and try 'All' again.  Make sure there is an 'index.html' in yur web root.
0
 

Author Comment

by:aytheta
Comment Utility
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?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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

0
 

Author Comment

by:aytheta
Comment Utility
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.
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
"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.
0
 
LVL 1

Accepted Solution

by:
namaiand earned 500 total points
Comment Utility
Here is how you get .htaccess working on a Ubuntu machine (or any linux machine that is running apache for that matter).


http://www.sitedeveloper.ws/tutorials/htaccess.htm
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Are you sitting there reading this and wondering how to get started with Linux? It almost seems like picking the right Linux distribution is about like picking the right college or buying a new car if you read some of the article out there. Relax… l…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now