在linux下安装配置php+nginx环境(不包含mysql)

最近在搞php,在这方面是绝对的新手,安装配置环境都搞了一天,故写下安装的记录日志,以供自己以后查看。

首先是安装包下载地址:http://pan.baidu.com/s/1gdgnYV5


Linux+php+nginx环境安装步骤

安装c++编辑器

命令列表:

yum install -y gcc-c++.x86_64

安装pcre

命令列表:

tar -zvxf pcre-8.34.tar.gz

cd pcre-8.34

./configure --prefix=/usr/local/pcre

make

make install

安装zlib(注意,后两句必须加,否则安装libpng会提示找不到zlib)

命令列表:

tar -zvxf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure --prefix=/usr/local/zlib

make

make install

export LDFLAGS="-L/usr/local/zlib/lib"

export CPPFLAGS="-I/usr/local/zlib/include"

安装openssl

命令列表:

tar -zvxf openssl-1.0.1j.tar.gz

cd openssl-1.0.1j

./config --prefix=/usr/local/openssl

make depend

make

make install

安装nginx

命令列表:(注意,pcre、openssl和zlib路径为源码路径,自行脑补)

tar -zvxf nginx-1.6.2.tar.gz

cd nginx-1.6.2

./configure --prefix=/usr/local/nginx --with-openssl=/root/install/openssl-1.0.1j --with-zlib=/root/install/zlib-1.2.8 --with-pcre=/root/install/pcre-8.34 --with-http_stub_status_module --with-http_ssl_module

安装libxml2

命令列表:

tar -zvxf libxml2-2.9.2.tar.gz

cd libxml2-2.9.2

./configure --prefix=/usr/local/libxml2 --with-zlib=/usr/local/zlib --with-python=no

make

make install

安装curl

命令列表:

tar -zvxf curl-7.39.0.tar.gz

cd curl-7.39.0

./configure --prefix=/usr/local/curl --with-ssl --with-zlib=/usr/local/zlib

make

make install

安装jpeg

命令列表:

tar -zvxf jpegsrc.v9.tar.gz

cd jpeg-9

./configure --prefix=/usr/local/jpeg --enable-shared --enable-static

make

make install

安装libpng

命令列表:

tar -zvxf libpng-1.6.15.tar.gz

cd libpng-1.6.15

./configure --prefix=/usr/local/libpng

make

make install

安装freetype(需要设置环境变量)

命令列表:

tar -zxvf freetype-2.5.2.tar.gz

cd freetype-2.5.2

vi /etc/profile

(末尾添加)

LIB_PNG=/usr/local/libpng/bin

PATH=$LIB_PNG:$PATH

export PATH

:wq

(重启或手动export)

./configure --prefix=/usr/local/freetype

make

make install

安装gd

命令列表:

tar -zvxf libgd-2.1.0.tar.gz

cd libgd-2.1.0

./configure --prefix=/usr/local/gd --with-png=/usr/local/libpng --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype

make

make install

安装PHP(因为服务器是nginx,所以需要启用fpm)

命令列表:

tar -zvxf php-5.5.19.tar.gz

cd php-5.5.19

./configure --prefix=/usr/local/php --with-gd=/usr/local/gd --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-freetype-dir=/usr/local/freetype --with-zlib=/usr/local/zlib --with-libxml-dir=/usr/local/libxml2 --with-curl=/usr/local/curl --enable-fpm --enable-mbstring --enable-soap --enable-sockets --with-mysql

make

(如果报error: X11/xpm.h: No such file or directory,就先执行yum –y install libXpm-devel, configure参数加上--with-xpm-dir=/usr/lib)

make install

cp php.ini-production /usr/local/php/php.ini

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

cp sapi/fpm/php-fpm /usr/local/bin

Linux+php+nginx环境配置步骤

vi /usr/local/php/etc/php-fpm.conf

去掉pid = run/php-fpm.pid前的注释,这样fpm的进程就会被写入这个文件:/usr/local/php/var/run/php-fpm.pid

创建nginx运行的组和用户

groupadd www

useradd -g www -M -s /sbin/nologin www

编辑nginx目录下的conf目录下的conf配置

user  www www;

更改wrker_processes的数值为2

(wrker_processes的数值一般设置为内核数)

error_log  logs/error.log crit

pid        logs/nginx.pid;

events {

use epoll;#Linux 下性能最好的 event 模式

worker_connections  2048;# 每个工作进程允许最大的同时连接数

}

(在http{***}之间增加如下内容,有重复项就覆盖)

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

client_max_body_size 20m;#改为请求体最小20m

gzip on;

gzip_min_length  1k;

gzip_buffers     4 16k;

gzip_http_version 1.0;

gzip_comp_level 2;

gzip_types       text/plain application/x-javascript text/css application/xml;

gzip_vary on;

#配置虚拟主机

include /usr/local/nginx/conf/vhosts/*.conf;

创建目录/usr/local/nginx/conf/vhosts/

建立程序对应conf后缀的配置文件

配置如下

server {

listen       8888;

server_name  mobile.wemeke.com;

#charset koi8-r;

#access_log  logs/host.access.log  main;

root   /server/php/www;

index  index.html index.htm index.php;

#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;

}

#将请求交给fpm来处理

location ~ [^/]\.php(/|$) {

fastcgi_split_path_info ^(.+?\.php)(/.*)$;

if (!-f $document_root$fastcgi_script_name) {

return 404;

}

fastcgi_param PATH_INFO $fastcgi_path_info;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

}

log_format  '$remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" "$http_x_forwarded_for"';

location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$

{

expires 30d;

}

location ~ .*\.(js|css)?$

{

expires 1h;

}

# 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           html;

#    fastcgi_pass   127.0.0.1:9000;

#    fastcgi_index  index.php;

#    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

#    include        fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

#    deny  all;

#}

}

php-fpm和nginx相关命令

启动php-fpm: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`

启动nginx:/usr/local/nginx/sbin/nginx

关闭nginx:/usr/local/nginx/sbin/nginx -s stop

发表评论

邮箱地址不会被公开。 必填项已用*标注

😉😐😡😈🙂😯🙁🙄😛😳😮:mrgreen:😆💡😀👿😥😎😕

验证码 *