Download PHP Thread Safe version with the same bitness with the Apache currently installed on your system x86 or x64 from http://windows.php.net.
After the download finished, extract it into your computer and rename the folder with "php", copy it into your Apache folder "C:\apache"
Create a new folder in D drive name it "MyWebs" we will set this as a new Document Root
In the "C:\apache\php" folder, find and rename "php.ini-production" to "php.ini"
Double click to open it and find the following line:
doc_root =
Add path to MyWebs folder we've just created:
doc_root = "d:\mywebs"
Find the next line:
; extension_dir = "ext"
Uncomment it and add path to the PHP extensions directory:
extension_dir = "c:\apache\php\ext"
By default PHP uses Windows temp to store session and upload data. We can move them to Apache directory.
Create a new folder in "C:\apache" name it "temp" inside the "temp" folder create 2 folders name them "upload" and "session" Now we got 2 new folders "C:\apache\temp\upload" and "C:\apache\temp\session"
Still in the PHP configuration file (php.ini) find the line below:
;upload_tmp_dir =
Uncomment it and add path to the upload folder:
upload_tmp_dir= "C:\apache\temp\upload"
And the next line:
;session.save_path = "/tmp"
Uncomment it and add path to the session folder:
session.save_path= "C:\apache\temp\session"
Save the PHP configuration.
Configuring Apache Server with PHP.
Open up Apache Configuration file, located at C:\apache\conf\httpd.conf
Find DocumentRoot and Directory
DocumentRoot "c:/Apache/htdocs"
<Directory "c:/Apache/htdocs">
Replace the path to the PHP doc_root we created earlier
DocumentRoot "d:/mywebs"
<Directory "d:/mywebs">
Find DirectoryIndex as follows:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
Add index.php to the line
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
At the end of the httpd.conf add the following lines:
ScriptAlias /php/ "C:/apache/php/"
AddType application/x-httpd-php .php .php5
Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC "C:/apache/php"PHPIniDir "C:/apache/php/"
LoadModule php7_module "C:/apache/php/php7apache2_4.dll"
If you are installing PHP 5+ replace the last line with:
LoadModule php5_module "C:/apache/php/php5apache2_4.dll"
Restart the Apache Server.
Testing PHP run as Apache module
Open up Notepad, copy and paste the code below:
<?php phpinfo(); ?>
Save the file into Apache document root "D:\MyWebs" as "phpinfo.php"
Open up browser, in the address bar type in "http://localhost/phpinfo.php" and Enter.
If everything went well, you should see something like the image above.
Here is a video on YouTube How to install PHP on Windows 10
No comments:
Post a Comment