centos6.5 yum 安装php7,nginx1.8.1


yum -y update


rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm


touch /etc/yum.repos.d/nginx.repo


vim /etc/yum.repos.d/nginx.repo


name=nginx repo



yum --enablerepo=remi -y update 

#安装服务 php70,mysql,nginx,php-fpm
yum -y --enablerepo=remi,remi-php70 install nginx php-fpm php-common

yum -y --enablerepo=remi,remi-php70 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

yum -y install mysql mysql-server

yum -y install mysql-connector-odbc mysql-devel libdbi-dbd-mysql

touch /etc/nginx/fastcgi.conf

vim /etc/nginx/fastcgi.conf


if ($request_filename ~* (.*)\.php) {
set $php_url $1;
if (!-e $php_url.php) {
return 403;
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 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;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param REDIRECT_STATUS 200;

#打开nginx.conf (ps:我的nginx是最新文档版本1.8.1)
vim /etc/nginx/nginx.conf


user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;

use epoll;
worker_connections 65535;

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

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;

keepalive_timeout 15;

tcp_nodelay on;

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;

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;
gzip_disable msie6;
#limit_zone crawler $binary_remote_addr 10m;
log_format '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#access_log /var/log/nginx/access.log main;
include /etc/nginx/conf.d/*.conf;

#设置nginx 自启服务
/sbin/chkconfig --add nginx
/sbin/chkconfig nginx on

#nginx 启动
/sbin/service nginx start

#设置php-fpm 自启服务
/sbin/chkconfig --add php-fpm
/sbin/chkconfig php-fpm on

#php-fpm 启动
/sbin/service php-fpm start

#添加mysql 自启服务
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on

#mysql 启动
/sbin/service mysqld start

mysqladmin -u root password 'new passwd'
mysql -u root -p
DELETE FROM mysql.user WHERE user ='';

#设置一个独立的nginx 虚拟主机配置
cd /etc/nginx/conf.d

touch zmq.conf

vim zmq.conf


server {
listen 80;
server_name Domain name
index index.html index.htm index.php;
root you in path
location ~ .*\.(php|php5|php7)?$
fastcgi_index index.php;
include fastcgi.conf;
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
expires 30d;
location ~ .*\.(js|css)?$
expires 1h;
location / {
try_files $uri $uri/ /index.php?$query_string;
access_log you in url/you in name.log;


php-fpm 需要配置相关的权限

nginx 执行的程序目录也需要配置权限