skip to Main Content

Let’s say I have a local apache2 and I need a script that runs the apache2 with a special injected VirtualHost.

More presice:
I have a xampp Installation (PHP 7.3.10, MariaDB 10.4.8, mysqlnd 5.0.12-dev, Apache 2.4.41) on Windows 10.
Several PHP projects are located all over the hard drive. Until now I modify the ./apache/conf/extra/httpd-vhosts.conf file before starting the apache2 service on every project switch. With that I can leave the project folders where there are without copying them in the xampp installation folder.

Now I am curious if I can write a script for each project (bat or sh, GitShell is installed) that will run mariadb normally and apache2 with a temporarily VirtualHost for that specific project folder as DocumentRoot.

What I currently can do:
Lay down a httpd-vhosts.conf file and a startProject.sh script in a project folder. Running the script will copy the configuration file in the xampp installation and then start the apache2 service.
That is working, but only one apache2 process can start and not multiple projects at once.

What I want:
I want to use a parameter that specifies a VirtualHost by parameter when starting apache2.
Maybe by saying apache2 to use a special config file rather then the file in the own project structure.
Or I want to use a parameter by starting the apache2 process that specifies a alternatie DocumentRoot Folder for a already specified VirtualHost.

Currently this is my approach:

#!binbash
BASEDIR=$(dirname "$0")
xamppPath="C:xamppv7.3.10"
cd $xamppPath
"apachebinhttpd.exe" -S "$BASEDIRhttpd-vhosts.conf" &

But -S only prints out the VirtualHosts, not setting the configuration file.

How can I achieve running a project with a script somewhere on my harddrive without overriding the existing configuration file in the xampp installation folder?

2

Answers


  1. Chosen as BEST ANSWER

    In the xampp package there is no direct apachectl file, so a use of -D <name> is not possible for me. It would be the perfect solution, but unfortunately not possible.

    Now I have to override the httpd-vhosts.conf file from every project I want to start it. Therefore, I am using a modified script solution:

    #!binbash
    BASEDIR=$(dirname "$0")
    xamppPath="C:xamppv7.3.10"
    cp -f "$BASEDIRhttpd-vhosts.conf" "$xamppPathapacheconfextrahttpd-vhosts.conf"
    sleep 1
    cd $xamppPath
    "apachebinhttpd.exe" &
    

    It is not the perfect solution, but it works.
    Two apache services at the same time with two different projects is not possible, but until now not necessary.


  2. Easier: build a couple of congratulation files, use option -f to specify an effective configuration file, not -S.

    Can be more complicated: user -D name and use <IfDefine name> in the configuration file to “select” sections of it to apply to a particular start.

    Note: I use apachectl, not directly httpd to start/stop Apache.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search