Home Backend Development PHP Tutorial Nginx环境停Php安装

Nginx环境停Php安装

Jun 13, 2016 am 10:30 AM
enable fastcgi fpm nginx php

Nginx环境下Php安装

其实很简单的事,我每次安装貌似都会走弯路,所以还是记下来吧

?

CentOS 5.5 Nginx 1.0.5Php 5.5.8
Copy after login

?

1.先安装Nginx

#tar -zxvf nginx-1.0.5.tar.gz#cd nginx-1.0.5#./configure#make#make install
Copy after login

?

2.安装php,采用fastcgi的安装方式,顺道查了下fastcgi的优势和劣势,供参考(摘抄自网络)

【注:我已经安装好了Mysql,因为没有太多特别的地方,所以就不做说明】

优势

  1. PHP脚本运行速度更快(3到30倍)。PHP解释程序被载入内存而不用每次需要时从存储器读取,极大的提升了依靠脚本运行的站点的性能。
  2. 需要使用更少的系统资源。由于服务器不用每次需要时都载入PHP解释程序,你可以将站点的传输速度提升很高而不必增加cpu负担。
  3. 不需要对现有的代码作任何改变。现有的一切都适用于PHP的FastCGI

潜在问题

  1. 对所有的子目录(/home/USERNAME/public_html/php.ini)你只有一个可用的php.ini文件。 这是优化网站代码所必需的。如果你需要多个php.ini文件以适应不同的脚本需要,你可以在任何子目录禁用PHP的快速CGI,而其余的地方则继续有 效。如果你需要这样做请联系support。
  2. 你对PHP环境做的任何升级(如php.ini文件的改变)都有几分钟的延迟。这是因为为了更快的速度 你的php.ini文件已经被载入内存,而不是每次需要时再从存储器重新读取。

我在安装的时候并没有去考虑php.ini的问题,只要考虑好php-fpm.conf就可以了

php的安装的确是稍微不太一样,简单的说,就是作为一个单独的服务启动了

#tar -zxvf php-5.3.8.tar.gz#cd php-5.3.8// 编译的时候一定要加入参数--enable-fpm#./configure --prefix=/usr/local/php --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --with-mysql=/usr/local/mysql/  --with-pdo-mysql=/usr/local/mysql --enable-soap --enable-sockets --enable-zip --enable-xml --with-curl --enable-mbregex --enable-sysvsem --enable-mbstring --with-mcrypt --enable-fpm#make#make install
Copy after login

?

3.配置php和nginx

1.使用php-fpm启动php

#cd /usr/local/php/etc/#cp php-fpm.conf.default php-fpm.conf#vi php-fpm.conf// 找到如下几行,确保如下几行前没有";"pid = run/php-fpm.piderror_log = log/php-fpm.loglisten = 127.0.0.1:9000pm.max_children = 50pm.start_servers = 20pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 500
Copy after login

?php5.5.8版本提供了php-fpm的管理工具,可以很方便的start,stop,restart

// 只是我个人习惯把php相关命令丢在这#cd /usr/local/php/sbin/// 在安装文件中复制该文件#cp /downloads/php-5.3.8/sapi/fpm/init.d.php-fpm ./#chmod 755 init.d.php-fpm// start | stop | restart#./init.d.php-fpm start
Copy after login

?

2.nginx的配置?

#vi /usr/local/nginx/conf/nginx.conf// 去掉之前的"#"// SCRIPT_FILENAME如果填错,则显示空白页面location ~ \.php$ {            root           html;            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            include        fastcgi_params;        }#vi /usr/local/nginx/conf/fastcgi_params// 注释掉该行,暂时还不知道为啥#fastcgi_param  REDIRECT_STATUS    200;
Copy after login

?启动nginx

#cd /usr/local/nginx/sbin/// 测试配置文件是否正确#./nginx -t// 启动#./nginx // 重新载入#./nginx -s reload// 重启#./nginx -s reopen
Copy after login
?

?

?

?

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

PHP's Purpose: Building Dynamic Websites PHP's Purpose: Building Dynamic Websites Apr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP: Handling Databases and Server-Side Logic PHP: Handling Databases and Server-Side Logic Apr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

Why Use PHP? Advantages and Benefits Explained Why Use PHP? Advantages and Benefits Explained Apr 16, 2025 am 12:16 AM

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

How to configure nginx in Windows How to configure nginx in Windows Apr 14, 2025 pm 12:57 PM

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

How to check the name of the docker container How to check the name of the docker container Apr 15, 2025 pm 12:21 PM

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

See all articles