日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

ubuntu系統(tǒng)下安裝php7.4

 精品唯居 2022-06-14 發(fā)布于北京

視頻地址

原文地址

一.下載/更新php源

  1. 打開下載網(wǎng)址

    https:///~ondrej/+archive/ubuntu/php

  2. 先安裝一下這個命令 add-apt-repository

    apt-get install software-properties-common

  3. 添加第三方源:

    add-apt-repository ppa:ondrej/php

  4. 更新本地源

    apt-get update

二.安裝php7.4

  1. 安裝

    apt-get install php7.4 php7.4-fpm php7.4-mysql php7.4-gd php7.4-mbstring
    選擇6. Asia
    選擇70. Shanghai

  2. 啟動php

    service php7.4-fpm start #啟動fpm

  3. 查看進(jìn)程

    root@7c609eaf61d3:/etc/init.d# ps aux|grep php 
    
    root     11864  0.0  0.0 342724 10104 ?        Ss   07:05   0:00 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
    
    www-data 11865  0.0  0.0 345020  9672 ?        S    07:05   0:00 php-fpm: pool www
    
    www-data 11866  0.0  0.0 345020  9672 ?        S    07:05   0:00 php-fpm: pool www
    
    root     11868  0.0  0.0  11464  1004 pts/1    S+   07:06   0:00 grep --color=auto php
  4. 查看版本

    root@7c609eaf61d3:/etc/init.d# php -v #查看進(jìn)程
    PHP 7.4.8 (cli) (built: Jul 13 2020 16:45:47) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.8, Copyright (c), by Zend Technologies

安裝php主要的就三個
phpcli #命令行
php7.4-fpm #和nginx配合的多進(jìn)程管理 多數(shù)使用這個
module #和apache配合的

  1. 查看監(jiān)聽的端口

    安裝net-tools

    可以用altupn命令查看監(jiān)聽的端口

    apt-get install net-tools
    root@7c609eaf61d3:/etc/init.d# netstat -altupn|grep 9000
    root@7c609eaf61d3:/etc/init.d# netstat -altupn|grep 80  
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      23/nginx: master pr 
    tcp        0      0 172.17.0.3:47020        124.200.113.110:80      TIME_WAIT   -                   
    tcp6       0      0 :::80                   :::*                    LISTEN      23/nginx: master pr
     以上可以看到9000端口沒有被監(jiān)聽,只監(jiān)聽了80端口

    fpm監(jiān)聽有兩種方式

  • a.監(jiān)聽端口,一般為9000端口

  • b.監(jiān)聽socket

三.修改配置

3.1 修改www.conf 文件

vim /etc/php/7.4/fpm/pool.d/www.conf
/listen = #可以找到監(jiān)聽方式 listen = /run/php/php7.4-fpm.sock

說明默認(rèn)使用sock方式配合nginx方式工作

修改以下幾處配置

1.打開在控制臺顯示php的錯誤

;php_flag[display_errors] = off 改為 php_flag[display_errors] = on

;php_admin_flag[log_errors] = on 改為 php_admin_flag[log_errors] = on

2.打開日志

;access.log = log/$pool.access.log 改為 access.log = log/$pool.access.log

打開日志后,需要新建日志文件/usr/log/www.access.log,

/var/log/php7.4-fpm.log文件里

mkdir -p /usr/log

vim /usr/log/www.access.log

保存并退出

如果沒有這個文件,php會啟動不了,不報錯,錯誤日志會寫入日志文件,

cat /etc/php/7.4/fpm/php-fpm.conf里可以查到php錯誤日志會寫會

error_log = /var/log/php7.4-fpm.log

四.配置域名

vim /etc/hosts

127.0.0.1 phptest.haimait.hm

五.nginx的配置文件

5.1 sock方式和nginx配合工作

  1. 修改php監(jiān)聽方式

    vim /etc/php/7.4/fpm/pool.d/www.conf

    這里我們使用監(jiān)聽sock的方式配合nginx工作

    listen = /run/php/php7.4-fpm.sock

  2. 重啟php

    service php7.4-fpm reload

  3. 修改nginx配置文件

    vim /etc/nginx/conf.d/phptest.haimait.hm.conf

    server {
        listen       80;
        server_name  phptest.haimait.hm;
        access_log  /var/log/nginx/phptest.haimait.hm.access.log;
        error_log   /var/log/nginx/phptest.haimait.hm.error.log;
        root   /wwwroot/html/phptest;
        location / {
            index  index.php index.html index.htm;
        }
        location ~ \.php$ {
            root           /wwwroot/html/phptest;
            #fastcgi_pass這里的路徑要的/etc/php/7.4/fpm/pool.d/www.conf 里listen = 里的配置的一致
            fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
            #fastcgi_pass  127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #?user root
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

    保存退出后

  4. 重啟nginx

    root@7c609eaf61d3:/etc/nginx/conf.d# service nginx restart
    * Restarting nginx nginx
  5. curl測試

curl http://127.0.0.1/index.php 測試成功

5.2監(jiān)聽9000端口和nginx配合工作(推薦)

  1. 修改php監(jiān)聽方式

    vim /etc/php/7.4/fpm/pool.d/www.conf

    這里我們改為使用監(jiān)聽9000端口的方式配合nginx

    listen = /run/php/php7.4-fpm.sock 改為listen = 127.0.0.1

    重啟php

  2. service php7.4-fpm reload

  3. 修改nginx配置文件

    vim /etc/nginx/conf.d/phptest.haimait.hm.conf

server {
    listen       80;
    server_name  phptest.haimait.hm;
    access_log  /var/log/nginx/phptest.haimait.hm.access.log;
    error_log   /var/log/nginx/phptest.haimait.hm.error.log;
    root   /wwwroot/html/phptest;
    location / {
        index  index.php index.html index.htm;
    }
    location ~ \.php$ {
        root           /wwwroot/html/phptest;
        #fastcgi_pass這里的路徑要的/etc/php/7.4/fpm/pool.d/www.conf 里listen = 里的配置的一致
        #fastcgi_pass   unix:/run/php/php7.4-fpm.sock;
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #?user root
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }
}

保存退出后

  1. 重啟nginx

root@7c609eaf61d3:/etc/nginx/conf.d# service nginx restart
* Restarting nginx nginx
  1. curl測試

    curl http://127.0.0.1/index.php 測試成功 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多