Nginx环境下Php安装
其实很简单的事,我每次安装貌似都会走弯路,所以还是记下来吧
?
CentOS 5.5 Nginx 1.0.5Php 5.5.8
?
1.先安装Nginx
#tar -zxvf nginx-1.0.5.tar.gz#cd nginx-1.0.5#./configure#make#make install
?
2.安装php,采用fastcgi的安装方式,顺道查了下fastcgi的优势和劣势,供参考(摘抄自网络)
【注:我已经安装好了Mysql,因为没有太多特别的地方,所以就不做说明】
优势
- PHP脚本运行速度更快(3到30倍)。PHP解释程序被载入内存而不用每次需要时从存储器读取,极大的提升了依靠脚本运行的站点的性能。
- 需要使用更少的系统资源。由于服务器不用每次需要时都载入PHP解释程序,你可以将站点的传输速度提升很高而不必增加cpu负担。
- 不需要对现有的代码作任何改变。现有的一切都适用于PHP的FastCGI
潜在问题
- 对所有的子目录(/home/USERNAME/public_html/php.ini)你只有一个可用的php.ini文件。 这是优化网站代码所必需的。如果你需要多个php.ini文件以适应不同的脚本需要,你可以在任何子目录禁用PHP的快速CGI,而其余的地方则继续有 效。如果你需要这样做请联系support。
- 你对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
?
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
?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
?
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;
?启动nginx
#cd /usr/local/nginx/sbin/// 测试配置文件是否正确#./nginx -t// 启动#./nginx // 重新载入#./nginx -s reload// 重启#./nginx -s reopen?
?
?
?

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools