Computer Programming web Web programming Tips



Installation and Configuration Apache and PHP for Windows

By Sergey Skudaev


Here you will learn about Apache installation and configuration, PHP installation and configuration, MySQL installation, how to Configure Apache Server for PHP, how to edit httpd.conf file, how to edit php.ini file.

Download Apache web server for Windows from https://www.apachelounge.com/download/

Download and install C++ Redistributable Visual Studio 2017 https://aka.ms/vs/15/release/VC_redist.x64.exe

Download PHP for Windows from  www.php.net

The tutorial for MySQL installation for Windows

All software are free and we take it for granted, but some one did hard work to develop it.

When you will install Apache Web Server, by default it will be installed in "C:/Program Files" directory. During installation you have to change path to install Apache in "C:\Apache" or in "C:\Apache2" directory.

Download PHP from http://windows.php.net/download Use the Thread Safe zip file.

To install PHP unzip PHP distributable zip file in "C:\php" directory.

Configure Apache httpd.conf file, which is located in conf directory.
On my PC it is "C:\Apache24\conf\httpd.conf"

Find the text:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

and set it to your extension directory. On my PC it is:

extension_dir = "C:\php\ext"

Rename php.ini.dist file to php.ini and copy it to Windows\system or WINT\system32 directory

For Apache2 and PHP7 add to httpd.conf file the following lines:

AddHandler application/x-httpd-php .php
AddType application/x-httpd-php .php .html
LoadModule php7_module "c:/php7/php7apache2_4.dll"
PHPIniDir "C:/php"

Restarted computer and everything was working!

Edit php.ini.dist file in C:\php directory

Find the line:

; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"

and set it to your extension directory. On my PC it is:

extension_dir = "C:\php\ext"

Find the line:

;upload_tmp_dir =

Type directory to which your user will be permitted to upload files.

On my PC it is:

upload_tmp_dir = "c:\Apache24\htdocs\catalog\upload"

If you want to use short open php tag like "<?" instead of "<?php" Set "short_open_tag" to On.

short_open_tag = On

By default it is set to Off in PHP.INI file. It is recommended, however, to user "<?php" tag just in case if hosting server does not support short open tag.

Make sure that following extentions are uncommented in PHP.INI file


extension=php_curl.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_imap.dll
extension=php_mbstring.dll
extension=php_mcrypt.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_xmlrpc.dll
extension=php_zip.dll

Rename php.ini.dist file to php.ini and copy it to Windows\system or WINT\system32 directory

For testing configuration regardless of PHP version create a test directory in C:\Apache2\htdocs directory.

Add the ";C:\php" to the path system environment variable.

Open notepad and type a php script:

<?php

phpinfo();

?>

Save file as phpInfo.php in the htdocs directory.

Start Apache web server from Windows start up menu.

Open you Internet Explorer and type in the following URL address:

http:/localhost/

If Apache installed and configured correctly, Apache home page displays "It Works" text.

To test php installation and configuration, type the following URL address in Internet Explorer:

http:/localhost/phpinfo.php

Click Go button. If installation is correct, you will see a long text with information about your Windows, Apache, and PHP setup.

Each time after you modify PHP.INI file, you have to restart Apache so that the changes took affect.

PHP links:

www.sitepoint.com

www.codetoad.com

www.phpfreaks.com

www.devx.com

www.phpbuilder.com

www.zend.com

Home