Home >Backend Development >PHP Tutorial >Learn PHP configuration in depth_PHP tutorial
After a long period of development of PHP, many users know PHP very well. Here I will express my personal understanding and discuss it with everyone. Below we will introduce the steps of PHP configuration. Although you can download the source code of PHP, like Apache 2, it is best to use the binary distribution package directly.
PHP Configuration
Now comes the most interesting part: perfectly matching Apache and PHP. First, please copy all DLL files in the C:PhpDlls directory to the Windows System directory (%windir%System). Next, look for the section containing a large number of AddType commands in the Apache configuration file (Httpd.conf), and add the following line yourself:
<ol class="dp-xml"><li class="alt"><span><span>AddType application/x-httpd-php .php </span></span></li></ol>
Copy C:PhpPhp.ini-recommended to the Windows directory ( %windir%), rename it to Php.ini and open it with a text editor. Edit the three lines that set doc_root, extension_dir, and session.save_path to be consistent with what is shown below. Be sure to replace InstallDir with the name of your Apache 2 installation directory.
<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>
Both forward and backslashes are allowed in session.save_path. The PHP configuration claims that these path parameters require a backslash at the end, but this is incorrect. This is not required in PHP 4.3. Also, if C:Temp does not exist, create it yourself.
The next step is to allow Apache to run PHP programs as modules, which requires you to take 2 steps. First, copy C:PhpPhp4ts.dll to the Windows system folder (%windir%System). Find the LoadModule section in Httpd.conf and add the following line yourself:
<ol class="dp-xml"><li class="alt"><span><span>LoadModule php4_module “c:/php/php4apache2.dll” </span></span></li></ol>
If you need to run a PHP program in CGI mode (using Php.exe) for some reason, please change the above Comment this line and add the following lines to 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>
Is everything done?
After saving the changes, you need to prove it yourself Two points can ensure that Apache 2/PHP 4 becomes a perfect pair: can Apache load normally, and can it process PHP pages correctly?
To know whether Apache can load normally, enter the following command in the command line window you have opened:
<ol class="dp-xml"><li class="alt"><span><span>apache–k start </span></span></li></ol>
In addition, if Apache is running, you can restart it with the following command:
<ol class="dp-xml"><li class="alt"><span><span>apache–k restart </span></span></li></ol>
The advantage of starting Apache from the command line is that if an error occurs, Apache will report it immediately. The most common problem you may encounter is that Apache may not be able to load Php4apache2.dll for some reason. If Apache reports this error, please follow the steps described above again to make sure everything is correct. To know if Apache can handle PHP pages correctly, use your text editor to create a simple PHP page, named Phptest.php, containing only the following line:
<ol class="dp-xml"><li class="alt"><span><span><? phpinfo(); ?> </span></span></li></ol>
Save the file Go to the main web server directory (C:InstallDirectoryApacheApache2Htdocs) and use a browser to access http://localhost/phptest.php. If everything is fine, you should see a web page with the PHP logo and a lot of settings and other information. To know whether PHP is currently running through CGI or inside Apache, you can check the environment variable orig_script_name. If PHP is run via CGI, the value of this variable is /Php/Php.exe. If Apache is running PHP scripts as modules, the value of this variable should be /Phptest.php.
Although installing Apache 2 and PHP on Windows is not an easy task, there is no need to cross the river by feeling for the stones. Through the instructions in this article, you should be able to quickly build the best and most cost-effective