Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start an apache server in any directory from command line

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:

  1. Contributing a great command line interface to apache itself
  2. Writing a simple command line tool that wraps/contains apache (or something)
  3. 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

like image 984
Devin Rhode Avatar asked Dec 04 '12 02:12

Devin Rhode


People also ask

How do I force start httpd?

How do I restart httpd service? You can use the service or systemctl command to restart httpd server. Another option is use /etc/init. d/httpd service script.

Which command is used to run Apache module?

In Linux, the apachectl or apache2ctl command is used to control Apache HTTP server interface, it is a front-end to Apache.

How do I start Apache server on Windows server?

Step by step Apache install on Windows Download the installation media in the form of a ZIP file. Extract the contents of the Apache Web Server 2.4 zip to the file system. Locate the extracted Apache24 folder and copy this folder to the root of C:\ Open the C:\Apache24\bin folder and run the httpd.exe command.


2 Answers

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 
like image 153
gpilotino Avatar answered Sep 19 '22 07:09

gpilotino


http-server is a much better simple http server than pache, it's what I use currently! :)

Use [pache][1]

Install with npm - which comes with node here: http://nodejs.org/

sudo npm install pache -g 

Run on current dir, port 3000:

pache 

Or specify directory and port:

pache site-directory 2000 

[1]: https://github.com/devinrhode2/pache

like image 45
Devin Rhode Avatar answered Sep 22 '22 07:09

Devin Rhode