I want to be able to start an apache server from the command line, typing something like apache site-folder
or apache . --port=2000
This should read and use .htaccess
files.
I know about python -m SimpleHTTPServer
and it's close to what I need, but not quite.
Ideal solutions:
I just want to type command <Directory> --port=8000 --other-options
The command name could also be pache
At some point I may want to use this in production. It should be easy to send the process to the background, and then stop that instance or all instances, like forever
Relevant links: http://httpd.apache.org/docs/2.4/programs/httpd.html
It should be only one command for anyone to install the script for immediate use
What about apache debug mode (-X) ?
apache2 -X -d. -f.htaccess -C"PidFile `mktemp`" -C"Listen 1025"
-C"ErrorLog /dev/stdout" -C"DocumentRoot `pwd`"
to put it in the background once started you may use Ctrl^Z then type "bg"
Using the the FOREGROUND flag, wrapping it up in a shell script:
#!/bin/sh
if [ $# -ne 2 ]; then
echo "$0 <port> <dir>"
exit 10
fi
/usr/sbin/apache2 -DFOREGROUND -d. -f.htaccess -C"PidFile `mktemp`" \
-C"Listen $1" -C"ErrorLog /dev/stdout" -C"DocumentRoot $2" -e debug
call it "pache", chmod +x, then you can run
./pache 1026 /tmp/webroot