13 Replies Latest reply: Dec 9, 2011 8:11 AM by NicFromOz
Computable User Level 1 Level 1 (0 points)

I've installed a custom version of Apache2 that I want to run in complete replacement of the system provided one.

I tought it would suffice to stop the http service by the System Preferences but it didn't work.

What follow is a troubleshooting session I've done in an attempt to solve the problem.

I would point out that I'm not an Mac OS X power user.

 

I was attempting to reconfigure my webserver and I've noticed that, even if I killed it (by ps -aux | fgrep apache2 evidence) I had still an httpd process running effectively listening on port 80.

 

I've killed it and I've happily noticed that it wasn't respawn.

 

I've than ran Safari pointing to localhost and noticed it didn't failed to connect.

 

Reissued lsof -i | fgrep LISTEN I've found some httpd processes were binding the 80 port again.

 

At this point i know for sure:

  1. "my" apache2 processes aren't running
  2. system httpd have been started again

 

Check which was listening by telnet

/System/Library/LaunchDaemons$ telnet localhost 80

Trying ::1...

Connected to localhost.

Escape character is '^]'.

GET / HTTP/1.0

 

 

Connection closed by foreign host.

 

I've observed that I didn't get an HTTP-conform reply but a socket was effectively allocated.

 

I've checked the configuration of /System/Library/LaunchDaemon/org.apache.httpd.plist and found

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

         <key>Disabled</key>

         <true/>

         <key>Label</key>

         <string>org.apache.httpd</string>

         <key>ProgramArguments</key>

         <array>

                <string>/usr/sbin/httpd</string>

                <string>-D</string>

                <string>FOREGROUND</string>

        </array>

        <key>OnDemand</key>

        <false/>

        <key>SHAuthorizationRight</key>

        <string>system.preferences</string>

</dict>

</plist>

 

Any idea?


MacBook Pro, Mac OS X (10.7)
  • James Brickley Level 1 Level 1 (145 points)

    You didn't try stopping Apache2 with "apachectl"?  Also where did you install your copy of Apache2?  /usr/local/apache2, etc.?  Where did you obtain the Apache2 version?  Did you grab the source from the apache website and complie it or did you use some other method to install it?  Are you running it on port 80?

     

    What are you trying to accomplish by installing a custom copy of Apache2?  Are you looking to install extra modules etc?  Are you trying to setup a development environment? 

  • etresoft Level 7 Level 7 (26,220 points)

    Computable User wrote:

     

    I've installed a custom version of Apache2 that I want to run in complete replacement of the system provided one.

    ...

    I would point out that I'm not an Mac OS X power user.

    You are certainly conflicted, that's for sure.

     

    The "Disabled" key no longer has any meaning. The actual value is stored "elsewhere". Run the following command to permanently disable Apple's Apache:

    sudo launchctl unload -w /System/Library/LaunchDaemon/org.apache.httpd.plist

     

    Now, can I ask why you have installed a custom version of Apache? From the rest of your post, you sure look like a power user to me. It may just be that you are used to doing things the way some "other" operating systems work. If you tell me what your ultimate goal is, perhaps I can tell you a more elegant, Mac-friendly way to achieve it.

  • Computable User Level 1 Level 1 (0 points)

    As I stated above I've successfully stopped Apache2 process (which is my custom installation) and incidentally I used apachectl to carry out the job.

     

    I've obtained it trhough Mac ports.

     

    I think that the following command will suffice to answer your questions and give some more insight of my disaster

     

    /System/Library/LaunchDaemons$ ps ax | egrep '(.*httpd.*)|(.*apache.*)'

    14063   ??  Ss     0:00.18 /usr/sbin/httpd -D FOREGROUND

    14202   ??  S      0:00.00 /usr/sbin/httpd -D FOREGROUND

    14343   ??  Ss     0:00.01 /opt/local/bin/daemondo --label=apache2 --start-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart ; --pid=none

    14350   ??  Ss     0:00.14 /opt/local/apache2/bin/httpd -k start

    14355   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14356   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14357   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14358   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14359   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14375 s000  S+     0:00.00 egrep (.*httpd.*)|(.*apache.*)

     

    How can I deactivate the daemondo? Where I have to look?

  • James Brickley Level 1 Level 1 (145 points)

    /opt doesn't exist by default on Mac OS X.  Mac ports must have installed daemondo along with apache2.

     

    http://guide.macports.org/chunked/reference.startupitems.html sheds more light on it.  Mac Ports provides daemondo to assist with handling launchd configurations on Mac OS X for daemons that Mac Ports installs, such as your apache2 installation. 

     

    Your answers are to be found in the Mac Ports documentation.

  • Computable User Level 1 Level 1 (0 points)

    etresoft wrote:

     

    Computable User wrote:

     

    I've installed a custom version of Apache2 that I want to run in complete replacement of the system provided one.

    ...

    I would point out that I'm not an Mac OS X power user.

    You are certainly conflicted, that's for sure.

     

    The "Disabled" key no longer has any meaning. The actual value is stored "elsewhere". Run the following command to permanently disable Apple's Apache:

    sudo launchctl unload -w /System/Library/LaunchDaemon/org.apache.httpd.plist

     

    Now, can I ask why you have installed a custom version of Apache? From the rest of your post, you sure look like a power user to me. It may just be that you are used to doing things the way some "other" operating systems work. If you tell me what your ultimate goal is, perhaps I can tell you a more elegant, Mac-friendly way to achieve it.

     

    /System/Library/LaunchDaemons$ sudo launchctl unload -w /System/Library/LaunchDaemon/org.apache.httpd.plist

    Password:

    Sorry, try again.

    Password:

    launchctl: Couldn't stat("/System/Library/LaunchDaemon/org.apache.httpd.plist"): No such file or directory

    nothing found to unload

    /System/Library/LaunchDaemons$ !ps

    ps ax | egrep '(.*httpd.*)|(.*apache.*)'

    14063   ??  Ss     0:00.18 /usr/sbin/httpd -D FOREGROUND

    14202   ??  S      0:00.00 /usr/sbin/httpd -D FOREGROUND

    14343   ??  Ss     0:00.01 /opt/local/bin/daemondo --label=apache2 --start-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start ; --stop-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper stop ; --restart-cmd /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper restart ; --pid=none

    14350   ??  Ss     0:00.15 /opt/local/apache2/bin/httpd -k start

    14355   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14356   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14357   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14358   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14359   ??  S      0:00.00 /opt/local/apache2/bin/httpd -k start

    14395 s000  R+     0:00.00 egrep (.*httpd.*)|(.*apache.*)

     

    ds

     

    I was ready to bet you've found a solution.

     

    Q. Now, can I ask why you have installed a custom version of Apache?

    A. I came from Linux and I have to deploy my software on Linux systems. I was scared to found any kind of difference between the two systems so I've decided to build my httpd from scratch and so ensuring that I'd get the same result on both system.

    I've started experimenting Mac port just to test the replacement procedure of the daemon.

     

    I suppose my mates are right when say that I'm too drastic…

  • James Brickley Level 1 Level 1 (145 points)

    Try out http://virtualbox.com/ and simply setup a VM with your exact production Linux system on it.  VirtualBox is free and pretty easy to use.  It runs on Mac OS X with no trouble.  Or you can buy VMWare Fusion or Parallels.

     

    Although Mac OS X is very very Unix like, there are differences such as launchd which uses XML configuration files to define all the parameters for a daemon. 

     

    $ man launchd

    $ man launchctl

     

    http://launchd.macosforge.org/

    http://www.afp548.com/article.php?story=20050620071558293

    http://www.youtube.com/watch?v=cD_s6Fjdri8

  • Computable User Level 1 Level 1 (0 points)

    Yes, I'm aware of them… simply I didn't want to incur in such overhead.

     

    Anyway, the problem doesn't pertain Mac Ports'Apache instance. I was able to control it.

    I said "was" because, drastically, I've removed Mac Ports (I think it would be better to do things in Mac style on a Mac: learned lesson) and still have the problem: httpd binds on 80 but it doesn't speak HTTP…

     

    I would thank you for the excellent material you've suggested to me, especially for the lectio Googlis by the launchd's author … honeslty, the last place where I'd attemped to look.

     

    Thank you for your support, it's time to study and learn… possibly fix.

  • James Brickley Level 1 Level 1 (145 points)

    Apache2 on OSX is simply missing modules and configuration settings that Linux distros include by default.

     

    /etc/apache2 is where the configuration files are.

  • etresoft Level 7 Level 7 (26,220 points)

    Computable User wrote:

     

    /System/Library/LaunchDaemons$ sudo launchctl unload -w /System/Library/LaunchDaemon/org.apache.httpd.plist

    Password:

    Sorry, try again.

    Password:

    launchctl: Couldn't stat("/System/Library/LaunchDaemon/org.apache.httpd.plist"): No such file or directory

    nothing found to unload

    Sorry about that. I just copied what you had above. That should have been:

    sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

     

    MacOS X is case-insensitive, but not plural-insensitive.

     

    Q. Now, can I ask why you have installed a custom version of Apache?

    A. I came from Linux and I have to deploy my software on Linux systems. I was scared to found any kind of difference between the two systems so I've decided to build my httpd from scratch and so ensuring that I'd get the same result on both system.

    I've started experimenting Mac port just to test the replacement procedure of the daemon.

     

    I don't think that should be an issue. The thing about Linux is that no two versions (or machines) are identical. The Mac Apache is definitely going to be different than the Apache on any given Linux machine, but then so will the Apache on some other Linux machine.

     

    You will have an easier time learning the Mac-specific items if you stick to the Apple builds and work with them until you get stuck. If some module isn't available on the Mac, it might not be available on your deployment platform either. On Linux, the reverse is more likely, you will build something base on your development environment and then have big problems when some library isn't available on the deployment environment and, for whatever reason, you can't install it there. I find it far easier to develop on a Mac and then deploy to Linux.

     

    I suggest avoiding the "ports" tools until you find your way around a bit. Some people swear by them, but I like to have full control of everything I install. I also don't like the ports tools installing things that I already have. I prefer to "embrace the Mac-ness"

  • Computable User Level 1 Level 1 (0 points)

    Finally I get rid of it: launchd is a very "topicized" and "clean" piece of code…

     

    I've forced the removal of the job

    ~# launchctl remove org.apache.httpd

     

    and load it again

    ~# launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist

     

    and unload it again

    ~# launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

     

    It defenitively seems that something is going wrong with local configuration… provided  that it still refuses to speak HTTPese…

     

    … but this is an other story and here in Italy it's almost 5am…

     

    Mac Ports and Co will be forbidden here… some more CPU time spent to make bins… legacy tough style

  • James Brickley Level 1 Level 1 (145 points)

    Not sure what happened but this is what I get using two carriage returns after the "GET / HTTP/1.0".

     

    MacPro:~ test$ telnet localhost 80

    Trying 127.0.0.1...

    Connected to localhost.

    Escape character is '^]'.

    GET / HTTP/1.0

     

     

    HTTP/1.1 200 OK

    Date: Fri, 05 Aug 2011 10:01:52 GMT

    Server: Apache/2.2.19 (Unix) DAV/2

    Content-Location: index.html.en

    Vary: negotiate

    TCN: choice

    Last-Modified: Thu, 21 Jul 2011 10:39:10 GMT

    ETag: "522e95-2c-4a891f5898f80"

    Accept-Ranges: bytes

    Content-Length: 44

    Connection: close

    Content-Type: text/html

    Content-Language: en

     

     

    <html><body><h1>It works!</h1></body></html>Connection closed by foreign host.

    MacPro:~ test$

  • Computable User Level 1 Level 1 (0 points)

    You get what is expected from an HTTP server: an HTTP reply

  • NicFromOz Level 1 Level 1 (0 points)

    There's a typo here. It should be:

    sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist