How to troubleshoot Mountain Lion’s Apache

After I install Mac OS X Mountain Lion, it seems like my Apache server can no longer start successfully:

[code lang=”bash”]bash-3.2# sudo tail /private/var/log/apache2/error_log
[Thu Aug 02 09:36:46 2012] [notice] caught SIGTERM, shutting down
[Thu Aug 02 09:37:57 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
httpd: Could not reliably determine the server’s fully qualified domain name, using kahwee-mba.local for ServerName
[Thu Aug 02 09:37:57 2012] [notice] Digest: generating secret for digest authentication …
[Thu Aug 02 09:37:57 2012] [notice] Digest: done
[Thu Aug 02 09:37:57 2012] [notice] Apache/2.2.22 (Unix) DAV/2 mod_ssl/2.2.22 OpenSSL/0.9.8r configured — resuming normal operations
[Thu Aug 02 09:46:17 2012] [error] [client 127.0.0.1] File does not exist: /Library/WebServer/Documents/favicon.ico
[Thu Aug 02 09:54:19 2012] [error] [client 127.0.0.1] File does not exist: /Library/WebServer/Documents/r, referer: http://home.internal.kw.sg/
[Thu Aug 02 09:54:19 2012] [error] [client 127.0.0.1] File does not exist: /Library/WebServer/Documents/favicon.ico
[Thu Aug 02 09:54:31 2012] [notice] caught SIGTERM, shutting down
[/code]

To find out why, run apachectl -t:

[code lang=”bash”]
bash-3.2# sudo apachectl -t
httpd: Syntax error on line 106 of /private/etc/apache2/httpd.conf: Cannot load /usr/libexec/apache2/mod_dav_fs.so into server: dlopen(/usr/libexec/apache2/mod_dav_fs.so, 10): Symbol not found: _dav_add_responsen Referenced from: /usr/libexec/apache2/mod_dav_fs.son Expected in: flat namespacen in /usr/libexec/apache2/mod_dav_fs.so
[/code]

Seems like it is caused by my disabling of mod_dav. mod_dav_fs acts as a support module for mod_dav and provides access to resources located in the server’s file system.

So I go to line 106 of /private/etc/apache2/httpd.conf and I comment out that line too.

[code lang=”bash”]sudo nano /private/etc/apache2/httpd.conf[/code]

Try to run the syntax check of Apache configuration again:

[sourcecode language=”bash”]
bash-3.2# sudo apachectl -t
Syntax OK
bash-3.2# [/sourcecode]

That seems to be working, now we start Apache:

[code lang=”bash”]sudo apachectl start[/code]

Useful apachectl commands include:

  • apachectl start
  • apachectl stop
  • apachectl restart
  • apachectl -t

Hope it helps!

How to redirect www to no-www in Lighttpd

This is pretty easy and is more of a personal note. First check that mod_redirect is enabled in lighttpd.conf:

[code lang=”bash”]sudo nano /etc/lighttpd/lighttpd.conf[/code]

Uncomment the line that write “mod_redirect”.

[code lang=”bash”]server.modules = (
“mod_rewrite”,
“mod_access”,
“mod_alias”,
“mod_accesslog”,
“mod_compress”,
“mod_redirect”,
…[/code]

Then add the following at the bottom of your lighttpd.conf:

[code lang=”bash”]$HTTP[“host”] =~ “^www.(.)” {
url.redirect = ( “^/(.
)” => “http://%1/$1″ )
}[/code]

Finally, give lighttpd a restart and test it out:

[code lang=”bash”]sudo /etc/init.d/lighttpd restart[/code]

Hope it helps.

After I made the switch to Lighty, I totally forgot to do redirect all my www sites to no-www, this results in all people who visit www.darylli.com to be shown the default site which is what you see here basically.

How to set up VirtualHost in Ubuntu

My environment is Ubuntu 8.1 Intrepid Ibex. I also written a guide on how to set up virtual hosts in Windows XP or Windows Vista.

0. Introduction

Sometimes, we have multiple projects and we would like to access the Project 1’s website by typing ‘http://project1/’ in the browser address bar. And Project 2 may be at ‘http://project2/’. Virtual hosts are what you need for your development work. This guide requires you to have basic knowledge of Apache. This guide assumes you haven’t done additional configuration to your Apache. You must have already got Apache2 installed.

Also remember that you should always do a backup of every configuration file you change.

1. Add a new host in Ubuntu

You should only be adding new hosts if you want to develop multiples sites in your local computer. Skip this section to go to Section 2 if you just want to add virtual hosts to a remote server.

Type in the following command into your terminal, you need to sudo here: Continue reading “How to set up VirtualHost in Ubuntu”

How to set up VirtualHost in XAMPP for Windows

My environment is Windows Vista but these instructions work for Windows XP as well. I also written a guide on how to set up virtual hosts in Ubuntu.

0. Introduction

Sometimes, we have multiple projects and we would like to access the Project 1’s website by typing ‘http://project1/’ in the browser address bar. And Project 2 may be at ‘http://project2/’. This is how we can configure Windows and Apache to do just that. While this guide is written for XAMPP’s Apache, if the instruction applies pretty much to Apache too. You can put your configuration into ‘httpd.conf’.

1. Add a new host in Windows

First go to your hosts file, it is located at C:WindowsSystem32driversetchosts for most people. If you’re using Windows Vista, you need to run command prompt as administrator. Type ‘cmd’ into the search bar and right click on the ‘cmd’ search result to point to ‘Run as administrator’. Continue reading “How to set up VirtualHost in XAMPP for Windows”