Cenos7 編譯安裝 Mariadb Nginx PHP Memcache ZendOpcache (實測 筆記 Centos 7.0 + Mariadb 10.0.15 + Nginx 1.6.2

環境:php

系統硬件:vmware vsphere (CPU:2*4核,內存2G,雙網卡)html

系統版本:CentOS-7.0-1406-x86_64-DVD.isomysql


安裝步驟:linux

1.準備nginx

1.1 顯示系統版本
[root@centos ~]# cat /etc/redhat-release
CentOS Linux release 7.0.1406 (Core)c++


[root@centos ~]# uname -a
Linux tCentos7 3.10.0-123.13.2.el7.x86_64 #1 SMP Thu Dec 18 14:09:13 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux算法


1.2 安裝基本軟件包sql

[root@centos ~]# yum install vim wget lsof gcc gcc-c++ bzip2 -y數據庫

[root@centos ~]# yum install net-tools bind-utils -ybootstrap


1.3 顯示IP地址 (centos7須要先安裝 net-tools bind-utils包)

[root@centos ~]# ifconfig|grep inet

inet 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.255


1.4 關閉selinux (不關有時會添加不了用戶,或者重啓後無法開機)

[root@centos ~]# vim /etc/selinux/config

屏蔽如下兩行

#SELINUX=enforcing

#SELINUXTYPE=targeted

添加如下一行

SELINUXTYPE=disabled

保存,退出


重啓後,查詢是否關閉(顯示Disabled則表示關閉)

[root@centos ~]# shutdown -r now

[root@centos ~]# getenforce

Disabled


2.安裝mariadb


2.1 安裝依賴
[root@centos ~]# yum install ncurses-devel openssl* bzip2 m4 -y


2.2 安裝cmake

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf cmake-3.0.0.tar.gz

[root@centos ~]# cd cmake-3.0.0

[root@centos ~]# ./bootstrap

[root@centos ~]# make && make install


2.3 安裝bison(須要 m4 庫)

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf bison-3.0.tar.gz

[root@centos ~]# cd bison-3.0

[root@centos ~]# ./configure

[root@centos ~]# make && make install


2.4 安裝jemalloc(須要 bzip2 庫解壓)

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar xjf jemalloc-3.6.0.tar.bz2

[root@centos ~]# cd jemalloc-3.6.0

[root@centos ~]# ./configure

[root@centos ~]# make && make install

[root@centos ~]# echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf

[root@centos ~]# ldconfig


2.5 建立mysql須要的目錄、配置用戶和用戶組

[root@centos ~]# groupadd mysql

[root@centos ~]# useradd -g mysql mysql -s /sbin/nologin

[root@centos ~]# mkdir -p /data/mysql

[root@centos ~]# chown -R mysql:mysql /data/mysql


2.6 編譯mariadb(須要 cmake ncurses-devel bison 庫)

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf mariadb-10.0.15.tar.gz

[root@centos ~]# cd mariadb-10.0.15

[root@centos ~]# cmake -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/data/mysql -DMYSQL_TCP_PORT=3306 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_EXTRA_CHARSETS=all -DEXTRA_CHARSETS=all -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all

# 編譯說明
# -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb # 安裝根目錄
# -DMYSQL_DATADIR=/usr/local/mariadb/data/ # 數據存儲目錄
# -DMYSQL_UNIX_ADDR=/usr/local/mariadb/tmp/mysqld.sock # UNIX socket文件
# -DDEFAULT_CHARSET=utf8 # 默認字符集
# -DDEFAULT_COLLATION=utf8_general_ci # 默認字符校對
# -DMYSQL_TCP_PORT=3306 # TCP/IP端口
# -DWITH_READLINE=1 # readline庫
# -DENABLED_LOCAL_INFILE=1 # 啓用加載本地數據
# -DWITH_EXTRA_CHARSETS=all # 擴展支持編碼 ( all | utf8,gbk,gb2312 | none )
# -DEXTRA_CHARSETS=all # 擴展字符支持
# -DWITH_MYISAM_STORAGE_ENGINE=1 # Myisam 引擎支持
# -DWITH_INNOBASE_STORAGE_ENGINE=1 # innoDB 引擎支持
# -DWITH_XTRADB_STORAGE_ENGINE=1 # XTRADB 支持
# -DWITH_ARIA_STORAGE_ENGINE=1 # ARIA 引擎支持
# -DWITH_ARCHIVE_STORAGE_ENGINE=1 # ARCHIVE 引擎支持
# -DWITH_BLACKHOLE_STORAGE_ENGINE=1 # BLACKHOLE 引擎支持
# -DWITH_FEDERATEDX_STORAGE_ENGINE=1 # FEDERATEDX 引擎支持
# -DWITH_PARTITION_STORAGE_ENGINE=1 # PARTITION 引擎支持
# -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 # PERFSCHEMA 引擎支持
# -DWITH_SPHINX_STORAGE_ENGINE=1 # SPHINX 引擎支持
# -DCMAKE_EXE_LINKER_FLAGS="-ljemalloc" -DWITH_SAFEMALLOC=OFF #Jemalloc內存管理庫


[root@centos ~]# make

[root@centos ~]# make install


2.7 建立軟鏈接

[root@centos ~]# ln -s /opt/mysql/lib/lib* /usr/lib/

[root@centos ~]# ln -s /opt/mysql/bin/mysql /bin


2.8 修改配置文件

[root@centos ~]# cd /opt/mysql

[root@centos ~]# cp ./support-files/my-large.cnf /etc/my.cnf

[root@centos ~]# vim /etc/my.cnf

在[client]下添加一行
default-character-set = utf8

在[mysqld]下添加一行
datadir = /data/mysql
character-set-server = utf8

保存退出


2.9 修改服務啓動檢測文件

[root@centos ~]# cp /usr/local/src/mariadb-10.0.15/packaging/rpm-oel/mysql-systemd-start /opt/mysql/bin/

[root@centos ~]# chmod 755 /opt/mysql/bin/mysql-systemd-start

[root@centos ~]# vim ./bin/mysql-systemd-start

找到如下內容
datadir=$(/usr/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n 's/--datadir=//p')
修改成
datadir=$(/opt/mysql/bin/my_print_defaults server mysqld | grep '^--datadir=' | sed -n 's/--datadir=//p')


找到如下內容
/usr/bin/mysql_install_db --rpm --datadir="$datadir" --user=mysql
修改成
/opt/mysql/scripts/mysql_install_db --rpm --basedir=/opt/mysql --datadir="$datadir" --user=mysql


找到如下內容
mysqladmin ping >/dev/null 2>&1 && break
修改成
/opt/mysql/bin/mysqladmin ping >/dev/null 2>&1 && break

保存退出

2.10 設置mysql開機自動啓動服務


[root@centos ~]# cp /usr/local/src/mariadb-10.0.15/packaging/rpm-oel/mysqld.service /lib/systemd/system

[root@centos ~]# systemctl enable mysqld.service

[root@centos ~]# systemctl list-unit-files|grep enabled|grep mysql

[root@centos ~]# vim /etc/systemd/system/mysql.service


找到如下內容
ExecStartPre=/usr/bin/mysql-systemd-start pre
修改成
ExecStartPre=/opt/mysql/bin/mysql-systemd-start pre


找到如下內容
ExecStart=/usr/bin/mysqld_safe
修改成
ExecStart=/opt/mysql/bin/mysqld_safe

找到如下內容
ExecStartPost=/usr/bin/mysql-systemd-start post

修改成
ExecStartPost=/opt/mysql/bin/mysql-systemd-start post


找到如下內容
TimeoutSec=600
修改成
TimeoutSec=30

保存退出


2.11 啓動服務
[root@centos ~]# systemctl daemon-reload

[root@centos ~]# systemctl start mysqld.service

[root@centos ~]# systemctl status mysqld.service -l

[root@centos ~]# ps -ef|grep mysqld

[root@centos ~]# lsof -n | grep jemalloc

 

2.12 數據庫初始化、登陸客戶端

[root@centos ~]# cd /opt/mysql

[root@centos ~]# ./bin/mysql_secure_installation

根據提示設置數據密碼,及其它設置

[root@centos ~]# mysql -u root -p

Mysql [(none)]>status;

Mysql [(none)]>show engines;

Mysql [(none)]>exit;

 

2.13 增長遠程訪問用戶,而且打開防火牆3306端口(不遠程鏈接數據,可省略)

[root@centos ~]# mysql -u root -p

Mysql [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

Mysql [(none)]> FLUSH PRIVILEGES;

Mysql [(none)]> exit;

(root是用戶名,%是主機名或IP地址,這裏的%表明任意主機或IP地址,也可指定惟一的IP地址;密碼是MyPassword )


2.14 防火牆添加3306端口

[root@centos ~]# iptables -L|grep ACCEPT

[root@centos ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

[root@centos ~]# firewall-cmd --reload

[root@centos ~]# iptables -L|grep ACCEPT

 

3.編譯安裝Nginx

3.1 下載包
[root@centos ~]# cd /usr/local/src/

[root@centos ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz

[root@centos ~]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz

[root@centos ~]# wget http://zlib.net/zlib-1.2.8.tar.gz

[root@centos ~]# wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz

[root@centos ~]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.6.0.tar.bz2


3.2 安裝依賴
[root@centos ~]# yum install zlib-devel openssl-devel -y

3.3 安裝Pcre

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf pcre-8.36.tar.gz

[root@centos ~]# cd pcre-8.36

[root@centos ~]# ./configure

[root@centos ~]# make && make install


3.4 安裝openssl

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf openssl-1.0.1j.tar.gz

[root@centos ~]# cd openssl-1.0.1j

[root@centos ~]# ./config

[root@centos ~]# make && make install

 

3.5 安裝zlib

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf zlib-1.2.8.tar.gz

[root@centos ~]# cd zlib-1.2.8

[root@centos ~]# ./configure

[root@centos ~]# make && make install

3.6 建立www用戶和組,建立www虛擬主機使用的目錄,以及Nginx使用的日誌目錄,而且賦予他們適當的權限

[root@centos ~]# groupadd www

[root@centos ~]# useradd -g www www -s /sbin/nologin

[root@centos ~]# mkdir -p /data/www

[root@centos ~]# chmod +w /data/www

[root@centos ~]# chown -R www:www /data/www

***若是無法建立用戶,須要檢查SELinux狀態是否關閉

 

3.7 安裝nginx

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf nginx-1.6.2.tar.gz

[root@centos ~]# cd nginx-1.6.2

[root@centos ~]# ./configure --prefix=/opt/nginx --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36 --with-ld-opt="-ljemalloc"

[root@centos ~]# make && make install


3.8 修改 nginx.conf

[root@centos ~]# vim /opt/nginx/conf/nginx.conf

修改前面幾行爲:

user www www;

worker_processes auto;

error_log logs/error.log crit;

pid logs/nginx.pid;

events{
  use epoll;
  worker_connections 65535;
}


找到,並修改 root 行的內容
location / {
root /data/www;
index index.html index.htm;
}


保存,退出


3.9 創建測試首頁

[root@centos ~]# vim /data/www/index.html

<html>
<head><title>nginx index.html</title></head>
<body>
<h1>index.html</h1>
</body>
</html>

保存,退出


3.10 測試和運行

[root@centos ~]# cd /opt/nginx

[root@centos ~]# ldconfig

[root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf -t

若是顯示下面信息,即表示配置沒問題

nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful


查看jemalloc是否生效,須要先啓動nginx

[root@centos ~]# ./sbin/nginx -c /opt/nginx/conf/nginx.conf

[root@centos ~]# lsof -n | grep jemalloc

ginx 2346 root mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2347 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2348 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2349 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1
nginx 2350 www mem REG 253,1 1824470 51571788 /usr/local/lib/libjemalloc.so.1


3.11 防火牆添加80端口

[root@centos ~]# iptables -L|grep ACCEPT

[root@centos ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

[root@centos ~]# firewall-cmd --reload

[root@centos ~]# iptables -L|grep ACCEPT

 

3.12 瀏覽器打開

http://192.168.1.10

顯示出歡迎內容,則表示成功

 

3.13 做爲服務,開機後啓動

[root@centos ~]# vim /usr/lib/systemd/system/nginx.service

增長如下內容

[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf -t
ExecStart=/opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

:wq 保存退出


[root@centos ~]# systemctl enable nginx.service

[root@centos ~]# systemctl list-unit-files|grep enabled|grep nginx


3.14 啓動服務

[root@centos ~]# ./sbin/nginx -s stop

[root@centos ~]# systemctl daemon-reload

[root@centos ~]# systemctl start nginx.service

[root@centos ~]# systemctl status nginx.service -l

[root@centos ~]# ps -ef|grep nginx

[root@centos ~]# lsof -n | grep jemalloc

 

4 安裝PHP

4.1 準備安裝

下載 php-5.5.19.tar.gz 到/usr/local/src

下載 libiconv-1.14.tar.gz 到/usr/local/src

下載 libmcrypt-2.5.8.tar.gz 到/usr/local/src

下載 mcrypt-2.6.8.tar.gz 到/usr/local/src

下載 mhash-0.9.9.9.tar.gz 到/usr/local/src

下載 memcache-3.0.8.tar.gz 到/usr/local/src

下載 zendopcache-7.0.3.tgz 到/usr/local/src


4.2 更新依賴

yum install autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers libXpm* gcc gcc-c++ -y


4.3 安裝libiconv (增強系統對支持字符編碼轉換的功能)

[root@centos ~]# cd /usr/local/src

[root@centos ~]# tar zvxf libiconv-1.14.tar.gz

[root@centos ~]# cd libiconv-1.14

[root@centos ~]# ./configure --prefix=/usr/local

[root@centos ~]# cd srclib

[root@centos ~]# sed -i -e '/gets is a security/d' ./stdio.in.h

[root@centos ~]# cd ..

[root@centos ~]# make && make install

[root@centos ~]# ln -sf /usr/local/lib/libiconv.so.2 /usr/lib64/

[root@centos ~]# ldconfig

 

4.4 安裝libmcrypt,libltdl(加密算法庫,PHP擴展mcrypt功能對此庫有依耐關係,要使用mcrypt必須先安裝此庫)

[root@centos ~]# cd /usr/local/src

[root@centos ~]# tar zvxf libmcrypt-2.5.8.tar.gz

[root@centos ~]# cd libmcrypt-2.5.8

[root@centos ~]# ./configure

[root@centos ~]# make && make install

[root@centos ~]# cd libltdl/

[root@centos ~]# ./configure --enable-ltdl-install

[root@centos ~]# make && make install

[root@centos ~]# ln -sf /usr/local/lib/libmcrypt.* /usr/lib64/

[root@centos ~]# ln -sf /usr/local/bin/libmcrypt-config /usr/lib64/

[root@centos ~]# ldconfig


4.5 安裝mhash (hash加密算法庫)

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf mhash-0.9.9.9.tar.gz

[root@centos ~]# cd mhash-0.9.9.9

[root@centos ~]# ./configure

[root@centos ~]# make && make install

[root@centos ~]# ln -sf /usr/local/lib/libmhash.* /usr/lib64/

[root@centos ~]# ldconfig

4.6 安裝mcrypt

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf mcrypt-2.6.8.tar.gz

[root@centos ~]# cd mcrypt-2.6.8

[root@centos ~]# ./configure

[root@centos ~]# make && make install

 

4.7 安裝php (已經安裝mariadb,nginx,ldap)

4.7.1 建立mysql軟鏈接、ldap軟鏈接

[root@centos ~]# mkdir -p /opt/mysql/include/mysql

[root@centos ~]# ln -s /opt/mysql/include/* /opt/mysql/include/mysql/

[root@centos ~]# ln -s /usr/lib64/libldap* /usr/lib

[root@centos ~]# ln -s /usr/lib64/liblber* /usr/lib


4.7.2 安裝

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf php-5.5.19.tar.gz

[root@centos ~]# cd php-5.5.19

[root@centos ~]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php/etc --with-mysql=/opt/mysql --with-mysqli=/opt/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap

[root@centos ~]# make ZEND_EXTRA_LIBS='-liconv'

[root@centos ~]# make install

 

4.7.3 複製配置文件

[root@centos ~]# cp php.ini-production /opt/php/etc/php.ini


4.7.4 安裝memcache擴展(已經安裝PHP)

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf memcache-3.0.8.tgz

[root@centos ~]# cd memcache-3.0.8

[root@centos ~]# /opt/php/bin/phpize

[root@centos ~]# ldconfig

[root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config

[root@centos ~]# make && make install


修改php配置文件,支持memcache

[root@centos ~]# vim /opt/php/etc/php.ini

在文件中搜索; extension_dir = "./" ,並在下面添加如下兩行內容

extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20121212/"
extension = "memcache.so"

 

4.7.5 安裝ZendOpcache擴展(已經安裝php)

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# tar zvxf zendopcache-7.0.3.tgz

[root@centos ~]# cd zendopcache-7.0.3

[root@centos ~]# /opt/php/bin/phpize

[root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config

[root@centos ~]# make && make install


修改php配置文件,支持ZendOpcache

[root@centos ~]# vim /opt/php/etc/php.ini

在文件中搜索; extension_dir = "./" ,並在下面添加如下兩行內容

zend_extension=/opt/php/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

 

4.7.6 安裝pdo_mysql擴展(已經安裝PHP)

[root@centos ~]# cd /usr/local/src/

[root@centos ~]# cd php-5.5.19/ext/pdo_mysql/

[root@centos ~]# /opt/php/bin/phpize

[root@centos ~]# ./configure --with-php-config=/opt/php/bin/php-config --with-pdo-mysql=/opt/mysql

[root@centos ~]# make && make install


修改php配置文件,支持pdo_mysql

[root@centos ~]# vim /opt/php/etc/php.ini

在文件中搜索; extension_dir = "./" ,並在下面添加如下兩行內容(若是extension_dir已存在,只添加後面一行)

extension_dir = "/opt/php/lib/php/extensions/no-debug-non-zts-20121212/"

extension = "pdo_mysql.so"

 

4.7.7 安裝php-fpm

[root@centos ~]# cp /opt/php/etc/php-fpm.conf.default /opt/php/etc/php-fpm.conf

[root@centos ~]# vim /opt/php/etc/php-fpm.conf


修改內容,而且讓其它生效

[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 5s
user = www
group = www
pm.max_children = 35
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35

保存,退出

# php-fpm.conf 重要參數詳解

# pid = run/php-fpm.pid
# pid設置,默認在安裝目錄中的var/run/php-fpm.pid,建議開啓

# error_log = log/php-fpm.log
# 錯誤日誌,默認在安裝目錄中的var/log/php-fpm.log

# log_level = notice
# 錯誤級別. 可用級別爲: alert(必須當即處理), error(錯誤狀況), warning(警告狀況), notice(通常重要信息), debug(調試信息). 默認: notice.

# emergency_restart_threshold = 60
# emergency_restart_interval = 60s
# 表示在emergency_restart_interval所設值內出現SIGSEGV或者SIGBUS錯誤的php-cgi進程數若是超過 emergency_restart_threshold個,php-fpm就會優雅重啓。這兩個選項通常保持默認值。

# process_control_timeout = 0
# 設置子進程接受主進程複用信號的超時時間. 可用單位: s(秒), m(分), h(小時), 或者 d(天) 默認單位: s(秒). 默認值: 0.
# daemonize = yes
# 後臺執行fpm,默認值爲yes,若是爲了調試能夠改成no。在FPM中,可使用不一樣的設置來運行多個進程池。 這些設置能夠針對每一個進程池單獨設置。

# listen = 127.0.0.1:9000
# fpm監聽端口,即nginx中php處理的地址,通常默認值便可。可用格式爲: 'ip:port', 'port', '/path/to/unix/socket'. 每一個進程池都須要設置.

# listen.backlog = -1
# backlog數,-1表示無限制,由操做系統決定,此行註釋掉就行。backlog含義參考:http://www.3gyou.cc/?p=41

# listen.allowed_clients = 127.0.0.1
# 容許訪問FastCGI進程的IP,設置any爲不限制IP,若是要設置其餘主機的nginx也能訪問這臺FPM進程,listen處要設置成本地可被訪問的IP。默認值是any。每一個地址是用逗號分隔. 若是沒有設置或者爲空,則容許任何服務器請求鏈接

# listen.owner = www
# listen.group = www
# listen.mode = 0666
# unix socket設置選項,若是使用tcp方式訪問,這裏註釋便可。

# user = www
# group = www
# 啓動進程的賬戶和組

# pm = dynamic #對於專用服務器,pm能夠設置爲static。
# 如何控制子進程,選項有static和dynamic。若是選擇static,則由pm.max_children指定固定的子進程數。若是選擇dynamic,則由下開參數決定:
# pm.max_children #,子進程最大數
# pm.start_servers #,啓動時的進程數
# pm.min_spare_servers #,保證空閒進程數最小值,若是空閒進程小於此值,則建立新的子進程
# pm.max_spare_servers #,保證空閒進程數最大值,若是空閒進程大於此值,此進行清理

# pm.max_requests = 1000
# 設置每一個子進程重生以前服務的請求數. 對於可能存在內存泄漏的第三方模塊來講是很是有用的. 若是設置爲 '0' 則一直接受請求. 等同於 PHP_FCGI_MAX_REQUESTS 環境變量. 默認值: 0.

# pm.status_path = /status
# FPM狀態頁面的網址. 若是沒有設置, 則沒法訪問狀態頁面. 默認值: none. munin監控會使用到

# ping.path = /ping
# FPM監控頁面的ping網址. 若是沒有設置, 則沒法訪問ping頁面. 該頁面用於外部檢測FPM是否存活而且能夠響應請求. 請注意必須以斜線開頭 (/)。

# ping.response = pong
# 用於定義ping請求的返回相應. 返回爲 HTTP 200 的 text/plain 格式文本. 默認值: pong.

# request_terminate_timeout = 0
# 設置單個請求的超時停止時間. 該選項可能會對php.ini設置中的'max_execution_time'由於某些特殊緣由沒有停止運行的腳本有用. 設置爲 '0' 表示 'Off'.當常常出現502錯誤時能夠嘗試更改此選項。

# request_slowlog_timeout = 10s
# 當一個請求該設置的超時時間後,就會將對應的PHP調用堆棧信息完整寫入到慢日誌中. 設置爲 '0' 表示 'Off'

# slowlog = log/$pool.log.slow
# 慢請求的記錄日誌,配合request_slowlog_timeout使用

# rlimit_files = 1024
# 設置文件打開描述符的rlimit限制. 默認值: 系統定義值默承認打開句柄是1024,可以使用 ulimit -n查看,ulimit -n 2048修改。

# rlimit_core = 0
# 設置核心rlimit最大限制值. 可用值: 'unlimited' 、0或者正整數. 默認值: 系統定義值.

# chroot =
# 啓動時的Chroot目錄. 所定義的目錄須要是絕對路徑. 若是沒有設置, 則chroot不被使用.

# chdir =
# 設置啓動目錄,啓動時會自動Chdir到該目錄. 所定義的目錄須要是絕對路徑. 默認值: 當前目錄,或者/目錄(chroot時)

# catch_workers_output = yes
# 重定向運行過程當中的stdout和stderr到主要的錯誤日誌文件中. 若是沒有設置, stdout 和 stderr 將會根據FastCGI的規則被重定向到 /dev/null . 默認值: 空.


4.7.8 修改nginx,支持php

[root@centos ~]# vim /opt/nginx/conf/nginx.conf

找到並修改如下代碼

location ~ \.php$ {
root /data/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
include fastcgi_params;
}


4.7.9 將php-fpm服務加到開機啓動服務

[root@centos ~]# cp /usr/local/src/php-5.5.19/sapi/fpm/php-fpm.service /lib/systemd/system/

[root@centos ~]# vim /lib/systemd/system/php-fpm.service

替換全部的${prefix}爲/opt/php,${exec_prefix}爲/opt/php,最終修改以下

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/opt/php/var/run/php-fpm.pid
ExecStart=/opt/php/sbin/php-fpm --nodaemonize --fpm-config /opt/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

保存,退出


[root@centos ~]# systemctl enable php-fpm.service

[root@centos ~]# systemctl list-unit-files|grep enabled|grep php-fpm

[root@centos ~]# systemctl daemon-reload

[root@centos ~]# systemctl start php-fpm.service

[root@centos ~]# systemctl status php-fpm.service -l


4.7.10 編寫測試頁面

[root@centos ~]# vim /data/www/index.php

輸入如下內容

<html>
<head><title>hello php</title></head>
<body>
<?php phpinfo();?>
</body>
</html>

保存,退出

相關文章
相關標籤/搜索