一、搭建php环境

# 使用之前请确保已经安装wget,如未安装请执行下面一条命令来安装

yum install -y wget

# 1.备份当前yum源(可选)

cd /etc/yum.repos.d/
cp CentOS-Base.repo CentOS-Base-repo.bak

# 2.使用wget下载阿里yum源repo文件

wget http://mirrors.aliyun.com/repo/Centos-7.repo

# 3.清理默认缓存包

yum clean all

# 4.把下载下来的阿里云repo文件设置成为默认源

mv Centos-7.repo CentOS-Base.repo

# 5.生成阿里云yum源缓存并更新yum源

yum makecache
yum update

# 6.安装PHP应用

yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y yum-utils
yum-config-manager --enable remi-php73
yum install -y php php-bcmath php-pecl-inotify php-mbstring php-pecl-redis5 php-pecl-zip php-mysqlnd php-pdo
yum install -y php-fpm

# 7.扩展常用PHP依赖

yum install epel-release  -y
yum install -y gcc gcc-c++ pcre pcre-devel openssl openssl-devel zlib zlib-devel
yum -y install ncurses-devel
yum -y install wget vim pcre pcre-devel openssl openssl-devel libicu-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
yum install php-xml

# 8.启动php-fpm并设置为开机启动

systemctl start php-fpm  #启动php-fpm命令
systemctl enable php-fpm #设置为开机启动
systemctl restart php-fpm #重新启动php-fpm

二、安装Nginx

1.yum安装nginx

yum install nginx -y

2.配置nginx.conf

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
use epoll;
worker_connections 51200;
multi_accept on;
}

http {
include 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 1024m;
client_body_buffer_size 10m;
sendfile on;
tcp_nopush on;
keepalive_timeout 120;
server_tokens off;
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;
fastcgi_intercept_errors on;

#Gzip Compression
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

##Brotli Compression
#brotli on;
#brotli_comp_level 6;
#brotli_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;

##If you have a lot of static files to serve through Nginx then caching of the files' metadata (not the actual files' contents) can save some latency.
#open_file_cache max=1000 inactive=20s;
#open_file_cache_valid 30s;
#open_file_cache_min_uses 2;
#open_file_cache_errors on;

######################## default ############################
server {
listen 80;
server_name _;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/www/default;
index index.html index.htm index.php;
#error_page 404 /404.html;
#error_page 502 /502.html;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ [^/]\.php(/|$) {
#fastcgi_pass remote_php_ip:9000;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
deny all;
}
}
########################## vhost #############################
include vhost/*.conf;
}

3.nginx文件配置

server {
listen 80;
server_name xxx.xxx.com;
access_log /data/wwwlogs/access_nginx.log combined;
root /data/www/cms/cmsadmin;
index index.html index.htm index.php;
#error_page 404 /404.html;
#error_page 502 /502.html;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
location ~ ^/(\.user.ini|\.ht|\.git|\.svn|\.project|LICENSE|README.md) {
deny all;
}
}

三、搭建redis

1.yum安装redis

yum install redis -y

2.配置redis.conf

搜索 protected-mode yes 改为 protected-mode no
搜索 requirepass 放开注释改为 requirepass xxxx #代表密码
搜索 daemonize no 改为 daemonize yes #代码后台启动

3.启动redis

/usr/sbin/nginx -c /etc/nginx/nginx.conf  #启动redis命令
/usr/sbin/nginx -c /etc/nginx/nginx.conf -s reload #重启nginx命令