深入学习PHP配置
PHP经过长时间的发展,很多用户都很了解PHP了,这里我发表一下个人理解,和大家讨论讨论。下面我们就介绍一下PHP配置的步骤。虽然可以下载PHP 的源码,但和Apache 2一样,最好直接使用二进制发行包。
PHP配置
现在来到了最有趣的部分:将Apache和PHP完美地配合起来。首先,请将C:PhpDlls目录中的所有DLL文件拷贝到Windows的 System目录(%windir%System)。接着,在Apache的配置文件(Httpd.conf)中查找包含了大量AddType命令那个小节,自己添加下面这一行:
<ol class="dp-xml"><li class="alt"><span><span>AddType application/x-httpd-php .php </span></span></li></ol>
将C:PhpPhp.ini-recommended拷贝到Windows目录(%windir%),把它重命名为Php.ini,并用文本编辑器打开它。编辑其中对doc_root、extension_dir和session.save_path进行设置的3行,使其和下面展示的一致,注意要把 InstallDir替换成你的Apache 2的安装目录的名称。
<ol class="dp-xml"> <li class="alt"><span><span class="attribute"><font color="#ff0000">doc_root</font></span><span> = c:apacheapache2htdocs </span></span></li> <li class=""><span> </span></li> <li class="alt"> <span></span><span class="attribute"><font color="#ff0000">extension_dir</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">c</font></span><span>:phpextensions </span> </li> <li class=""><span> </span></li> <li class="alt"> <span></span><span class="attribute"><font color="#ff0000">session.save_path</font></span><span> = </span><span class="attribute-value"><font color="#0000ff">c</font></span><span>:/temp </span> </li> </ol>
在session.save_path中使用正斜杠和反斜杠都是允许的。PHP配置声称这些路径参数需要在最后添加一个反斜杠,但这个说法是不正确的。在PHP 4.3中不需要这样做。另外,如果C:Temp不存在,请自己创建它。
下一步是允许Apache将PHP程序作为模块来运行,这要求你采取2个步骤。首先,将C:PhpPhp4ts.dll拷贝到Windows的系统文件夹(%windir%System)。在Httpd.conf中找到LoadModule小节,自己添加下面这一行:
<ol class="dp-xml"><li class="alt"><span><span>LoadModule php4_module “c:/php/php4apache2.dll” </span></span></li></ol>
如果你出于某种原因而需要在CGI模式中运行PHP程序(使用Php.exe),请将上面这一行变成注释,并在Httpd.conf中添加下面这些行:
<ol class="dp-xml"> <li class="alt"><span><span>ScriptAlias /php/ "c:/php/" </span></span></li> <li class=""><span> </span></li> <li class="alt"><span>Action application/x-httpd-php "/php/php.exe" </span></li> </ol>
一切都搞定了吗?
保存所做的更改后,你需要亲自去证明两点,才能确保Apache 2/PHP 4成为一对完美的搭档:Apache能正常加载吗,它能正确处理PHP页吗?
要知道Apache是否能够正常加载,在你已经打开的命令行窗口中输入以下命令:
<ol class="dp-xml"><li class="alt"><span><span>apache–k start </span></span></li></ol>
另外,如果Apache正在运行,可用以下命令重新启动它:
<ol class="dp-xml"><li class="alt"><span><span>apache–k restart </span></span></li></ol>
从命令行启动Apache的好处在于,如果出现一个错误,Apache会立即报告它。你可能遇到的最常见的问题在于,Apache可能由于某种原因而无法加载Php4apache2.dll。如果Apache报告了这个错误,请按前面所述的步骤重新操作一遍,确保一切都没有错误。要知道Apache是否能正确地处理PHP页,请用你的文本编辑器创建一个简单的PHP页,命名为Phptest.php,其中只包含下面这一行:
<ol class="dp-xml"><li class="alt"><span><span><? phpinfo(); ?> </span></span></li></ol>
将文件保存到主Web服务器目录(C:InstallDirectoryApacheApache2Htdocs),用浏览器访问http://localhost/phptest.php。如果一切正常,应该看到一个含有PHP徽标的网页,其中包含大量设置和其他信息。要知道PHP当前是通过CGI来运行,还是在Apache内部运行,可以检查一下环境变量orig_script_name。如果PHP通过CGI来运行,这个变量的值就是/Php/Php.exe。如果Apache将PHP 脚本作为模块来运行,该变量的值应该是/Phptest.php。
虽然在Windows上安装Apache 2和PHP并不是一件容易的事情,但也完全没必要采取摸着石头过河的做法。通过本文的说明,你应该可以快速搭建起这个史上最好的、成本最

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

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











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 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

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 and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

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 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 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.

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.
