Categories
Mac

Where are the Apache Configuration files on Mac? – httpd.conf

Here’s where to find httpd.conf on Mac. This is the httpd.conf location on Mac OS X 10.6 Snow Leopard and Mac OS X 10.7 Lion. This article also shows how to make the httpd.conf directory visible in the Mac Finder.

What is Httpd.conf?

Httpd.conf is the Apache web server’s main configuration file. Mac OSX ships with Apache installed. See Apache’s configuration docs for how to configure Apache.

Httpd.conf Location on Mac

On Mac httpd.conf location is in the directory /etc/apache2. You can access this folder through the Mac Finder or through the Mac Terminal.

Checked on OS X 10.7, 10.6.8, 10.6.7.

Httpd.conf Location in Mac Finder

You won’t normally see even the /etc/apache2 directory showing up in the Mac Finder. I tried looking in Macintosh HD, but /etc doesn’t show up.)

I found a tip at Codejacked on how to open hidden files in the Finder.

Here’s how to view httpd.conf’s directory in the Mac’s finder:

  1. In the Finder, click the Go menu, and choose Go to Folder…
  2. Type in /etc/apache2.
  3. Click Go.

The Finder will show the apache2 folder, and in it, you’ll see httpd.conf.

Httpd.conf Location in Mac Terminal

You can also get to the httpd.conf file through a terminal session, which is okay if your comfortable in the Unix shell (bash):

tazpro:~ taz$ cd /etc/apache2

tazpro:apache2 taz$ ls
extra		magic		original	users
httpd.conf	mime.types	other

Can’t Save Httpd.conf?

Httpd.conf is protected by OSX from being edited. If you open it with the TextEdit application for example, you won’t be able to save it. For details to bypass this security, see How to Easily Edit Httpd.conf on Mac.

Restart Apache to Apply Configuration Changes

Don’t forget you will need to restart Apache for your configuration changes in httpd.conf to be applied. To restart Apache on Mac:

  1. Go to the Apple menu and choose System Preferences.
  2. Click on Sharing.
  3. Untick Web Sharing.
  4. Tick Web Sharing.
Categories
Ubuntu

Httpd.conf – What’s its Location on Ubuntu?

Here’s where to find the Apache 2 web server configuration file httpd.conf on Ubuntu.

Did you know that on Ubuntu, the main Apache configuration file is not httpd.conf? The main Apache config file is actually apache2.conf.

When Apache 2 reads apache2.conf, the contents of httpd.conf is included by an include directive in apache2.conf. Here’s the lines from apache2.conf that include httpd.conf:

# Include all the user configurations:
Include /etc/apache2/httpd.conf

So use httpd.conf on Ubuntu is specifically for your servers specific configuration. You may still need to want to edit apache2.conf at times, to change Apache’s configuration rather than add to it.

Httpd.conf Location

On Ubuntu, httpd.conf is located in the directory /etc/apache2. apache2.conf is also located in /etc/apache2.

Httpd.conf Location for Specific Ubuntu Versions

To ensure these locations are accurate, I’ve checked httpd.conf’s location on a number of different Ubuntu versions. The definitive article is Where is Httpd.conf’s Location on Ubuntu? at Ubuntu Gods.

Ubuntu Version httpd.conf Location
Ubuntu 7.04 Feisty Fawn /etc/apache2/httpd.conf
Ubuntu 8.10 Intrepid Ibex /etc/apache2/httpd.conf
Ubuntu 10.10 Maverick Meerkat /etc/apache2/httpd.conf

Additions & refinements welcome!

Categories
Apache

The Six Most Common Htaccess Problems and How to Fix Them

Is your Apache htaccess not working? Here are the top reasons why an htaccess file may not work, and how get your htaccess working.

Htaccess Problem #1: No Dot Before the Filename

The .htaccess file’s filename must start with a dot, like so:

.htaccess

Files and directory names starting with a dot are treated as hidden files by Unix, Linux & Mac. The htaccess file is hidden so it doesn’t distract from normal web content like HTML files. See hidden files for more information.

Without the dot at the beginning, Apache will ignore the htaccess file.

Htaccess Problem #2: Filename Not All Lowercase

If an htaccess file’s name contains uppercase letters, it generally will not work on Linux or Unix. This is because filenames on Linux and Unix are usually case sensitive. If an htaccess file has any uppercase letters, e.g. .HTACCESS or .HTaccess, Apache won’t find the htaccess file. The htaccess is ignored.

An htaccess file containing uppercase letters generall will work on Windows and Mac. This is because filenames on these platforms are generally case insensitive. I’d recommend sticking with lowercase, so your websites are portable to Linux servers. The use of uppercase letters could also circumvent Apache directives designed to prevent the contents of .htaccess files read from the web.

Htaccess Problem #3: Filename Misspelt

Common misspellings of the htaccess file’s name are htacess and htacess. Check the filename has two c’s and two s’s.

Htaccess Problem #4: Htaccess Disabled by AllowOverride Setting

On some servers, Apache is configured to ignore some or all directives in .htaccess files. This is for security reasons. The AllowOverride directive controls which features will be allowed in .htaccess files. For example AllowOverride None can turn off htaccess files for a folder and its subfolders.

Check your Apache configuration file for which AllowOverride directive is applied to the directory containing your problem htaccess file.

If you’re not sure which configuration file to look in, start with the main Apache configuration file httpd.conf or apache2.conf. If your website is configured in a file included by httpd.conf (e.g. a virtual hosts configuration file), you will need to look in that file. See Location of httpd.conf on CentOS, Ubuntu, Mac and others to locate your httpd.conf.

To enable using a .htaccess file, change AllowOverride None to AllowOverride All.

For example, for a CentOS 5.3 server, I needed to change the AllowOverride setting in the file /etc/httpd/conf.d/virtualhosts.conf.

httpd.conf before:

Options FollowSymLinks
AllowOverride None

httpd.conf after:

Options FollowSymLinks
AllowOverride All

Be aware that enabling htaccess files has security implications, as htaccess files override your Apache configuration. For example, if your site provides uploads, a hacker could potentially upload a .htaccess file to your server and use it to gain access to your server. There are options to AllowOverride that restrict the directives that will be used from a .htaccess file. See the documentation for AllowOverride.

Htaccess Problem #5: Incorrect Syntax

If Apache can’t understand a line in your htaccess, it will usually cause an error from Apache. The error may show in the web browser when a webpage causes Apache to read the .htaccess file.

To demonstrate this, I added a bad line to the Smart Web Developer .htaccess file. See if you can spot the bad line. 🙂

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

utter rubbish config line here

This causes the following error in the browser:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

The reason for the error is logged to an Apache error log:

[Sat Feb 26 18:21:09 2011] [alert] [client 127.0.0.1] /Users/taz/Sites/smartwebdeveloper/.htaccess: Invalid command 'utter', perhaps misspelled or defined by a module not included in the server configuration, referer: http://smartwebdeveloper.com/

Another option to debug Apache syntax is to put the the .htaccess contents into the main Apache configuration file under a <Directory> directive. Apache has an option to parse and check its configuration files. To run an Apache syntax check, run: httpd -S.

Htaccess Problem #6: Htaccess Settings Overridden by Another Htaccess File

Multiple .htaccess files may be read and applied if a web request is made to a file in nested directories. Typically all .htaccess files in the path between the website’s root directory and the requested file’s directory will be read and applied in order. As a result, an htaccess file in a more deeply nested directory can override the settings made by an htaccess in a higher directory.

Is there another .htaccess file in another directory in the path to your webpage? That htaccess file the may be overriding the settings in the htaccess you’re looking at.

On Mac, Linux & Unix, you can find all .htaccess files on your website in the terminal:

find /path/to/website/root -iname .htaccess -print

Conclusion

Hope this article helped you! If it did, write me a comment and let me know.

Categories
Apache

How to Redirect a Domain Using an Apache .htaccess File

Why Redirect From Your www Domain to Your www-less Domain

For example, why would you redirect from www.smartwebdeveloper.com to smartwebdeveloper.com.

To search engines these are two different domains with identical content.

Your incoming links may get spread between the two domains – some links to pages in the www-prefixed domain and some links to the www-less domain.

Your SEO link juice gets spread between two sites. You could end up with two sites with two different page ranks, instead of a single site with a higher page rank than both.

Forward www to www-less Domain Using .htaccess

A good solution is to forward all pages at the www domain to the non-www domain. An HTTP response code of 301Moved Permanently – is the best response, because it says “this page isn’t here, this is it’s permanent URL”, because Google will still count any links to the www-prefixed domain towards your sites rankings.

To do this, in the root HTML directory for the www-prefixed domain, create a .htaccess file like the following:

#
# [taz] Redirect requests for www.smartwebdeveloper.com to
# smartwebdeveloper.com using Apache's rewrite engine.
#
RewriteEngine on

# [taz] Redirect requests for www.smartwebdeveloper.com,
# with an optional terminating '.' (DNS domains can be terminated with '.'),
# and optionally ending with :port (e.g. ':443' for SSL).
RewriteCond %{HTTP_HOST} ^www\.smartwebdeveloper\.com\.?(:[0-9]*)?$ [NC]

# [taz] Do a HTTP 301 redirect (i.e. page permanently moved)
# to the same URI at smartwebdeveloper.com.
RewriteRule ^(.*)$ http://smartwebdeveloper.com/$1 [R=301,L]

If you have troubles getting the .htaccess to work, try this .htaccess troubleshooting article.

Tested on CentOS 5.3.

Categories
Apache

Httpd.conf’s Location on CentOS, Ubuntu, Red Hat, Mac and Others

Here’s where to find the Apache 2 web server configuration file httpd.conf The httpd.conf directory differs across Linux & Unix variants like CentOS, Mac OS X, Red Hat, Ubuntu and XAMPP Mac.

This table lists the httpd.conf location for each operating system:

Operating System / Linux Distro httpd.conf Location
CentOS 5.2 /etc/httpd/conf/httpd.conf
CentOS 5.3 /etc/httpd/conf/httpd.conf
Mac OSX 10.6 Snow Leopard /etc/apache2/httpd.conf
Mac OSX 10.7 Lion /etc/apache2/httpd.conf
Red Hat Enterprise Linux Server 5.6 Tikanga (RHEL) /etc/httpd/conf/httpd.conf
Ubuntu 7.04 Feisty Fawn /etc/apache2/httpd.conf
Ubuntu 8.10 Intrepid Ibex /etc/apache2/httpd.conf
Ubuntu 10.10 Maverick Meerkat /etc/apache2/httpd.conf
XAMPP on Mac /Applications/XAMPP/etc/httpd.conf

For more specific information on Ubuntu, see httpd.conf location on Ubuntu.

The location for Fedora will likely be the same as CentOS (same distro family).

The location for Debian will likely be the same as Ubuntu (same distro family).

If your operating system or Apache package isn’t mentioned here, you can use the find command on Linux, Unix or Mac to find httpd.conf, e.g.:

find / -name httpd.conf 2>/dev/null

On Windows, you can use the search facility of Windows Explorer to find httpd.conf.

Additions & refinements welcome!