Home > database >  script not working (change dir, run local webserver, open browser)
script not working (change dir, run local webserver, open browser)

Time:10-25

I cannot get this bash script to work to run a dokuwiki website on my local machine:

#!/bin/bash

cd ~/Sites/dokuwiki;
php -S localhost:8000 index.php;
open "http://localhost:8000/doku.php?id=start";

The script is executable.

If I run each line individually in the terminal it works perfectly. I'm just trying to avoid all of that typing. I'd like to run the script to execute those commands all at once.

When I drop the executable file on an open terminal window (or double click on the file), the first two lines execute, but the script stops executing (the local web server is running in that terminal window awaiting commands). I can then manually open a browser and navigate to my local website. But I am trying to get the script to do that.

I tried opening a second terminal window in the script by using ttab -w open [bla bla bla ...] but no second window was opened and the open command (to open the browser) was not executed. (I installed ttab via npm.)

I am using MacOS (12.6, Monterey) and an M1 chip, though I don't think that really matters. This should be a pretty "universal" kind of script.

This should be simple but I can't seem to figure it out.

CodePudding user response:

It looks like your command is hanged at php -S localhost:8000 index.php; as it starts the server and wait for user keyboard input.

To run it in background change it to:

nohup php -S localhost:8000 index.php &;
  • Related