我是多余的 發表於 2020-7-17 06:41:00

ubuntu系统下安装php7.4

<p></p><div class="toc"><div class="toc-container-header">目录</div><ul><li>一.下载/更新php源</li><li>二.安装php7.4</li><li>三.修改配置<ul><li>3.1 修改<code>www.conf </code>文件</li></ul></li><li>四.配置域名</li><li>五.nginx的配置文件<ul><li>5.1 sock方式和nginx配合工作</li><li>5.2监听9000端口和nginx配合工作(推荐)</li></ul></li></ul></div><p></p>
<p>视频地址</p>
<p>原文地址</p>
<h2 id="一下载更新php源">一.下载/更新php源</h2>
<ol>
<li>
<p>打开下载网址</p>
<p> https://launchpad.net/~ondrej/+archive/ubuntu/php</p>
</li>
<li>
<p>先安装一下这个命令 <code>add-apt-repository</code></p>
<p>apt-get install software-properties-common</p>
</li>
<li>
<p>添加第三方源:</p>
<p>add-apt-repository ppa:ondrej/php</p>
</li>
<li>
<p>更新本地源</p>
<p>apt-get update</p>
</li>
</ol>
<h2 id="二安装php74">二.安装php7.4</h2>
<ol>
<li>
<p>安装</p>
<p>apt-get install php7.4 php7.4-fpm php7.4-mysql php7.4-gd php7.4-mbstring<br>
选择6. Asia<br>
选择70. Shanghai</p>
</li>
<li>
<p>启动php</p>
<p>service php7.4-fpm start #启动fpm</p>
</li>
<li>
<p>查看进程</p>
<pre><code class="language-bash">root@7c609eaf61d3:/etc/init.d# ps aux|grep php

root   118640.00.0 342724 10104 ?      Ss   07:05   0:00 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)

www-data 118650.00.0 3450209672 ?      S    07:05   0:00 php-fpm: pool www

www-data 118660.00.0 3450209672 ?      S    07:05   0:00 php-fpm: pool www

root   118680.00.0114641004 pts/1    S+   07:06   0:00 grep --color=auto php   
</code></pre>
</li>
<li>
<p>查看版本</p>
<pre><code class="language-bash">root@7c609eaf61d3:/etc/init.d# php -v #查看进程
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
</code></pre>
</li>
</ol>
<p>安装php主要的就三个<br>
phpcli #命令行<br>
php7.4-fpm #和nginx配合的多进程管理 多数使用这个<br>
module #和apache配合的</p>
<ol start="5">
<li>
<p>查看监听的端口</p>
<p>安装net-tools</p>
<p>可以用altupn命令查看监听的端口</p>
<pre><code class="language-bash">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
</code></pre>
<pre><code> 以上可以看到9000端口没有被监听,只监听了80端口
</code></pre>
<p>fpm监听有两种方式</p>
</li>
</ol>
<ul>
<li>a.监听端口,一般为9000端口</li>
<li>b.监听socket</li>
</ul>
<h2 id="三修改配置">三.修改配置</h2>
<h3 id="31-修改wwwconf-文件">3.1 修改<code>www.conf </code>文件</h3>
<p>vim /etc/php/7.4/fpm/pool.d/www.conf<br>
/listen = #可以找到监听方式 listen = /run/php/php7.4-fpm.sock</p>
<p><img src="https://img2020.cnblogs.com/blog/1441611/202007/1441611-20200717072026884-959370215.png" alt="" loading="lazy"></p>
<p>说明默认使用sock方式配合nginx方式工作</p>
<p>修改以下几处配置</p>
<p>1.打开在控制台显示php的错误</p>
<p><code>;php_flag = off</code> 改为<code>php_flag = on</code></p>
<p><code>;php_admin_flag = on</code> 改为 <code>php_admin_flag = on</code></p>
<p>2.打开日志</p>
<p><code>;access.log = log/$pool.access.log</code> 改为 <code>access.log = log/$pool.access.log</code></p>
<p>打开日志后,需要新建日志文件<code>/usr/log/www.access.log</code>,</p>
<p><code>/var/log/php7.4-fpm.log</code>文件里</p>
<p>mkdir -p /usr/log</p>
<p>vim /usr/log/www.access.log</p>
<p>保存并退出</p>
<p>如果没有这个文件,php会启动不了,不报错,错误日志会写入日志文件,</p>
<p><code>cat /etc/php/7.4/fpm/php-fpm.conf</code>里可以查到php错误日志会写会</p>
<p><code>error_log = /var/log/php7.4-fpm.log</code></p>
<h2 id="四配置域名">四.配置域名</h2>
<p><code>vim /etc/hosts </code></p>
<p><code>127.0.0.1        phptest.haimait.hm</code></p>
<h2 id="五nginx的配置文件">五.nginx的配置文件</h2>
<h3 id="51-sock方式和nginx配合工作">5.1 sock方式和nginx配合工作</h3>
<ol>
<li>
<p>修改php监听方式</p>
<p><code>vim /etc/php/7.4/fpm/pool.d/www.conf </code></p>
<p>这里我们使用监听<code>sock</code>的方式配合<code>nginx</code>工作</p>
<p><code>listen = /run/php/php7.4-fpm.sock</code></p>
</li>
<li>
<p>重启php</p>
<p><code>service php7.4-fpm reload</code></p>
</li>
<li>
<p>修改nginx配置文件</p>
<p><code>vim /etc/nginx/conf.d/phptest.haimait.hm.conf</code></p>
<pre><code class="language-bash">server {
    listen       80;
    server_namephptest.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 / {
      indexindex.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_pass127.0.0.1:9000;
      fastcgi_indexindex.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #�user root
      #fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
      include      fastcgi_params;
    }
}
</code></pre>
<p>保存退出后</p>
</li>
<li>
<p>重启nginx</p>
<pre><code class="language-bash">root@7c609eaf61d3:/etc/nginx/conf.d# service nginx restart
* Restarting nginx nginx
</code></pre>
</li>
<li>
<p>curl测试</p>
</li>
</ol>
<p>curl http://127.0.0.1/index.php 测试成功</p>
<h3 id="52监听9000端口和nginx配合工作推荐">5.2监听9000端口和nginx配合工作(推荐)</h3>
<ol>
<li>
<p>修改php监听方式</p>
<p><code>vim /etc/php/7.4/fpm/pool.d/www.conf </code></p>
<p>这里我们改为使用监听9000端口的方式配合nginx</p>
<p><code>listen = /run/php/php7.4-fpm.sock</code> 改为<code>listen = 127.0.0.1</code></p>
<p>重启php</p>
</li>
<li>
<p><code>service php7.4-fpm reload</code></p>
</li>
<li>
<p>修改nginx配置文件</p>
<p><code>vim /etc/nginx/conf.d/phptest.haimait.hm.conf</code></p>
</li>
</ol>
<pre><code class="language-bash">server {
    listen       80;
    server_namephptest.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 / {
      indexindex.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_pass127.0.0.1:9000;
      fastcgi_indexindex.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #�user root
      #fastcgi_paramSCRIPT_FILENAME/scripts$fastcgi_script_name;
      include      fastcgi_params;
    }
}
</code></pre>
<p>保存退出后</p>
<ol start="4">
<li>重启nginx</li>
</ol>
<pre><code>root@7c609eaf61d3:/etc/nginx/conf.d# service nginx restart
* Restarting nginx nginx
</code></pre>
<ol start="5">
<li>
<p>curl测试</p>
<p>curl http://127.0.0.1/index.php 测试成功</p>
</li>
</ol>


</div>
<div id="MySignature" role="contentinfo">
   
http://www.cnblogs.com/haima/<br><br>
来源:https://www.cnblogs.com/haima/p/13326981.html
頁: [1]
查看完整版本: ubuntu系统下安装php7.4