linux中PHP7+nginx

下載
http://cn2.php.net/distributions/php-5.6.22.tar.bz2 cn2.php.net/distributio…
更新
yum源
這裏將
Centos的yum源更換爲國內的阿里雲源。yum安裝正常的能夠跳過本步驟。
阿里雲
Linux安裝鏡像源地址:
http://mirrors.aliyun.com/
一、備份你的原鏡像文件,以避免出錯後能夠恢復:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
二、下載新的CentOS-Base.repo 到/etc/yum.repos.d/
## CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo mirrors.aliyun.com/repo/Centos…
## CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo mirrors.aliyun.com/repo/Centos…
## CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo mirrors.aliyun.com/repo/Centos…
三、生成緩存
yum clean all
yum makecache
安裝依賴
yum install -y gcc gcc-c++ make cmake bison autoconf wget lrzsz
yum install -y libtool libtool-ltdl-devel
yum install -y freetype-devel libjpeg.x86_64 libjpeg-devel libpng-devel gd-devel
yum install -y python-devel patch sudo
yum install -y openssl* openssl openssl-devel ncurses-devel
yum install -y bzip* bzip2 unzip zlib-devel
yum install -y libevent*
yum install -y libxml* libxml2-devel
yum install -y libcurl* curl-devel
yum install -y readline-devel
須要編譯
libmcrypt、mhash、mcrypt庫(下載見文末附件)
tar zxvf /libmcrypt-2.5.8.tar.gz \
&& cd /libmcrypt-2.5.8 && ./configure && make && make install && cd - / && rm -rf /libmcrypt* \
&& tar zxvf /mhash-0.9.9.9.tar.gz && cd mhash-0.9.9.9 && ./configure && make && make install && cd - / && rm -rf /mhash* \
&& tar zxvf /mcrypt-2.6.8.tar.gz && cd mcrypt-2.6.8 && LD_LIBRARY_PATH=/usr/local/lib ./configure && make && make install && cd - / && rm -rf /mcrypt*
開始安裝
使用
./configure --help
查看編譯支持的選項。若是寫了不支持的選項,如
php7裏不支持--with-mysql=mysqlnd
會提示:
configure: WARNING: unrecognized options: --with-mysql
tar jxvf php-7.0.7.tar.bz2
cd php-7.0.7

$ ./configure --prefix=/usr/local/php --with-config-file-scan-dir=/usr/local/php/etc/ --enable-inline-optimization --enable-opcache --enable-session --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pdo-sqlite --with-sqlite3 --with-gettext --enable-mbregex --enable-mbstring --enable-xml --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-xmlrpc --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-curlwrappers --with-zlib --enable-zip --with-bz2 --with-gd --enable-gd-native-ttf --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-readline

$ make
$ make install
可選項:
--with-fpm-user=www --with-fpm-group=www
這裏面開啓了不少擴展。若是這時候忘了開啓,之後還能加上嗎?答案是能夠的。之後只須要進入源碼的
ext
目錄,例如忘了
pdo_mysql
,進入
ext/pdo_mysql
,使用
phpize工具,像安裝普通擴展同樣便可生成pdo_mysql.so。
關於:
--enable-safe-mode
開啓的話
php能夠執行一下系統函數,建議關閉(可搜索受此函數影響的php函數)
#
若是隻須要配置某一個目錄能夠執行則 設置爲
on
並指定
safe_mode_exec_dir=string
目錄來執行系統函數。
#
本特性已自
PHP 5.3.0
起廢棄並將自
PHP 5.4.0
起移除。
safe_mode = off
php7編譯不用加這個配置。
編譯比較耗內存和
CPU。等待半小時左右,編譯完成:
Build complete.
Don't forget to run 'make test'.

Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/
Installing PHP CLI binary: /usr/local/php/bin/
Installing PHP CLI man page: /usr/local/php/php/man/man1/
Installing PHP FPM binary: /usr/local/php/sbin/
Installing PHP FPM config: /usr/local/php/etc/
Installing PHP FPM man page: /usr/local/php/php/man/man8/
Installing PHP FPM status page: /usr/local/php/php/php/fpm/
Installing phpdbg binary: /usr/local/php/bin/
Installing phpdbg man page: /usr/local/php/php/man/man1/
Installing PHP CGI binary: /usr/local/php/bin/
Installing PHP CGI man page: /usr/local/php/php/man/man1/
Installing build environment: /usr/local/php/lib/php/build/
Installing header files: /usr/local/php/include/php/
Installing helper programs: /usr/local/php/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.0
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.3.0
[PEAR] PEAR - installed: 1.10.1
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/php-7.0.7/build/shtool install -c ext/phar/phar.phar /usr/local/php/binln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers: /usr/local/php/include/php/ext/pdo/

[root@e8ed9b00e80c php-7.0.7]# /usr/local/php/bin/php -m
[PHP Modules]
bcmath
bz2
Core
ctype
curldate
dom
fileinfo
filter
gd
gettexthash
iconvjson
libxml
mbstring
mcrypt
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
Reflectionsession
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizerxml
xmlreader
xmlrpc
xmlwriter
zip
zlib
文件
須要從安裝包裏複製
php.ini、php-fpm.conf到安裝目錄:
$ cp php-7.0.7/php.ini* /usr/local/php/etc/

$ cd /usr/local/php/etc/

$ cp php.ini-production /usr/local/php/lib/php.ini
$ cp php-fpm.conf.default php-fpm.conf

$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf

$ ls
pear.conf php-fpm.conf.default php.ini-development php.ini-production
配置
php.ini
#
不顯示錯誤,默認
display_errors = Off
#
在關閉
display_errors
後開啓
PHP
錯誤日誌(路徑在
php-fpm.conf
中配置),默認
log_errors = On
#
字符集,默認
default_charset = "UTF-8"
#
文件上傳大小,默認值過小,建議修改
10M
upload_max_filesize = 2M
# Maximum size of POST data that PHP will accept.
表單最大值,默認是
8M
,若是表單含有多圖上傳,大小可能不夠。超過該大小後臺收不到 表單數據
post_max_size = 8M
#
設置
PHP
的擴展庫路徑
,
,默認被註釋了。
extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/"#
若是不設置
extension_dir
,也能夠直接寫絕對位置:
# extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20151012/redis.so

#
設置
PHP
的時區
date.timezone = PRC
#
開啓
opcache
,默認是
0
[opcache]; Determines if Zend OPCache is enabled
opcache.enable=1
配置
php-fpm.conf
;
去掉裏分號,方便之後重啓。建議修改
;
Default Value: none;
下面的值最終目錄是
/usr/local/php/var/run/php-fpm.pid;
開啓後能夠平滑重啓
php-fpm
pid = run/php-fpm.pid
;
設置錯誤日誌的路徑,能夠默認值
;
Note: the default prefix is /usr/local/php/var; Default Value: log/php-fpm.log,
/usr/local/php/var/log/php-fpm.log
error_log = /var/log/php-fpm/error.log
; Log
等級,能夠默認值
; Possible Values: alert, error, warning, notice, debug; Default Value: notice
log_level = notice
;
後臺運行,默認
yes
,能夠默認值
;
Default Value: yes;
daemonize = yes
;
引入
www.conf
文件中的配置,能夠默認值
include=/usr/local/php/etc/php-fpm.d/*.conf
配置
www.conf(在php-fpm.d目錄下)
www.conf擴展配置文件:
這是
php-fpm進程服務的
;
設置用戶和用戶組,默認都是
nobody
。能夠默認值
user = nginx
group = nginx
;
設置
PHP
監聽
;
下面是默認值,不建議使用。能夠默認值
; listen = 127.0.0.1:9000;
根據
nginx.conf
中的配置
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
listen = /var/run/php-fpm/php-fpm.sock
######
開啓慢日誌。能夠默認值
slowlog = /var/log/php-fpm/$pool-slow.logrequest_slowlog_timeout = 10s
保存配置文件後,檢驗配置是否正確的方法爲
:
/usr/local/php/sbin/php-fpm -t
若是出現諸如
test is successful 字樣,說明配置沒有問題。另外該命令也可讓咱們知道php-fpm的配置文件在哪。
創建軟鏈接:
ln -sf /usr/local/php/sbin/php-fpm /usr/bin/
ln -sf /usr/local/php/bin/php /usr/bin/
ln -sf /usr/local/php/bin/phpize /usr/bin/
ln -sf /usr/local/php/bin/php-config /usr/bin/
ln -sf /usr/local/php/bin/php-cig /usr/bin/
或者將
php編譯生成的bin
目錄添加到當前
Linux系統的環境變量中:
echo -e '\nexport PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH\n' >> /etc/profile && source /etc/profile
啓動
php-fpm
/usr/local/php/sbin/php-fpm
若是提示沒有
www用戶(www.conf裏填寫了www而不是nobody),則新增:
useradd wwwchown -R www:www /www
檢測是否啓動
:
ps aux |grep php-fpm #
另外該命令也可讓咱們知道
fpm
的配置文件在哪。
netstat -ant |grep 9000
查看
php-fpm進程數:
ps aux | grep -c php-fpm
php-fpm操做彙總:
/usr/local/php/sbin/php-fpm # php-fpm
啓動
kill -INT `cat /usr/local/php/var/run/php-fpm.pid` # php-fpm
關閉
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` #php-fpm
平滑重啓
重啓方法二:
killall php-fpm/usr/local/php/sbin/php-fpm &
若是沒法平滑啓動,那就終止進程
id:
ps aux | grep php-fpmkill -9 1210 #1210
php-fpm
進程
id
安裝
Nginx
nginx news
http://nginx.org/
依賴:
#
爲了支持
rewrite
功能,咱們須要安裝
pcre
yum install pcre-devel
#
須要
ssl
的支持,若是不須要
ssl
支持,請跳過這一步
# yum install openssl*
# gzip
類庫安裝,按需安裝
# yum install zlib zlib-devel
配置編譯參數
$ tar -zxvf nginx-1.11.1.tar.gz
$ cd nginx-1.11.1
$ ./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-pcre
配置
ok:
Configuration summary
+ using system PCRE library
+ using system OpenSSL library
+ md5: using OpenSSL library
+ sha1: using OpenSSL library
+ using system zlib library

nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
編譯安裝
nginx
makemake install
設置軟鏈接:
ln -sf /usr/local/nginx/sbin/nginx /usr/sbin
檢測
nginx:
nginx -t
顯示:

nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
成功了。咱們從新配置下
nginx.conf:
#user nobody;worker_processes 1;
#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;
#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

#
解決虛擬主機名字過長
http://www.jb51.net/article/26412.htm
server_names_hash_bucket_size 128;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

autoindex on;#
顯示目錄
autoindex_exact_size on;#
顯示文件大小
autoindex_localtime on;#
顯示文件時間

include vhosts/*.conf;

}
配置
localhost:
vhosts/localhost.conf
server {
listen 80;
server_name localhost;

#charset utf-8;

#access_log logs/host.access.log main;

location / {
root /www/www/;
index index.php index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /www/www/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
啓動
nginx:
/usr/local/nginx/sbin/nginx
#
或者
nginx
重啓:
/usr/local/nginx/sbin/nginx -s reload
#
或者
nginx -s reload
中止:
/usr/local/nginx/sbin/nginx -s stop
#
或者
nginx -s stop
若是提示
80端口被佔用了,可使用ps aunx | grep 80
查看。通常是
apache佔用了。可使用:
chkconfig --list
chkconfig nginx on
service apache off
禁止
apache啓動並關閉apache服務。
相關文章
相關標籤/搜索