Start an apache server in any directory from command line

后端 未结 7 1311
故里飘歌
故里飘歌 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条回答
  • 2020-12-25 13:10

    Hope you find your solution. I hate .htaccess. So I wrote this:

    #!/bin/bash
    cat >._apache2_dir_conf << EOF
    Include /etc/apache2/mods-enabled/*.load
    Include /etc/apache2/mods-enabled/*.conf
    ErrorLog $1/._apache2_dir_error.log
    HostnameLookups Off
    NameVirtualHost *:$2
    ServerName joyeruc
    Listen $2
    PidFile $1/._apache2_pid
    <VirtualHost *:$2>
        ServerAdmin joyer@uc
        DocumentRoot $1
        <Directory />
            Options FollowSymLinks
            AllowOverride None
        </Directory>
        <Directory $1/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
        </Directory>
        ErrorLog $1/._apache2_dir_error.log
        LogLevel warn
    </VirtualHost>
    
    EOF
    
    #apache2 -k $3 -X -f $1/._apache2_dir_conf
    apache2 -X -f $1/._apache2_dir_conf
    
    0 讨论(0)
  • 2020-12-25 13:14

    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.

    0 讨论(0)
  • 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 <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
    
    0 讨论(0)
  • 2020-12-25 13:21

    Why not use Gatling which allows you to do exactly what you want?

    http://www.fefe.de/gatling/

    0 讨论(0)
  • 2020-12-25 13:25

    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

    0 讨论(0)
  • 2020-12-25 13:25

    This works:

    Your apache config could point to /var/www

    Then use:

    sudo mount -o bind /home/webcreatorperson/mywebsite /var/www
    

    to unbind use:

    sudo umount /var/www
    

    If you want several ports you could preconfigure ports in apache to point to directories like /var/www/8000.

    0 讨论(0)
提交回复
热议问题