1. 程式人生 > >centos7上部署php7遇到的坑

centos7上部署php7遇到的坑

一直以來,都是在ubuntu上部署的,今天突然來了一個centos7.4的機器要部署環境


先說下坑:沒怎麼在centos7上裝過php7,關鍵在於源

網上第一次找的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

web需要用到memcache的php外掛,這個外掛應該有兩個

php7-memcache,php7-memcached,但是這個源中沒有php7-memcache,如下圖

所以一直搞不定,索性再查,查到下面源

大概是從這個網站先看到:https://xieye.iteye.com/blog/2429305,然後在搜尋這個源用的人多不多,發現還可以

yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm

於是乎解決:

 


下面說下整個操作流程:一切建立在centos7.4上

一、裝nginx

[[email protected] ~]# wget https://raw.githubusercontent.com/uscwifi/yum-repository/master/nginx-centos7.repo -O /etc/yum.repos.d/nginx.repo
[
[email protected]
~]# yum repolist [[email protected] ~]# yum install nginx -y

二、裝php7及相關外掛

[[email protected] ~]# yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[[email protected] ~]# yum repolist
[[email protected] ~]# yum install php70-php php70-php php70-php-bcmath php70-php-common php70-php-devel php70-php-fpm php70-php-gd php70-php-mbstring php70-php-mcrypt  php70-php-mysqlnd php70-php-pecl-memcache php70-php-pecl-memcached -y

三、裝memcache

[[email protected] ~]# yum install memcached libmemcached -y

四、拉程式碼,寫nginx配置檔案

[[email protected] ~]# mkdir -p /var/www
[[email protected] ~]# cd /var/www/
[[email protected] www]# git clone https://gitlab.x.xxx.com/cactus/xxx_banckend.git
[[email protected] www]# cd /etc/nginx/conf.d/
[[email protected] conf.d]# vim xxx.xxx.com.conf
[[email protected] conf.d]# cat xxx.xxx.com.conf 
server {
      listen 80 ;
      server_name xxx.xxx.com;
      if ($host ~ xxx.xxx.com)
      {
       rewrite ^/(.*)$ https://xxx.xxx.com.com$request_uri? permanent;
      }
      access_log /var/log/nginx/xxx.xxx.com-access.log;
      error_log /var/log/nginx/xxx.xxx.com-error.log;
}
server {
       listen 443;
       server_name xxx.xxx.com;
       root /var/www/Tianzige_banckend/web;
       index index.html index.htm index.php ;
       ssl on ;
       ssl_certificate /etc/nginx/ssl/xxx.xxx.com.cer;
       ssl_certificate_key /etc/nginx/ssl/xxx.xxx.com.key;
       ssl_protocols       SSLv3 TLSv1 TLSv1.1 TLSv1.2;
       ssl_prefer_server_ciphers on;
       ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;
       access_log /var/log/nginx/xxx.xxx.com-access.log;
       error_log /var/log/nginx/xxx.xxx.com-error.log;
 
       location ~ \.(gif|jpg|jpeg|png|css|js|ico)$ {
 
       }
 
	location ~ ^/favicon\.ico$ {
                root   /var/www/sites/8083/xxxx-backend/web/;
        }

	location / {
        	rewrite ^/(.+)$ /index.php last;
	} 
	location ^~ /api/ {
                proxy_pass xxx.xxx.com/;
                proxy_redirect default ;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }

       location ~ \.php$ {
            fastcgi_pass             127.0.0.1:9000;
            #fastcgi_pass             unix:/var/run/php/php7.0-fpm.sock;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_index index.php;
            fastcgi_buffer_size       128k;
            fastcgi_buffers           64 128k;
            fastcgi_intercept_errors  on;
            fastcgi_param   PATH_INFO $fastcgi_path_info;
            fastcgi_param             HTTP_AUTHORIZATION  $http_authorization;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include                   fastcgi_params;
            fastcgi_connect_timeout 300;
            fastcgi_read_timeout 300;
            fastcgi_send_timeout 300;
            client_max_body_size 100m;
        }
        location ~ /.git
        {
            deny all;
        }
}

五、調節nginx程序數,php的程序數

[[email protected] conf.d]# vim /etc/nginx/nginx.conf
 worker_processes  auto;
[[email protected] conf.d]# vim /etc/opt/remi/php70/php-fpm.d/www.conf
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
user = nginx
group = nginx

六、啟動相關服務

[[email protected] ~]# systemctl start nginx
[[email protected] ~]# nginx -t
[[email protected] ~]# nginx -s reload
[[email protected] ~]# systemctl enable nginx
[[email protected] ~]# systemctl start memcached
[[email protected] ~]# systemctl enable memcached
[[email protected] ~]# systemctl start php70-php-fpm.service
[[email protected] ~]# systemctl enable php70-php-fpm.service

應該沒了