您的位置 首页 php

Ubuntu linux 上的 Nginx 和 Php 安装

教程 – 在 Ubuntu Linux 上安装 Nginx

1.安装 Nginx 服务器和所需的包。

 apt-get updatebrapt-get install nginx  

2.在 Nginx 配置文件中添加以下行。

 brclient_max_body_size 32M;  

在我们的示例中,我们将 Nginx 的最大上传大小设置为 32 MB。

4.下面是我们配置后的文件。

 user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {      
worker_connections 768;
}
http {
client_max_body_size 32M;
        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        ssl_prefer_server_ciphers on;
        access_log /var/log/nginx/access.log;
       error_log /var/log/nginx/error.log;
        gzip on;
        include /etc/nginx/conf.d/*.conf;
       include /etc/nginx/sites-enabled/*;
}  

5.重新启动 Nginx 服务。

 service nginx restart  

已成功安装 Nginx 服务器。

教程 Nginx – 启用 PHP 支持

Nginx 需要外部程序来添加 PHP 支持。

1.安装 PHP 包。

 apt-get install php-fpm  

2.安装其他 PHP 模块。

 apt-get install php-mysql php-mbstring php-xml php-gd php-curl php-bcmath php-ldap mlocate  

3.查找系统上 PHP 配置文件的位置。

编辑名为:PHP的配置文件。Ini。

 updatedb
locate php.ini
vi /etc/php/7.4/fpm/php.ini  

您的PHP版本可能与我们的版本不同。

您的 PHP 配置文件位置可能与我们的不同。

4.启用并配置 PHP 配置文件的以下项目。

 max_execution_time = 300
memory_limit = 256M
post_max_size = 32M
upload_max_filesize = 32M
max_input_time = 300  

在我们的示例中,我们使用的是巴西的时区。

5.编辑默认网站的 Nginx 配置文件。

 vi /etc/nginx/sites-available/default  

为 Nginx 启用 PHP 支持。

这里是原始文件,在我们的配置之前。

 server {
listen 80 default_server;
r        listen [::]:80 default_server;
         root /var/www/html;
         index index.html index.htm index.nginx-debian.html;
         server_name _;
         location / {
                   try_files $uri $uri/ =404;br        }
  }  

下面是带有我们配置的新文件

 server {
          listen 80 default_server;
          listen [::]:80 default_server;
         root /var/www/html;
          index index.php index.html index.htm index.nginx-debian.html;
          server_name _;
          location / {
                   try_files $uri $uri/ =404;
            }
         location ~ .php$ {
           include snippets/fastcgi-php.conf;
           fastcgi_pass unix:/var/run/php/php-fpm.sock;
           }
  }  

6.验证您的 Nginx 配置文件是否没有错误。

 nginx -t  

下面是命令输出。

 nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful  

8.重新启动 PHP 服务。

 service php7.4-fpm restart  

9.重新启动 Nginx 服务。

 service nginx restart  

祝贺! 您已经完成了 Nginx 服务器上的 PHP 安装。

教程 Nginx – 测试 PHP 安装

1.创建 PHP 测试文件。

 vi /var/www/html/test.php  

这是文件内容。

 <?php
phpinfo();
?>  

2.打开浏览器并输入 Web 服务器 /test.php 的 IP 地址。

在我们的示例中,浏览器中输入了以下 URL:

将显示 PHP 测试页。

祝贺! PHP 安装成功完成。

文章来源:智云一二三科技

文章标题:Ubuntu linux 上的 Nginx 和 Php 安装

文章地址:https://www.zhihuclub.com/151148.shtml

关于作者: 智云科技

热门文章

网站地图