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:
- Contributing a great command line interface to apache itself
- Writing a simple command line tool that wraps/contains apache (or something)
- Linking to docs on an existing cli for apache
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
Also
It should be only one command for anyone to install the script for immediate use
http-server
is a much better simple http server than pache, it's what I use currently! :)This works:
Your apache config could point to /var/www
Then use:
to unbind use:
If you want several ports you could preconfigure ports in apache to point to directories like /var/www/8000.
Hope you find your solution. I hate .htaccess. So I wrote this:
What about apache debug mode (-X) ?
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:
call it "pache", chmod +x, then you can run
For the benefit of anyone stumbling across this with the same question, I wanted something that was as simple as the pache package mentioned, but not relying on having node.js installed.
My use-case was in looking for a replacement for the webrick server used in Jekyll. Webrick, like most lightweight run-anywhere http servers, doesn't support .htaccess files.
So I took gpilotino's answer and packaged it up a bit. I've been using it for a few weeks now and although I am sure it can be improved upon it's doing the job. It comes as a script and a minimal httpd.conf file, which makes it easy to extend to support, say, PHP.
You can find it at: https://github.com/julianbrowne/apache-anywhere
Essentially, once it's installed (an optionally config tweaked) you just run:
apache -d document_root_directory -p {port}
and:
apache stop {port}
when you are done.
Hmm... interesting.
I can see why you want to be able to spawn a separate apache instance, on demand, on a different port, etc. etc.
Ie, sometimes, you want to just change the config for one instance, or you would like users to be able to self serve, etc.
But more importantly, you want to be able to give your users Apache flexibility without it breaking Apache for everyone else. That's something that a massive virtualhost config file can't deal with.
I have something similar setup in my own environments.
In either case, to fire up Apache on a Mac with custom settings, this is what I did:
Folders/files:
~/site/conf/httpd.conf ~/site/logs/ ~/site/public/
Contents of the httpd.conf file:
This makes use of the system wide installation of Apache.
To fire up the instance:
Configuration for modules, ports listened to, php, pid and lock file locations, etc. could be moved to an outside include, which would be controlled by the administrator and not the user. You can then provide the user with a baseline template httpd.conf file, a simple start/stop/reload/etc. wrapper, and give all of your users the ability to fire up their own website.
Given that it's a Mac OS environment, the less you need to install, the more straightforward management will be.