Ubuntu安装NGINX+PHP-FPM环境

#禁止IP6协议

vi /etc/modprobe.d/blacklist.conf

#底部追加

blacklist ipv6

#修改软件仓库源

mv /etc/apt/sources.list /etc/apt/sources.list.bak

vi /etc/apt/sources.list

#Ubuntu 14.04 阿里云仓库配置 输入如下内容

deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

#PHP v5.6add-apt-repository ppa:ondrej/php5-5.6

deb http://ppa.launchpad.net/ondrej/php5-5.6/ubuntu trusty main

deb-src http://ppa.launchpad.net/ondrej/php5-5.6/ubuntu trusty main

#NGINX v1.8add-apt-repository ppa:nginx/stable

deb http://ppa.launchpad.net/nginx/stable/ubuntu trusty main 

deb-src http://ppa.launchpad.net/nginx/stable/ubuntu trusty main 

#MYSQL-5.6add-apt-repository ppa:ondrej/mysql-5.6

deb http://ppa.launchpad.net/ondrej/mysql-5.6/ubuntu trusty main 

deb-src http://ppa.launchpad.net/ondrej/mysql-5.6/ubuntu trusty main 

#修改软件仓库源权限

chmod 644 /etc/apt/sources.list

chown root:root /etc/apt/sources.list

#更新源

apt-get update

#如提示信任问题,则需安装公钥

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4F4EA0AAE5267A6C

apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 00A6F0A3C300EE8C

apt-get update

#更新系统

apt-get upgrade && apt-get clean && apt-get autoclean

#安装环境

apt-get install vim make p7zip-full ncftp nginx php5-fpm php5-curl php5-imagick php5-gd php5-mcrypt php5-odbc php5-mysql php5-sqlite php5-mssql  php5-redis php5-ldap php5-imap php5-mcrypt php5-xsl

#独立数据库服务器,遂未安装数据库,需要请加 mysql-server-5.6 mysql-client-5.6

#系统配置

修改文件 /etc/profile

最后加入 ulimit -SHn 65535

#修改PHP配置文件    /etc/php5/fpm/php.ini

sys_temp_dir = "/tmp";设置系统临时目录

upload_tmp_dir = "/tmp";设置PHP上传文件临时目录

session.save_path = "/tmp";设置SESSION保存目录

error_log = "/home/logs/phperror.log";记录PHP运行错误

log_errors_max_len = 102400;加大错误日志文件的尺寸

memory_limit = 384M;加大PHP内存限制,防止生成静态等大型操作内存不够

short_open_tag = On;启用开放标签,部分程序模板需要简写。

date.timezone = PRC;配置默认时区,避免部分程序时间紊乱。

#修改php-fpm配置/etc/php5/fpm/pool.d/www.conf

listen = /dev/shm/php5-fpm.sock ;网传这个目录性能比较好

listen.mode = 0660

pm.max_children = 192

pm.start_servers = 12

pm.min_spare_servers = 8

pm.max_spare_servers = 96

pm.max_requests = 1024

#修改NGINX配置文件

pid /run/nginx.pid;

user www-data www-data;

worker_processes auto;

#worker_cpu_affinity auto;

worker_rlimit_nofile 32768;

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/access.log;#指定默认日志文件路径

error_log /home/logs/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配置文件

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

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

fastcgi_param  QUERY_STRING       $query_string;

fastcgi_param  REQUEST_METHOD     $request_method;

fastcgi_param  CONTENT_TYPE       $content_type;

fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

fastcgi_param  REQUEST_URI        $request_uri;

fastcgi_param  DOCUMENT_URI       $document_uri;

fastcgi_param  DOCUMENT_ROOT      $document_root;

fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;

fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;

fastcgi_param  REMOTE_PORT        $remote_port;

fastcgi_param  SERVER_ADDR        $server_addr;

fastcgi_param  SERVER_PORT        $server_port;

fastcgi_param  SERVER_NAME        $server_name;

fastcgi_param  REDIRECT_STATUS    200;

fastcgi_param  PATH_INFO          $fastcgi_path_info;

fastcgi_index index.php;

fastcgi_pass unix:/dev/shm/php5-fpm.sock;

#创建环境目录

mkdir /home/backup

mkdir /home/logs

mkdir /home/wwwroot

mkdir /home/wwwroot/default

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

<?php

phpinfo();

#配置目录权限

chown -R www-data:www-data /home/*

#重启PHP-FPM服务

service php5-fpm restart

#重启NGINX服务

service nginx restart

#自此环境搭建完成,剩余细节配置运行过程中调优。

Ubuntu 14.04.3 LTS x64 安装稳定版 NGINX 1.8.0 和 PHP5.6.13,纯属安装记录,非技术文档,勿喷!

你可能感兴趣的:(nginx,ubuntu,php-fpm)