====== PHP and Apache on Windows ======
===== Install php, apache on windows =====
==== prepare environment for installing ====
prepare environment for running PHP if you only download package which only contain PHP command lines, not PHP package installer. You need to install **Visual C++ Redistributable for Visual Studio**(one of versions 2010,2012,2013,2015) from https://www.microsoft.com/en-us/download/details.aspx?id=49984
And you must use the same version visuall studio for building PHP and Apache(Because you run PHP as PHP-apache module which is built from PHP):
* vs2008(VC9)
* vs2010(VC10)
* vs2012(VC11)
* vs2013
* vs2015
==== Basic Steps to install ====
(PHP 5.6 and Apache 2.4 compiled with VC11)
- Install Visual C++ Redistributable for Visual Studio 2012(VC11) http://www.microsoft.com/en-us/download/details.aspx?id=30679#
- Install PHP package for **thread safe** (thread safe version **contain apache2 module**) with extra options
- Install Apache version base on **apache2 module** which contain in PHP package from http://www.apachelounge.com/download/
apache_2.2.14-win32-x86-no_ssl.msi
Network Domain: home-vn.com.vn
- Test apache by go to link http://192.168.1.3/ => output:
=> It works!
- Change configure of httpd.conf for calling PHP as module
AddType application/x-httpd-php .php
DirectoryIndex index.php index.htm index.html
PHPIniDir "C:/Program Files/PHP/"
LoadModule php5_module "C:/Program Files/PHP/php5apache2_2.dll"
- Change config of php.ini for loading modules which connecting to MySQL server(**must change extension_dir**):
extension_dir = "C:\Program Files (x86)\php-5.4.40\ext"
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
- Create phpinfo.php for checking modules which loaded by PHP:
And check by go to http://192.168.1.3/phpinfo.php
- Modify httpd.conf to enable mod rewrite:
LoadModule rewrite_module modules/mod_rewrite.so
==== Install Apache from binary directory ====
- Step1: Download Apache binary from http://www.apachelounge.com/download/(Base on OS 64bits or 32bits)
- Step2: Extract download file to drive C on windows. For example:c:\Apache24
- Step3: Change **ServerRoot** config in **httpd.conf** If you extract Apache binary to another directory:
ServerRoot "c:/Apache24"
- Step4: Install httpd as an service:
httpd.exe -k install
After install, you can check service name in services.msc and see it. And to uninstall
httpd.exe -k uninstall
- Step5: Run to test httpd:
httpd.exe
==== Config virtual host on Apache ====
- Step1: Edit httpd.conf to add new config file for virtual host:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Include conf/vhosts/*.conf
- Step2: create file **conf/vhosts/home.conf** to include config other virtual hosts
DocumentRoot "E:/web/dacsan-opencart"
ServerName dacsan.babies.vn
DirectoryIndex index.php index.html index.htm
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
SetEnv APPLICATION_ENV development
ErrorLog "logs/dacsan-opencart-error.log"
CustomLog "logs/dacsan-opencart-access.log" common
DocumentRoot "E:/web/baotam"
ServerName baotam.vn
DirectoryIndex index.php index.html index.htm
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Deny,Allow
Allow from all
SetEnv APPLICATION_ENV development
ErrorLog "logs/baotam-error.log"
CustomLog "logs/baotam-access.log" common
==== Some errors and fix ====
- Error 1:[authz_core:error] client denied by server configuration
=> Fix follow tutorial in link: http://httpd.apache.org/docs/2.4/upgrading.html#access.In this example, to config all requests are allowed:
* 2.2 configuration:
Order allow,deny
Allow from all
* 2.4 configuration:
Require all granted
- Error2:Can't load php_curl.dll when config loading it in php.ini(in PHP5.6 64bits on windows 7) => copy 3 files: **libssh2.dll, ssleay32.dll, libeay32.dll** to directory **c:\windows\system32**
===== Install XAMPP =====
refer: https://www.apachefriends.org/index.html