Home php教程 php手册 PHP 该怎样利用PHP-FPM配置Nginx

PHP 该怎样利用PHP-FPM配置Nginx

Jun 13, 2016 am 09:46 AM
php-fpm use

Nginx读作“Engine-X”,是一个web服务器和反向代理服务器。Nginx因为它在同时处理大量请求资源时的速度和能力以及资源最佳利用而家喻户晓。


PHP-FPM指的是“PHP FastCGI进程管理器”。CGI是外部应用程序(CGI程序)与Web服务器之间的接口标准,是在CGI程序和Web服务器之间传递信息的规程。它监听一个端口就像web服务器本身,并通过PHP和web服务器之间的请求。(PS:T不错的PHP Q扣峮:276167802,验证:csl)


与Nginx相比,Apache在处理大量的请求时是相对缓慢的。本教程提供了关于如何安装和配置PHP-FPM Nginx的说明,这将帮助您在Nginx上执行PHP程序。


1。安装Nginx


你可以选择从源代码安装Nginx,也可以使用带有发行版的管理工具包。


这里我们只介绍使用管理工具包安装。


例如,在Ubuntu上可以使用apt-get安装nginx如下所示:


$ sudo apt-get install nginx


启动nginx服务器,如下所示:


$ sudo service nginx start


然后打开http://localhost,看到Nginx的欢迎界面就说明我们安装成功了。



2。安装PHP5-FPM


接下来使用管理工具包安装PHP5-FPM。


例如,在Ubuntu中可以使用apt-get安装php5-fpm。如下所示:


$ sudo apt-get install php5-fpm



3。添加PHP的配置到Nginx


接下来,找到/ etc / nginx / sites-available /default 文件,并添加以下行:


$ sudo vi /etc/nginx/sites-available/default


server {


 listen   80;


 root /usr/share/nginx/www;


 index index.php index.html index.htm;


 server_name example.com;


 location / {


   try_files $uri $uri/ /index.html;


 }


 error_page 404 /404.html;


 error_page 500 502 503 504 /50x.html;


 location = /50x.html {


   root /usr/share/nginx/www;


 }


 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000


 location ~ \.php$ {


   try_files $uri =404;


   fastcgi_pass unix:/var/run/php5-fpm.sock;


   fastcgi_index index.php;


   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


   include fastcgi_params;


 }


}
Copy after login



4。在PHP5-FPM www.conf设置监听参数


接下来,我们需要对 php-FRPM 配置做以下更改。


默认情况下,你在www.conf文件中会看到如下的监听入口:


$ sudo vi /etc/php5/fpm/pool.d/www.conf


listen = 127.0.0.1:9000


将上面的监听替换成下面的,其他原封不动:


$ sudo vi /etc/php5/fpm/pool.d/www.conf


listen = /var/run/php5-fpm.sock




5。重启Nginx和PHP5-FPM


重启php5-fpm和nginx。如下所示:


$ sudo service nginx restart



$ sudo service php5-fpm restart


然后在 Nginx 根目录下创建 index.php 文件,并运行测试:


$ sudo vi /usr/share/nginx/www


<?php


 phpinfo( );


?>
Copy after login


最后,打开浏览器,输入http://localhost/index.php即可显示PHP的相关信息。
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use php-fpm for high-performance tuning How to use php-fpm for high-performance tuning Jul 08, 2023 am 11:30 AM

How to use php-fpm for high-performance tuning PHP is a very popular server-side scripting language that is widely used to develop web applications and dynamic websites. However, as traffic increases, the performance of your PHP application may suffer. In order to solve this problem, we can use php-fpm (FastCGIProcessManager) for high-performance tuning. This article will introduce how to use php-fpm to improve the performance of PHP applications and provide code examples. one,

How to use GitLab for project document management How to use GitLab for project document management Oct 20, 2023 am 10:40 AM

How to use GitLab for project document management 1. Background introduction In the software development process, project documents are very important information. They can not only help the development team understand the needs and design of the project, but also provide reference to the testing team and customers. In order to facilitate version control and team collaboration of project documents, we can use GitLab for project document management. GitLab is a version control system based on Git. In addition to supporting code management, it can also manage project documents. 2. GitLab environment setup First, I

How to use PHP-FPM optimization to improve the performance of PrestaShop applications How to use PHP-FPM optimization to improve the performance of PrestaShop applications Oct 05, 2023 pm 12:33 PM

How to use PHP-FPM optimization to improve the performance of PrestaShop applications. With the rapid development of the e-commerce industry, PrestaShop has become the e-commerce platform chosen by many merchants. However, as the size of the store increases and the number of visits increases, the PrestaShop application may encounter performance bottlenecks. In order to improve the performance of the PrestaShop application, a common method is to use PHP-FPM to optimize and improve the application's processing capabilities. PHP-FPM (FastCGI

How to improve the performance of your WooCommerce application using PHP-FPM optimization How to improve the performance of your WooCommerce application using PHP-FPM optimization Oct 05, 2023 am 08:24 AM

How to Improve the Performance of WooCommerce Applications Using PHP-FPM Optimization Overview WooCommerce is a very popular e-commerce plugin for creating and managing online stores on WordPress websites. However, as your store grows and traffic increases, WooCommerce apps can become slow and unstable. To solve this problem, we can use PHP-FPM to optimize and improve the performance of WooCommerce applications. What is PHP-FP

Use php-fpm connection pool to improve database access performance Use php-fpm connection pool to improve database access performance Jul 07, 2023 am 09:24 AM

Overview of using php-fpm connection pool to improve database access performance: In web development, database access is one of the most frequent and time-consuming operations. The traditional method is to create a new database connection for each database operation and then close the connection after use. This method will cause frequent establishment and closing of database connections, increasing system overhead. In order to solve this problem, you can use php-fpm connection pool technology to improve database access performance. Principle of connection pool: Connection pool is a caching technology that combines a certain number of databases

Detailed explanation of php-fpm tuning method Detailed explanation of php-fpm tuning method Jul 08, 2023 pm 04:31 PM

PHP-FPM is a commonly used PHP process manager used to provide better PHP performance and stability. However, in a high-load environment, the default configuration of PHP-FPM may not meet the needs, so we need to tune it. This article will introduce the tuning method of PHP-FPM in detail and give some code examples. 1. Increase the number of processes. By default, PHP-FPM only starts a small number of processes to handle requests. In a high-load environment, we can improve the concurrency of PHP-FPM by increasing the number of processes

How to use PHP-FPM optimization to improve the performance of Phalcon applications How to use PHP-FPM optimization to improve the performance of Phalcon applications Oct 05, 2023 pm 01:54 PM

How to use PHP-FPM to optimize and improve the performance of Phalcon applications. Introduction: Phalcon is a high-performance PHP framework. Combining with PHP-FPM can further improve the performance of applications. This article will introduce how to use PHP-FPM to optimize the performance of Phalcon applications and provide specific code examples. 1. What is PHP-FPMPHP-FPM (PHPFastCGIProcessManager) is a PHP process independent of the web server

What is php-fpm? How to optimize to improve performance? What is php-fpm? How to optimize to improve performance? May 13, 2022 pm 07:56 PM

What is php-fpm? The following article will take you to understand php-fpm and introduce what we need to optimize when optimizing php-fpm. I hope it will be helpful to everyone!

See all articles