Running a web server on your local machine can be incredibly useful for development, testing, or even hosting personal projects. Apache is a popular web server software that runs on macOS. While macOS comes with a version of Apache pre-installed, it doesn't automatically start upon booting the system.
For developers or administrators who frequently use Apache on their macOS systems, it can be convenient to have Apache start automatically every time the system boots up. This ensures that the web server is always available without manual intervention.
macOS uses the launchd system process as its init system, which initializes other processes. macOS already has a launchd service definition for Apache. To make Apache start automatically, you'll need to load it using launchctl.
$ sudo apachectl -k start
ps -aef | grep httpd 0 161 1 0 Sun04AM ?? 0:04.05 /usr/sbin/httpd -D FOREGROUND 501 800 161 0 Sun04AM ?? 0:02.54 /usr/sbin/httpd -D FOREGROUND 501 1007 161 0 Sun04AM ?? 0:02.62 /usr/sbin/httpd -D FOREGROUND 501 1381 161 0 Sun07AM ?? 0:01.71 /usr/sbin/httpd -D FOREGROUND 501 4472 161 0 Tue07AM ?? 0:01.74 /usr/sbin/httpd -D FOREGROUND 501 4473 161 0 Tue07AM ?? 0:01.17 /usr/sbin/httpd -D FOREGROUND 501 4474 161 0 Tue07AM ?? 0:01.06 /usr/sbin/httpd -D FOREGROUND
$ sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist Password:
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
Comment anonymously. Login not required.