[筆記]利用Webhook實現coding上的程式碼自動部署到Centos7伺服器上
阿新 • • 發佈:2019-01-25
centos7上的nginx伺服器配置
遠端控制伺服器
ssh root@192.16.1.148
//@ 左邊的 root 是連線時使用的使用者的名字,@ 右邊的數字是你的伺服器的 IP 地址
新增新使用者並設定密碼
adduser www
passwd www
分配root許可權
gpasswd -a www wheel
vi /etc/sudoers
//找到root ALL=(ALL) ALL 並在下面新增一行如下
www ALL=(ALL) ALL
用新使用者WWW登入伺服器
ssh www@192.16.1 .148
新增軟體倉庫
EPEL
sudo yum install epel-release -y
//為了使用 CentOS 系統的包管理工具去安裝更多的東西,需要安裝一些軟體倉庫
IUS
sudo yum install https://centos7.iuscommunity.org/ius-release.rpm -y
安裝Nginx
sudo yum install nginx -y
//啟動
sudo systemctl start nginx
//開機自啟動
sudo systemctl enable nginx
服務啟動以後,你就可以在瀏覽器上使用伺服器的 IP 地址,可以看到預設頁。
配置支援php的虛擬主機
vi /etc/nginx/nginx.conf
修改配置檔案server部分如下
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
重啟 nginx 或者重新載入 nginx 讓配置檔案生效
sudo systemctl reload nginx
配置php環境
下載php7
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
解壓
tar -xvf php7.tar.gz
進入目錄
cd php-7.1.1
安裝依賴
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
編譯配置
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
正式安裝
make && make install
配置環境變數
vi /etc/profile
//在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
執行命令使得改動生效
source /etc/profile
配置php-fpm
sudo yum install php70u-fpm -y
//啟動
sudo systemctl start php-fpm
//開機自啟動
sudo systemctl enable php-fpm
安裝常用PHP擴充套件
sudo yum install php70u-gd php70u-mysqlnd php70u-pdo php70u-mcrypt php70u-mbstring php70u-json php70u-opcache php70u-xml -y
重新載入
sudo systemctl reload php-fpm
目錄與檔案許可權
//檢視目錄與檔案許可權
sudo ps aux|grep php
//將nginx預設目錄檔案擁有者設為www
chown -R www:www /usr/share/nginx/html
//給檔案授予所有使用者可讀寫執行許可權
chmod 777 index.php
檢視端口占用
lsof -i tcp:80
列出埠
netstat -ntlp
netstat -ntlp | grep nginx
結束程序
pkill -9 nginx
檢視是否啟動
ps -ef | grep nginx
在coding上設定webhook
vim呼叫python格式化json資料
cat json.txt | python -m json.tool