1. 程式人生 > >安裝php並使用nginx連接PHP

安裝php並使用nginx連接PHP

否則 取消 expires rod doc html 復制 make filesize

版本是5.6.31

安裝前需要安裝的包:

yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel freetype-devel -y

編譯如下:

./configure --prefix=/usr/local/php-5.6.31 \
--with-config-file-path=/usr/local/php-5.6.31/etc --with-bz2 --with-curl \
--enable-ftp --enable-sockets --disable-ipv6 --with-gd \
--with-jpeg-dir=/usr/local --with-png-dir=/usr/local \
--with-freetype-dir=/usr/local --enable-gd-native-ttf \
--with-iconv-dir=/usr/local --enable-mbstring --enable-calendar \
--with-gettext --with-libxml-dir=/usr/local --with-zlib \
--with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd \
--enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath --with-xpm-dir=/usr

如果報錯,可以參考:http://www.linuxidc.com/Linux/2014-05/102327.htm 或者 http://blog.sina.com.cn/s/blog_75a07c3b0101kcwb.html

make

make install

安裝完成後需要配置Php,打開php.ini配置文件,修改如下參數為如下值,否則zabbix安裝不了

把安裝源文件中的php.ini-production復制到/usr/local/php-5.6.31/etc下面,改名為php.ini

修改如下參數:

max_execution_time = 300 memory_limit = 128M post_max_size = 16M
upload_max_filesize = 2M max_input_time = 300 date.timezone PRC 然後:cp /usr/local/php-5.6.31/etc/php-fpm.conf.default /usr/local/php-5.6.31/etc/php-fpm.conf 啟動php-fpm
[[email protected] sbin]# ./php-fpm 
[[email protected] sbin]# netstat -lnt|grep 9000
tcp        0      0 127.0.0.1:9000              0.0
.0.0:* LISTEN

配置nginx連接php

mkdir -p /data/logs/nginx/ # 用於存放nginx日誌

mkdir -p /data/site/zabbixserver.com/ # 站點根目錄 vim /data/site/zabbixserver.com/info.php <?php phpinfo(); ?>

在nginx.conf的http斷中加上如下內容:

####################################start##############################

server {
listen 80;
server_name zabbixserver.com;
access_log /data/logs/nginx/zabbixserver.com.access.log main;

index index.php index.html index.html;
root /data/site/zabbixserver.com;

location /
{
try_files $uri $uri/ /index.php?$args;
}

location ~ .*\.(php)?$
{
expires -1s;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;

}
}

################################end################################

啟動nginx的時候會報錯,把以下取消註釋就可以了

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

啟動nginx後

技術分享

補充一個地方:此時在zabbserver服務器上使用瀏覽器打開http://localhost,會打開nginx的歡迎頁面,但是http://zabbixserver.com會報403;在其它機器上訪問都是403,如果要訪問nginx歡迎頁面,可以修改下配置文件的端口號,然後加端口號訪問。

技術分享

技術分享

不過這時候在zabbixserver服務器上http://localhost:801

具體為什麽?過段時間再學這個

安裝php並使用nginx連接PHP