Nginx+PHP安装



#安装环境
apt-get install nginx php5-fpm php5-imagick php5-gd php5-odbc php5-mysql php5-sqlite php5-mssql  php5-redis php5-ldap php5-imap php5-mcrypt libmcrypt4 php5-xsl  php5-snmp  php5-apcu php-pear php5-curl

#php5启用启用mcrypt模块
php5enmod mcrypt

#PHP Session
mkdir  /var/lib/php5/sessions
chmod -R 777 /var/lib/php5/sessions


#修改PHP配置文件     /etc/php5/fpm/php.ini
sys_temp_dir = "/tmp";设置系统临时目录
upload_tmp_dir = "/tmp";设置PHP上传文件临时目录
session.save_path = "/var/lib/php5/sessions" ;设置SESSION保存目录
error_log = "/home/logs/php_errors.log";记录PHP运行错误
log_errors_max_len = 102400;加大错误日志文件的尺寸
memory_limit = 384M;加大PHP内存限制,防止生成静态等大型操作内存不够
short_open_tag = On;启用开放标签,部分程序模板需要简写。
#date.timezone = PRC;配置默认时区,避免部分程序时间紊乱。
date.timezone =   Asia/Shanghai

#修改php-fpm配置 /etc/php5/fpm/pool.d/www.conf
listen = /var/run/php5-fpm.sock  ;网传这个目录性能比较好
listen.mode = 0660
pm.max_children =98
pm.start_servers =6
pm.min_spare_servers =4
pm.max_spare_servers = 96
pm.max_requests = 2000

#修改NGINX配置文件 /etc/nginx/nginx.conf
pid /run/nginx.pid;

user www-data www-data;

worker_processes auto;
#worker_processes 8;
worker_cpu_affinity auto;
#worker_cpu_affinity 00000001  00000010  00000100  00001000  00010000  00100000  01000000 1 0000000 ;
worker_rlimit_nofile 65536;

events {
use epoll;
worker_connections 8192;
multi_accept on;
}
http {
server_tokens off;
sendfile on;
autoindex off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120;#长连接超时时间,单位是秒
reset_timedout_connection on;#关闭不响应的客户端连接
send_timeout 15;#发送数据超时

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

gzip on;
gzip_disable "MSIE [1-6]\.";
gzip_min_length  1k;
gzip_comp_level 5;
gzip_types text/plain text/html text/css text/xml text/plain application/json application/javascript;

access_log /home/logs/nginx/access.log;#指定默认日志文件路径
error_log /home/logs/ nginx/ error.log error;#指定默认错误日志文件路径

server {
listen 80 default_server;
server_name _;
root /home/wwwroot/default/;
index default.html index.php index.html index.htm;
location ~ \.php$ {
include fastcgi.conf;
}
}
include /etc/nginx/sites-enabled/*.vhost;
}

#修改fastcgi配置文件/etc/nginx/fastcgi.conf添加 
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;

如何配置fastcgi_pass unix:/dev/shm/php5-fpm.sock;
命令:ss --unix --all | grep php
输出类似:
u_str LISTEN 0 128 /run/php-fpm/php-fpm.sock 30653 * 0
我在 nginx.conf 中的配置
fastcgi_pass unix:/run/php-fpm/php-fpm.sock


#创建环境目录
mkdir /home/backup
mkdir /home/crontab
mkdir  /home/cache
mkdir /home/logs
mkdir /home/logs/nginx
mkdir /home/wwwroot
mkdir /home/wwwroot/default

#创建环境测试文件      /home/wwwroot/default/index.php
phpinfo();

#配置目录权限
chown -R www-data:www-data /home/*

#重启PHP-FPM服务
service php5-fpm restart

#重启NGINX服务
service nginx restart

#配置文件从SVN config目录进行copy覆盖到服务器
#安装环境
apt-get install nginx php5-fpm php5-imagick php5-gd php5-odbc php5-mysql php5-sqlite php5-mssql  php5-redis php5-ldap php5-imap php5-mcrypt libmcrypt4 php5-xsl  php5-snmp  php5-apcu php-pear php5-curl

#php5启用启用mcrypt模块
php5enmod mcrypt

#PHP Session
mkdir  /var/lib/php5/sessions
chmod -R 777 /var/lib/php5/sessions


#修改PHP配置文件     /etc/php5/fpm/php.ini
sys_temp_dir = "/tmp";设置系统临时目录
upload_tmp_dir = "/tmp";设置PHP上传文件临时目录
session.save_path = "/var/lib/php5/sessions" ;设置SESSION保存目录
error_log = "/home/logs/php_errors.log";记录PHP运行错误
log_errors_max_len = 102400;加大错误日志文件的尺寸
memory_limit = 384M;加大PHP内存限制,防止生成静态等大型操作内存不够
short_open_tag = On;启用开放标签,部分程序模板需要简写。
#date.timezone = PRC;配置默认时区,避免部分程序时间紊乱。
date.timezone =   Asia/Shanghai

#修改php-fpm配置 /etc/php5/fpm/pool.d/www.conf
listen = /var/run/php5-fpm.sock  ;网传这个目录性能比较好
listen.mode = 0660
pm.max_children =98
pm.start_servers =6
pm.min_spare_servers =4
pm.max_spare_servers = 96
pm.max_requests = 2000

#修改NGINX配置文件 /etc/nginx/nginx.conf
pid /run/nginx.pid;

user www-data www-data;

worker_processes auto;
#worker_processes 8;
worker_cpu_affinity auto;
#worker_cpu_affinity 00000001  00000010  00000100  00001000  00010000  00100000  01000000 1 0000000 ;
worker_rlimit_nofile 65536;

events {
use epoll;
worker_connections 8192;
multi_accept on;
}
http {
server_tokens off;
sendfile on;
autoindex off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 120;#长连接超时时间,单位是秒
reset_timedout_connection on;#关闭不响应的客户端连接
send_timeout 15;#发送数据超时

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

gzip on;
gzip_disable "MSIE [1-6]\.";
gzip_min_length  1k;
gzip_comp_level 5;
gzip_types text/plain text/html text/css text/xml text/plain application/json application/javascript;

access_log /home/logs/nginx/access.log;#指定默认日志文件路径
error_log /home/logs/ nginx/ error.log error;#指定默认错误日志文件路径

server {
listen 80 default_server;
server_name _;
root /home/wwwroot/default/;
index default.html index.php index.html index.htm;
location ~ \.php$ {
include fastcgi.conf;
}
}
include /etc/nginx/sites-enabled/*.vhost;
}

#修改fastcgi配置文件/etc/nginx/fastcgi.conf添加 
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php5-fpm.sock;

如何配置fastcgi_pass unix:/dev/shm/php5-fpm.sock;
命令:ss --unix --all | grep php
输出类似:
u_str LISTEN 0 128 /run/php-fpm/php-fpm.sock 30653 * 0
我在 nginx.conf 中的配置
fastcgi_pass unix:/run/php-fpm/php-fpm.sock


#创建环境目录
mkdir /home/backup
mkdir /home/crontab
mkdir  /home/cache
mkdir /home/logs
mkdir /home/logs/nginx
mkdir /home/wwwroot
mkdir /home/wwwroot/default

#创建环境测试文件      /home/wwwroot/default/index.php
phpinfo();

#配置目录权限
chown -R www-data:www-data /home/*

#重启PHP-FPM服务
service php5-fpm restart

#重启NGINX服务
service nginx restart

#配置文件从SVN config目录进行copy覆盖到服务器

你可能感兴趣的:(其它)