zoukankan      html  css  js  c++  java
  • 2020年ubuntu1804安装php7.3最新详细教程

    虽然很久没有写php了,但是php这个语言还是不能丢。php7发布以后运行速度有大幅的提升,改进也很快,php的开源项目也很多。所以在服务器安装一份,让自己随时能用。说不定哪天就用上了。

    一、准备php的第三方源

    因为ubuntu默认的php是7.2的版本,看很多大神介绍7.3比7.2有提高不少,所以考虑用php的第三方源
    (最新的7.4是2019年11月发布的,还在快速迭代,更新bug,暂时不考虑。)

    1. 第三方源ppa:ondrej/php 是一个比较知名的PHP源。
      作者Ondřej Surý 是 Debian PHP 软件源的官方维护者之一,所以说稳定性和安全性基本上不是问题。
    2. 用【ppa:ondrej/php】还是同时安装多个版本的php在同一台服务器,可以非常方便的切换版本,可以支持php5.6/7.1/7.2/7.3/7.4
    3. 先安装相关依赖包(以下都是以root用户进行操作)
    apt -y install software-properties-common apt-transport-https lsb-release ca-certificates
    #-y是省去提示yes/no时,输入y的麻烦
    
    1. 添加第三方源,会有个warning提示
    add-apt-repository ppa:ondrej/php 
    #WARNING: add-apt-repository is broken with non-UTF-8 locales
    #试了,这个命令 LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php,提示也一样
    apt update
    
    1. 安装php7.3和相关拓展
    apt install php7.3 php7.3-fpm php7.3-mysql php7.3-curl php7.3-gd php7.3-mbstring php7.3-xml php7.3-xmlrpc php7.3-zip php7.3-opcache php7.3-json  php7.3-pgsql
    #有点多,都是常用的
    apt instal php-redis php-mongodb 
    #这两个扩展没有针对7.3的,redis和mongodb现在使用都非常多
    
    1. 可根据需要安装的扩展
     apt-cache search php7.3
    

    二、配置PHP7.3

    1. php-fpm的启动和管理
      • 安装完Php7.3后,会自动启动php-fpm
      • /etc/init.d/php7.3-fpm start/stop/restart 可以启动、停止、重启php-fpm
      • 默认读取/ect/php/7.3/fpm/php-fpm.conf
    2. php的配置文件说明
      • 配置文件/etc/php/7.3/fpm/目录下
      • php-fpm.conf 是【global】
        • 中小应用这里修改的不多,如果需要深入定制可以参考以下文章
      • php-fpm线程池/etc/php/7.3/fpm/pool.d/www.conf
    pm = dynamic 如何控制子进程,选项有static和dynamic
    pm.max_children:静态方式下开启的php-fpm进程数量
    pm.max_requests:php-fpm子进程能处理的最大请求数
    pm.start_servers:动态方式下的起始php-fpm进程数量
    pm.min_spare_servers:动态方式下的最小php-fpm进程数
    pm.max_spare_servers:动态方式下的最大php-fpm进程数量
    区别:
    如果dm设置为 static,那么其实只有pm.max_children这个参数生效。系统会开启设置数量的php-fpm进程。
    如果dm设置为 dynamic,那么pm.max_children参数失效,后面3个参数生效。
    1G的内存
    pm = dynamic
    pm.start_servers = 6
    pm.min_spare_servers = 3
    pm.max_spare_servers = 20
    
    
         + [参考文档](https://www.cnblogs.com/jonsea/p/5522018.html),
           [php-fpm配置优化](https://blog.csdn.net/Derek_Yam/article/details/89474827),
           [优化2](https://www.cnblogs.com/52fhy/p/5051722.html),
           [参考3](https://www.php.cn/php-weizijiaocheng-391985.html)
    + pool.d/www.conf 是进程池的相关配置,是用tcp,还是用unix socket,可以参考这篇文章
         + [tcp Or unix](https://blog.csdn.net/qq624202120/article/details/60957634)
         + [参考2](https://www.cnblogs.com/mzhaox/p/11215113.html)[参考3](https://blog.csdn.net/lifushan123/article/details/45704471)
         + 改用TCP socket ,vim pool.d/www.conf ,修改listion = 127.0.0.1:9000
    + 默认启动的是unixsocket,/run/php/php7.3-fpm.sock
    
    1. 修改nginx的配置,新增一个phpdev.conf ,放在/etc/nginx/conf.d/phpdev.conf
    erver {
        listen       80;
        server_name  php.qumogu.com;
    
        #charset koi8-r;
        access_log  /var/log/nginx/phpdev.access.log  main;
    
        location / {
            root   /data/www/phpdev;
            index  index.html index.htm index.php;
        }
      
        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   /usr/share/nginx/html;
        }
    
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    
        #location ~ .php$ {
        #    proxy_pass   http://127.0.0.1;
        #}
    
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ .php$ {
            root           /data/www/phpdev;
            #fastcgi_pass   unix:/dev/shm/php-fpm.sock;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /.ht {
        #    deny  all;
        #}
    }
    

    在配置nginx的时候,一直报,no input file specified,无法正常显示php

    需要,指定root ,然后,参考

    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;  改为:
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    
    1. php-fpm的常用命令
    systemctl restart php7.3-fpm #重启
    systemctl start php7.3-fpm #启动
    systemctl stop php7.3-fpm #关闭
    systemctl status php7.3-fpm #检查状态
    #也可以用
    /etc/init.d/php7.3-fpm start/stop/restart
    
    1. 查看网络端口
    netstat -lnt | grep 9000
    netstat -lnt #查看所有端口占用
    
    1. 添加www-data用户合组
    useradd www-data
    groupadd www-data
    
  • 相关阅读:
    oracle 10g 免安装客户端在windows下配置
    sql2005 sa密码
    使用windows live writer 有感
    windows xp SNMP安装包提取
    汉化groove2007
    迁移SQL server 2005 Reporting Services到SQL server 2008 Reporting Services全程截图操作指南
    foxmail 6在使用中的问题
    AGPM客户端连接不上服务器解决一例
    SpringSource Tool Suite add CloudFoundry service
    Java 之 SWing
  • 原文地址:https://www.cnblogs.com/qumogu/p/12734694.html
Copyright © 2011-2022 走看看