yum安装 nginx php7.2

安装nginx

添加nginx的源

rpm -ivh http://nginx.org/packages/centos/7/noarch/
RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

然后再执行安装命令

yum install -y nginx

安装之后,可以查看nginx的默认安装目录

 whereis nginx

以下是Nginx的默认路径:

(1) Nginx配置路径:/etc/nginx/

(2) PID目录:/var/run/nginx.pid

(3) 错误日志:/var/log/nginx/error.log

(4) 访问日志:/var/log/nginx/access.log

(5) 默认站点目录:/usr/share/nginx/html

配置nginx

(不是https)

server{
   listen 80;
  server_name 你的域名;
   root /opt/API/public;
   index  index.html index.php;
   location / {
       if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;  //省略index.php 
            break;
          }
   }
     error_page   405 =200 @405;
   location @405
   {
       root  /opt/htdocs;
   }
   location ~ \.php$ {
   include fastcgi_params;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   try_files $uri = 404;
   }
}

(配置https)
在Nginx的安装目录下创建cert目录,并且将下载的全部文件拷贝到cert目录中。如果申请证书时是自己创建的CSR文件,请将对应的私钥文件放到cert目录下并且命名为a.key;

server {
 listen  443 ssl;
 server_name 你的域名;
 root /opt/API/public;
 index index.html index.php;
 ssl_certificate   /etc/nginx/cert/你的证书.pem;
 ssl_certificate_key   /etc/nginx/cert/你的证书.key;
 ssl_session_timeout 5m;
 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
 ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
 ssl_prefer_server_ciphers on;
 location / {
       if (!-e $request_filename) {
            rewrite  ^(.*)$  /index.php?s=/$1  last;
            break;
          }
   }
     error_page   405 =200 @405;
   location @405
   {
       root  /opt/htdocs;
   }
   location ~ \.php$ {
   include fastcgi_params;
   fastcgi_pass 127.0.0.1:9000;
   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
   try_files $uri = 404;
   }
}

安装php7.2

1、安装源

安装php72w,是需要配置额外的yum源地址的,否则会报错不能找到相关软件包。

php高版本的yum源地址,有两部分,其中一部分是epel-release,另外一部分来自webtatic。如果跳过epel-release的话,安装webtatic的时候,会有错误爆出。

所以,这里需要的命令是:

rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

当然,您也可以选择下面的这个命令,也是一样的效果。

yum install epel-release -y
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2、清除历史版本

为了防止centos上面发生php冲突,所以,这个命令还是先执行一下更好些。

yum -y remove php*

3、安装扩展包

事实上,这里面的对应扩展库很多,这里大家一定要注意cli和fpm这两个包,而其它的相关包就看您需要了。

yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel 

还有比较豪华的版本 (TP5框架需要用到pdo扩展 ):

yum -y install php72w php72w-cli
php72w-fpm php72w-common 
php72w-devel php72w-embedded 
php72w-gd php72w-mbstring 
php72w-mysqlnd php72w-opcache 
php72w-pdo php72w-xml
php72w-pecl-redis

4、安装完成以后,启动服务

systemctl enable php-fpm.service
systemctl start php-fpm.service

你可能感兴趣的:(yum安装 nginx php7.2)