unbuntu下的php8和nginx编译安装,以及mysql安装

php8.1.1安装

ubuntu21.10:编译安装php8.1.1|爱尚资源教程网 (23jcw.net) 测试通过

sudo ln -s /usr/local/soft/php8/bin/php /usr/local/bin/php

Nginx1.20.1安装:

安装nginx之前需要安装如下依赖:

sudo apt-get install libpcre3 libpcre3-dev  
sudo apt-get install zlib1g-dev

nginx安装:

cd /usr/local/src
wget https://nginx.org/download/nginx-1.20.1.tar.gz
tar -zxvf nginx-1.20.1.tar.gz
cd nginx-1.20.1
./configure
make && make install

配置 Nginx 使其支持 PHP 应用:

vim /usr/local/nginx/conf/nginx.conf

修改默认的 location 块,使其支持 .php 文件:

location / {
    root   html;
    index  index.php index.html index.htm;
}

下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改为下面的内容:

location ~* \.php$ {
    fastcgi_index   index.php;
    fastcgi_pass    127.0.0.1:9000;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}

启动nginx:

sudo /usr/local/nginx/sbin/nginx

停止nginx:

sudo /usr/local/nginx/sbin/nginx -s stop

加载配置文件:

sudo /usr/local/nginx/sbin/nginx -s reload

创建测试文件

rm /usr/local/nginx/html/index.html
echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php

打开浏览器,访问 http://localhost,将会显示 phpinfo() 。

添加虚拟主机

添加server,如果是本地要访问局域网其他主机,则在host文件中添加映射,比如:192.168.2.166 bfh.com

 server {
        listen       80;
        server_name  bfh.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   /home/cx/bfh.com/public;
            index  index.php index.html index.htm;
        }

        #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;
        }

        # 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 /home/cx/bfh.com/public;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            fastcgi_param  SCRIPT_NAME       $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;
        #}
    }

mysql安装

mysql安装:sudo apt install mysql-server  

service mysql status

netstat -an | grep 3306

 

参考链接:

php官方源码:GitHub - php/php-src at PHP-8.1.1

官方文档nginx安装: https://www.nginx.com/resources/wiki/start/topics/tutorials/install/

安装nginx之前可能需要的一些依赖包,详见:

https://blog.csdn.net/jiayouwa_jiayou/article/details/125760333

https://zhuanlan.zhihu.com/p/539284516

根据php官方文档来配置nginx:https://www.php.net/manual/zh/install.unix.nginx.php

Ubuntu编译安装php8,7和Nginx - 知乎 (zhihu.com)

 PHP7正式版测试,性能惊艳! - ThinkPHP框架

linux - ubuntu20 安装和配置mysql8.0.23 - 个人文章 - SegmentFault 思否

How to install and configure PHP | Ubuntu

php ./configure配置翻译解析_脚本语言_菜鸟的博客-CSDN博客

PHP: 核心配置选项列表 - Manual

The GNU configure and build system - Table of Contents

Composer (getcomposer.org)

posted @ 2022-09-26 23:18  蓝天,白云  阅读(403)  评论(0编辑  收藏  举报