Start an apache server in any directory from command line

后端 未结 7 1314
故里飘歌
故里飘歌 2020-12-25 12:26

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 sh

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 13:15

    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  "
        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
    

提交回复
热议问题