-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_server.sh
41 lines (29 loc) · 870 Bytes
/
run_server.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
PROJECT_DIR="D:/AllFiles/wamp64/www/"
PORT=8000
echo "Starting PHP server on port $PORT..."
php -S 127.0.0.1:$PORT -t "$PROJECT_DIR" > php_server.log 2>&1 &
PHP_PID=$!
sleep 2
if ! ps -p $PHP_PID > /dev/null; then
echo "Failed to start PHP server."
exit 1
fi
echo "PHP server started successfully with PID $PHP_PID."
echo "Starting ngrok for PHP server on port $PORT..."
ngrok http $PORT > ngrok.log 2>&1 &
NGROK_PID=$!
sleep 5
NGROK_URL=$(grep -o 'https://[0-9a-z]*\.ngrok\.io' ngrok.log | head -n 1)
if [ -z "$NGROK_URL" ]; then
echo "Failed to retrieve ngrok URL."
kill $PHP_PID
kill $NGROK_PID
exit 1
fi
echo "ngrok URL: $NGROK_URL"
echo "$NGROK_URL" > public_url.txt
echo "Public URL saved to public_url.txt"
echo "Press Ctrl+C to stop the server and ngrok."
tail -f php_server.log ngrok.log
trap "kill $PHP_PID $NGROK_PID" EXIT