Solved

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

Posted on 2010-09-19
13
1,081 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33713466
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
ID: 33713731
Can you paste the sample URL that throwing 404 error and relevant error_log of apache?
0
 

Author Comment

by:aytheta
ID: 33715023
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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 33718091
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
ID: 33723532
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 83

Expert Comment

by:Dave Baldwin
ID: 33727113
"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
 

Author Comment

by:aytheta
ID: 33728563
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 83

Expert Comment

by:Dave Baldwin
ID: 33728895
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
ID: 33729813
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 83

Expert Comment

by:Dave Baldwin
ID: 33732150
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
ID: 33733940
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 83

Expert Comment

by:Dave Baldwin
ID: 33736588
"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
ID: 33747699
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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

622 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