網站專案範例
「完整範例」。
資料夾結構
./
├── bin
│ ├── deploy.sh
│ ├── git-add.sh
│ ├── git-commit.sh
│ ├── git-config.sh
│ ├── git-log.sh
│ ├── git-pull.sh
│ ├── git-push.sh
│ ├── git-status.sh
│ ├── help.sh
│ ├── php-install.sh
│ └── web-server.sh
├── Makefile
├── README.md
└── web
└── index.html
2 directories, 14 files
Makefile
撰寫「Makefile」內容如下
THE_MAKEFILE_FILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
THE_BASE_DIR_PATH := $(abspath $(dir $(THE_MAKEFILE_FILE_PATH)))
THE_BIN_DIR_PATH := $(THE_BASE_DIR_PATH)/bin
PATH := $(THE_BIN_DIR_PATH):$(PATH)
default: help
.PHONY: default
help:
@help.sh
.PHONY: help
php-install:
@php-install.sh
.PHONY: php-install
web-server:
@web-server.sh
.PHONY: web-server
deploy:
@deploy.sh
.PHONY: deploy
git-add:
@git-add.sh
.PHONY: git-add
git-commit:
@git-commit.sh
.PHONY: git-commit
git-log:
@git-log.sh
.PHONY: git-log
git-pull:
@git-pull.sh
.PHONY: git-pull
git-push:
@git-push.sh
.PHONY: git-push
git-status:
@git-status.sh
.PHONY: git-status
Shell Script
撰寫「bin/web-server.sh」內容如下
#!/usr/bin/env bash
THE_BASE_DIR_PATH=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
THE_WEB_DIR_PATH=$THE_BASE_DIR_PATH/../web
#THE_SERVER_HOST=localhost
#THE_SERVER_HOST=127.0.0.1
THE_SERVER_HOST=0.0.0.0
THE_SERVER_PORT=8080
THE_SERVER_BIND=$THE_SERVER_HOST':'$THE_SERVER_PORT
## PHP Built-in web server
## http://php.net/manual/en/features.commandline.webserver.php
cd $THE_WEB_DIR_PATH
## php -S 0.0.0.0:8080
php -S $THE_SERVER_BIND
# php -S $THE_SERVER_BIND -t $THE_WEB_DIR_PATH
## Python
## Python 3
## https://docs.python.org/3/library/http.server.html
## python -m http.server 8080
## python -m http.server 8080 --bind 127.0.0.1
# python -m http.server $THE_SERVER_PORT
# python -m http.server $THE_SERVER_PORT --bind $THE_SERVER_HOST
## Python 2
## https://docs.python.org/2/library/simplehttpserver.html
## python -m SimpleHTTPServer 8080
# python -m SimpleHTTPServer $THE_SERVER_PORT
利用「PHP / Built-in web server」來啟動「Web Server」。
在「Xubuntu 14.04」環境下若要執行「php」,只要執行「
sudo apt-get install php5-cli
」,安裝「php5-cli」這個套件就行了。 在「Xubuntu 16.04」環境下則是安裝「php-cli」這個套件,所以要執行「sudo apt-get install php-cli
」。
執行
$ php -S 0.0.0.0:8080
也可以使用Pthon的版本,來啟動「Web Server」。
- Python3 是「http.server」。
- Python2 是「SimpleHTTPServer」。
執行
$ python3 -m http.server 8080 --bind 0.0.0.0
或是
$ python -m SimpleHTTPServer 8080
執行指令
執行
$ make
顯示
Usage: make [command]
Ex:
$ make
$ make help
$ make php-install
$ make web-server
$ make deploy
$ make git-add
$ make git-commit
$ make git-log
$ make git-pull
$ make git-push
$ make git-status
執行
$ make web-server
顯示
PHP 7.0.8-0ubuntu0.16.04.3 Development Server started at Sat Dec 10 15:42:06 2016
Listening on http://0.0.0.0:8080
Document root is /home/user/Project/web-project/web
Press Ctrl-C to quit.
觀看網頁
執行
$ lynx http://0.0.0.0:8080
或是執行
$ firefox http://0.0.0.0:8080