1.安装yum源
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安装nginx
yum install -y nginx
3.启动nginx并设置开机自动运行
systemctl start nginx #启动,restart-重启,stop-停止
systemctl enable nginx #开机启动
4.查看版本及运行状态
nginx -v #查看版本
ps -ef | grep nginx #查看运行状态
注意,这里的nginx运行的用户是root ,最好改成nginx
二.安装php7
更换安装源
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum clean all
yum makecache
yum update
安装
yum install php72w* --skip-broken
//或者指定模块7.0
yum install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel
//或者安装7.2版本
yum install php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel
配置php
vi /etc/php.in
改:cgi.fix_pathinfo=0 (大概在762行,如果文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以避免遭受恶意脚本注入的攻击)
配置php-fpm
vi /etc/php-fpm.d/www.conf
- user = nginx
- group = nginx
- listen = /var/run/php-fpm/php-fpm.sock
- listen.owner = nginx
- listen.group = nginx
配置nginx支持PHP
vi /etc/nginx/conf.d/default.conf
location / { root /web/web1; index index.php index.html index.htm; } location ~ \.php$ { #注意这里,也要把root加进去 root /web/web1; try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
注意防火墙
