Centos 7安装 php 和 nginx ,部署ci 3

近期因为部署一个老系统,

 测试安装了 php5.4和php7.0,和 nginx1.20.1

这个需要更新源,以这个为准

https://blog.csdn.net/zhezhebie/article/details/73325663

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 install php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel

 yum install php70w-xml   # 这步可省略,在php70里,发现已经安装

------------------

这个源,也支持 php72的安装,只要把上面的后缀,改为 php72w 即可。

yum install php72w-common php72w-fpm php72w-opcache php72w-gd php72w-mysqlnd php72w-mbstring php72w-pecl-redis php72w-pecl-memcached php72w-devel


 php -v      // 查看版本
 php -m      // 查看扩展

 

yum install php  # 如果不更改源,默认改为5.4版本。没有数据库支持和图片库(验证码显示)和zend opcache,需要另外安装

对于目录的缓存 ,需要配置权限 ,chmod -R 777 /usr/share/nginx/html

 安装php5.4的mysql数据库

yum install php-mysqlnd

安装支持图片库,比如验证码图片显示

yum install  php-gd

 安装 php-fpm 

yum install php-fpm

安装php的zend-opcache 缓存

yum install php-opcache

#以上为 php5.4的安装扩展

-----------------------------------------------


 systemctl start php-fpm
 systemctl enable php-fpm
 systemctl reload php-fpm

安装nginx

yum -y install nginx

安装完后,

/usr/sbin/nginx  -t      // 命令

/etc/nginx/nginx.conf     // 配置文件

/usr/share/nginx       // www目录

 让niginx支持php,这段关键,需要注意

 server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;
        location / {
         index index.php index.html index.htm;
        }
# z这段关键,这段不完善,只是php结尾,需要用最后面下面的那段正则{php($|/)}
一个时正则表达式不正确,一个是缺少这段 fastcgi_split_path_info ^(.+\.php)(.*)$;_
location
~ \.php$ { # 另一种更全面的写法 ~\.php($|/),意思是 结尾.php或者 .php/ fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }

 

--------------------------------------------------------------

ci框架会报一个缓存无法写入的错误。修改 

/application/config/config.php

$config['sess_save_path'] = NULL;   改为如下

$config['sess_save_path'] = FCPATH.'cache/sess_save_path';

 
在正则中,如需要admin的二级目录来访问ci,需要把admin加到正则里面(js|css|images|admin|robots\.txt|index\.php) )
另外,需要注意 php结尾的正则,看后面的哪个正确的生产环境配置。 

 

部署成功的如下,包括分级目录,只要配一个,就ok,不用admin一个目录一个目录的配。这个为生产环境配置,可用。

如果部署不是默认目录,需要在location外也加上 root,地址,否则报找不到 文件的错误

https://www.cnblogs.com/houweijian/p/12467488.html

user  www  www;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        root  html;     # 如果需要更换目录,这里需要改  会报找不到404错误。
        location / {
            root   html;    #这里的目录与上面的一致
            index  index.html index.htm index.php;
            
            if  ($request_filename !~ (\.js|js\/|\.css|css\/|admin|ckfinder|images|\.html)) {           
                rewrite ^(.*)$ /index.php/$1 last;
                break;
            }
        }
      
        location /en {
           if ($request_filename !~ (js|css|images|admin|robots\.txt|index\.php)){
           rewrite ^(.*)$   /en/index.php/$2 last;
           break;
           }
        }


      location ~\.php($|/) {                        # 后缀关键,~\ 之间无空格
            
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info ^(.+\.php)(.*)$;      #关键,访问二级目录时必须
            fastcgi_param   PATH_INFO $fastcgi_path_info;                                    
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param    PATH_TRANSLATED    $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }   



        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        

}

 

 php70安装后的 php -m

[root@centos79-test3 ~]# php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
json
libxml
mbstring
memcached
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

 

 

php 5.4 安装后的 php -m  ,只装php-fpm,不装其他扩展

[root@centos79-test ~]# php -m    
[PHP Modules]    
bz2    
calendar    
Core    
ctype    
curl    
date    
ereg    
exif    
fileinfo    
filter    
ftp    
gettext    
gmp    
hash    
iconv    
json    
libxml    
mhash    
openssl    
pcntl    
pcre    
Phar    
readline    
Reflection    
session    
shmop    
SimpleXML    
sockets    
SPL    
standard    
tokenizer    
xml    
zip    
zlib    
    
[Zend Modules]    

 

php5.4安装扩展后 ,gd ,mysql ,php-fpm,php-opcache

[root@centos79-test html]# php -m    
[PHP Modules]    
bz2    
calendar    
Core    
ctype    
curl    
date    
ereg    
exif    
fileinfo    
filter    
ftp    
gd    
gettext    
gmp    
hash    
iconv    
json    
libxml    
mhash    
mysql    
mysqli    
mysqlnd    
openssl    
pcntl    
pcre    
PDO    
pdo_mysql    
pdo_sqlite    
Phar    
readline    
Reflection    
session    
shmop    
SimpleXML    
sockets    
SPL    
sqlite3    
standard    
tokenizer    
xml    
zip    
zlib    
    
[Zend Modules]    
Zend OPcache

 

posted @ 2022-02-22 21:11  琴声清幽  阅读(295)  评论(0编辑  收藏  举报