您的位置:首页 > 运维架构 > Nginx

手动 2- 安装nginx和php(配置) linux

2014-02-27 15:42 471 查看
先安装下面的组件:

yum  install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gzip  make bzip2bzip2-devel pcre-devel wget ncurses-devel cmake make perl


nginx安装

wget http://nginx.org/download/nginx-1.4.5.tar.gz tar zxvf nginx-1.4.5.tar.gz
cd nginx-1.4.5
./configure --with-http_ssl_module
make && make install

先关闭防火墙:

service iptables stop


php安装

准备工作:
yum -y install gcc automake autoconf libtool make
yum -y install gcc gcc-c++ glibc
yum -y install libmcrypt-devel mhash-devel libxslt-devel 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

1

libmcrypt下载地址:http://download.csdn.net/detail/terry_water/6974153

安装:libmcrypt
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure
make
make install

2

php手动下载地址:http://download.csdn.net/detail/terry_water/6974181

wget http://cn2.php.net/distributions/php-5.5.9.tar.gz tar zvxf php-5.5.9.tar.gz
cd php-5.5.9
./configure --prefix=/usr/local/php --disable-fileinfo   --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc  --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --with-mysql=/usr/local/mysql --without-pear
make
make install


参考例子:
./configure --prefix=/opt/module/php --with-config-file-path=/opt/module/php/etc --with-mysql=/opt/module/mysql --with-mysqli=/opt/module/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir=/opt/module/lib/freetype --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd=/opt/module/lib/gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext

如果安装不需要zlib和zip,则不要编译这两个模块

./configure --prefix=/usr/local/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --with-mysql=/usr/local/mysql --without-pear

3

下面是对php-fpm运行用户进行设置
cd /usr/local/php
cp etc/php-fpm.conf.default etc/php-fpm.conf
vi etc/php-fpm.conf


修改(搜索nobody)
user = www-data
group = www-data


如果www-data用户不存在,那么先添加www-data用户
groupadd www-data
useradd -g www-data www-data


4。配置php-fpm

—————-补充内容php 5.3.6 中 php-fpm 配置 成 服务启动—————-

cp -f /tools/php-5.5.9/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
php-fpm的启动: 
##vim /usr/local/webserver/php/etc/php-fpm.conf 
php-fpm.pid 目录必须是:/usr/local/webserver/php/var/run/php-fpm.pid

chmod 755 /etc/init.d/php-fpm
/etc/init.d/php-fpm start
/sbin/chkconfig --add php-fpm (添加到开机服务列表)
/sbin/chkconfig php-fpm on


php-fpm的启动、停止和重启: 

/etc/init.d/php-fpm start
/etc/init.d/php-fpm stop
/etc/init.d/php-fpm reload


启动效果如下:

Hai_ISD_7_9_Cent56_64:/usr/local/webserver/php/etc#service php-fpm start 

Starting php-fpm  done 

Hai_ISD_7_9_Cent56_64:/usr/local/webserver/php/etc#service php-fpm stop 

Gracefully shutting down php-fpm . done 

Hai_ISD_7_9_Cent56_64:/usr/local/webserver/php/etc#service php-fpm start 

Starting php-fpm  done 

Hai_ISD_7_9_Cent56_64:/usr/local/webserver/php/etc#service php-fpm reload 

Reload service php-fpm  done

php-fpm配置文件

/usr/local/php/etc/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含义参考:

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

如何控制子进程,选项有static和dynamic。

如果选择static,则由pm.max_children指定固定的子进程数。

如果选择dynamic,则由下开参数决定:

pm.max_children,子进程最大数

pm.start_servers,启动时的进程数

pm.min_spare_servers,保证空闲进程数最小值,如果空闲进程小于此值,则创建新的子进程

pm.max_spare_servers,保证空闲进程数最大值,如果空闲进程大于此值,此进行清理

对于专用服务器,pm可以设置为static。

pm.max_requests = 1000

设置每个子进程重生之前服务的请求数. 对于可能存在内存泄漏的第三方模块来说是非常有用的. 如果设置为 ’0′ 则一直接受请求. 等同于 PHP_FCGI_MAX_REQUESTS 环境变量. 默认值: 0.

pm.status_path = /status

FPM状态页面的网址. 如果没有设置, 则无法访问状态页面. 默认值: none.

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 . 默认值: 空.

nginx的配置文件nginx.conf中改为:

下载文件:http://download.csdn.net/detail/terry_water/6974271

下载下来后把nginx包里的文件覆盖到/usr/local/nginx/conf

重启nginx

下面的仅仅是测试的nginx配置:

user  nginx nginx;
worker_processes  1;
pid        logs/nginx.pid;
events {
worker_connections  1024;
}
http {
include       mime.types;
default_type  application/octet-stream;
keepalive_timeout  65;
gzip  on;
server {
listen       80;
server_name  localhost,121.199.39.117;
root /www/web;
location / {
index  index.html index.htm;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}


修改IP为当前您的IP

添加nginx用户:
groupadd nginx
useradd -g nginx nginx


添加文件地址/www/web
mkdir /www
mkdir /www/web

添加log 文件

mkdir /var/log/nginx
touch /var/log/nginx/error.log
chmod 777 -R /var/log/nginx/error.log

添加nginx 文件access.log和error.log

mkdir /www/web_logs
touch /www/web_logs/access.log
chmod 777 /www/web_logs/access.log
touch /www/web_logs/error.log
chmod 777 /www/web_logs/error.log


启动nginx:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf


关闭nginx
ps -ef |grep nginx
kill 进程号


启动php-fpm
/usr/local/php/sbin/php-fpm
如果出错,查看:netstat -ntlp | grep 9000
kill  id号


关闭php-fpm
ps -ef |grep php-fpm
kill 进程号


添加配置文件:

index.php
<?php
echo phpinfo();
?>


添加文件权限chmod 777 -R /www
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: