The first confusion was when I tried starting httpd with classical “init.d” approach – look, mom, OS X don’t have init.d..
Instead of Linux tricks, OS X is using (RTFM!) a native apache utility
apachectl
To start HTTP server:
sudo apachectl start
and as expected , to stop
sudo apachectl stop
Another useful command test all configuration files and report on error
apachectl configtest
and test virtual host configuration with
apachectl -S
Alternative is to use launch daemon – actual Mac replacement for init.d
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Some additional info on launchd and launchctl. TBD
To setup HTTPD running automatically on Mac boot ( it is not by default)
sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist
not flag “-w” which made this load permanent (e.t. autostart on reboot). To disable autostart , unload httpd daemon with
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
LoadModule php5_module libexec/apache2/libphp5.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
Include /private/etc/apache2/extra/httpd-userdir.conf
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
Particularly, when moving from Apache 2.2 replace “allow all” construct
Order allow,deny
Allow from all
Require all granted
for example, to allow http://localhost/foo add /etc/apache2/other/foo.cfg file
Alias /foo /Users/stas/Sandbox/foo
<Directory “/Users/stas/Sandbox/foo”>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride all
Require all granted
AddType application/x-httpd-php .php
</Directory>
usually it is a best way to debug your web application locally – instead of www.foo.com, create local domain “foo.local”, build virtual host and debug as you would with a real application.
Step 0 : in configuration file /etc/apache2/httpd.conf uncomment lines
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so
Step 1 : create a new DNS entry
add new entry into the /etc/hosts file – see last line (first 3 lines are standard)
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 foo.local
Step 2: create virtual host definition
<VirtualHost *:80>
ServerAdmin webmaster@foo.local
DocumentRoot “/Users/stas/Sandbox/foo”
ServerName foo.local
ServerAlias www.foo.local
ErrorLog “/private/var/log/apache2/foo.local-error_log”
CustomLog “/private/var/log/apache2/foo.local-access_log” common
</VirtualHost>
see also http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-10-yosemite/
Setting up virtual hosts has one drawback -you will lose http://localhost ;-(
to restore it back, add one more virtual host definition:
<VirtualHost *:80> ServerName localhost DocumentRoot /Library/WebServer/Documents/</VirtualHost>
Log files located by default at /var/log/apache2/
I started developing software in mid-80s, initially as a hobby, but eventually hobby somehow self-converted into my full-time profession. I started from Assembler 360 (on Soviet clone of IBM 360/370), then moved to Assemblers of IBM PC, following by kernel development for Windows and Linux, embedded systems, VoIP, video streaming, network analysis and many more cool applications/devices/systems…. Bottom line, have quite a baggage to brag about…
Until I got my first Mac – quite late, when it harder to teach old dog new tricks… Actually I was resisting for a while idea to move to Mac – close software, close hardware, no alternative but buy from a single vendor and soon.. But a resistance to Apple is futile – once you forced to work with Mac ( it was AirBook) for a week, you just can’t go back and start wonder how people can ever use anything else but Mac OS ;-).. The only problem is that “old tricks” ( Linux/Windows configurations experience) are often confuse my memory when I need to do something on the OS X, and somehow I think that some old dogs may face quite similar problems… So maybe making my embarrassment public, I can help a few lost souls as well…
Enough with an introduction… This will be a sub-blog about problems i faced while working with OS X, using it as development platform of various application – Java, PHP, C++
Environment (to be updated):
– MacBook Pro with Retina Display ( upgrade from original AirBook)
– OS X Yosemite (10.10) (upgrade from original 10.7)
– some software installed with MacPort
– some software installed with Fink
– development environment – Eclipse (Luna – 4.4.1)
– Java – JDK 8u25
Expected topics:
– Who installed this shit – finding your way in OS X package managers.
– Configuration for local PHP development & testing
– Configuration for local web app development with Java
– Configuration for Android development ( including NDK debugging).