Skip to content

Instantly share code, notes, and snippets.

@LewisGet
Last active January 4, 2016 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save LewisGet/8648275 to your computer and use it in GitHub Desktop.
Save LewisGet/8648275 to your computer and use it in GitHub Desktop.
# PHP #
###下載 原始碼
$ wget http://tw2.php.net/distributions/php-5.3.8.tar.gz
$ wget http://xmlsoft.org/sources/libxml2-2.7.7.tar.gz
$ wget http://zlib.net/zlib-1.2.5.tar.gz
###解壓縮
$ tar -zxvf php-5.3.8.tar.gz
$ tar -zxvf libxml2-2.7.7.tar.gz
$ tar -zxvf zlib-1.2.5.tar.gz
###進入解壓後的資料夾 編譯
順序請依照
1. libxml
2. zlib
$ ./configure
$ make
$ make install
###安裝 icu
$ yum -y install icu
$ yum -y install libicu-devel
#php 編譯 pear 時所需
##icu 是用於 java 與 c/cpp 的 lib (i18n)
功能是 text 轉換 Unicode
###編譯 php ( NO cgi 與 cgi 只能擇一 )
$ ./configure \
--enable-fastcgi \
--enable-fpm \
--enable-shared \
--with-zlib \
--with-pear \
--with-mysql \
--enable-mbstring=shared \
--enable-intl=shared \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
-with-config-path=/etc/php.ini
$ make
$ make install
#參數介紹
--enable-fastcgi fastCGI
--enable-fpm FPM
--enable-shared lib 共用模式
--with-zlib zlib 共同編譯 (pdo_mysql 需要)
--with-pear 安裝 pear
--enable-mbstring=shared 開啟 mbstring
--enable-intl=shared 開啟 intl
--with-mysql 需編入 mysql
--with-mysql=mysqlnd 設定 mysql 的 bin 位置
--with-pdo-mysql=mysqlnd 設定 pro mysql 所控制的 bin 位置 (現在使用 $PATH 自動取得)
-with-config-path=/etc/php.ini php 設定檔存放位置
#注意項目
1. php-fpm 預設設定檔位於 /usr/local/etc/ 內
2. 預設設定檔不會有 .conf 只會有 .conf.default 請複製一份命名為 .conf
3. 請確保 /var/lib/php/session 有此目錄 ( 或者您所指定的目錄 )
且權限為可寫入
4. php-fpm 開啟時請讀取 /etc/php.ini
$ php-fpm -c /etc/php.ini
# APC #
$ pecl install apc
# php.ini
在 php.ini 內未有讀取 apc.so 請在 php.ini 加上 extension = apc.so
讀取 mbstring 請加上 extension = mbstring.so
讀取 intl 請加上 extension = intl.so
# NGINX #
### 安裝 pcre
$ yum -y install pcre
$ yum -y install pcre-devel
### 安裝 openssl
$ yum -y install openssl
$ yum -y install openssl-devel
### 下載原始碼
$ wget http://nginx.org/download/nginx-1.1.1.tar.gz
### 解壓縮
$ tar -zxvf nginx-1.1.1.tar.gz
### 進入後編譯
$ ./configure \
--sbin-path=/usr/local/sbin \
--with-http_ssl_module \
--with-http_stub_status_module
$ make
$ make install
#參數介紹
--sbin-path=/usr/local/sbin sbin 放置位置
--with-http_ssl_module https 編入
--with-http_stub_status_module https 安全模組
# PHP fpm 設定
## 注解移除並加上使用者
;listen.owner = nobody
;listen.group = nobody
;listen.mode = 0666
user = nobody
group = nobody
;pm.start_servers = 20
;pm.min_spare_servers = 5
;pm.max_spare_servers = 35
;pm.max_requests = 500
# NGINX 上 Symfony 設定
# 請在 nginx.conf 內的 http 區塊內加入
location / {
index app.php;
if (-f $request_filename) {
break;
}
rewrite ^(.*)$ /app.php last;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(.+)$;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
fastcgi_param HTTPS off;
fastcgi_pass 127.0.0.1:9000;
}
# 備註
1. php 跟 nginx 的 user, group 記得從 nobody 更改為目標使用者
2. 如 NGINX 使用編譯來安裝 預設 大部分 conf 都需自己複製 conf.default 來建立
3. 如果端口不在 9000 請更改端口
4. php-fpm 預設設定檔位於 /usr/local/etc/ 內
5. 預設設定檔不會有 .conf 只會有 .conf.default 請複製一份命名為 .conf
6. 請確保 /var/lib/php/session 有此目錄 ( 或者您所指定的目錄 )
且權限為可寫入
7. php-fpm 開啟時請讀取 /etc/php.ini
$ php-fpm -c /etc/php.ini
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment