Recently, I decided to install a working Apache 2.4 / PHP 5.4 and MySQL 5.5 running locally on my Windows 7 laptop for web design.
Installing AMP (Apache, MySQL and PHP) has become quite easier with single wizard based installations available as a packet these days. Like using XAMPP, WAMP you can just install them and use. But with these setups, you will have (or will not have) less knowledge about configuring them each in your own way because they will present some user interface where you can directly do configurations by one click. You will not know what exactly required for changing something in Apache, PHP or MySQL. So to have knowledge on configurations on them according to your requirement, you have to install each application individually.
The installation and configurations of PHP, Apache and MySQL in Windows has also become quite easier these days because they provide some default configurations. As PHP, after its latest releases i.e.5.4, does not provide the downloads of VC6 version (the PHP compiled with Visual C++ 2005 compiler) , because it is believed that the performance of the PHP compiled with VC9 (compiled with Visual C++ 2008 or later) has improved quite a lot than the compiled with VC6. So to work with the latest VC9 version of PHP, you must have installed PHP with VC9 compiled Apache as well or you use IIS as web server. VC9 compiled Apache is provided by Apache Lounge (apachelounge.com)not the original Apache (apache.org). Since I haven’t worked yet with IIS and always work with Apache in anyway, I don’t have knowledge about the IIS & PHP. Here I am going to explain few steps on how to install PHP 5.4 and Apache 2.4 in Windows
Where to install?
Since I have not used any installers for both PHP and Apache, I will be downloading the pre compiled zipped packages and install them in my D drive. The folder structure will look like below:
- d:/etc/apache – Apache installation
- d:/etc/php – PHP installation
- d:/etc/mysql – MySQL installation
- d:/etc/mysql/databases – MySQL data folder
- d:/etc/www – document root folder
Note: You can change the drive and path for the installations in your own way.
Download
- Download the latestApache 2.4.3 (as of writing this) from http://www.apachelounge.com/download/ (direct link for the current version – http://www.apachelounge.com/download/win32/binaries/httpd-2.4.3-win32.zip) and unzip it in d:/etc/apache. I do not use the OpenSSL one here.
- Download the archive version 5.4.9 from http://windows.php.net/download (http://windows.php.net/downloads/releases/archives/php-5.4.9-Win32-VC9-x86.zip) and unzip it in d:/etc/php. While downloading PHP, choose the Thread Safe version for windows. I do not use the latest version 5.4.10, because that I cannot get the corresponding PHP and Apache connector DLL file from the location in step 3.
- Download php5apache2_4.dll-php-5.4-win32.zip for the PHP and Apache connector DLL file (http://www.apachelounge.com/download/win32/modules-2.4/php5apache2_4.dll-php-5.4-win32.zip) and extract the file php5apache2_4.dll and copy it to d:/etc/php.
Configurations
Though the configurations may vary from individual’s requirement but here I will be discussing for some basic configurations in PHP and Apache.
Apache
- Open the file d:/etc/apache/conf/httpd.confin any text editor (I use my lovely Notepad++) then find and make the following changes/configurations as per your installation path.
- Set the server root
ServerRoot "D:/etc/apache"
- Enable required Apache modules. I just uncomment one more for mod_rewrite module.
- Add the following lines somewhere (I did just below the module enabling)
LoadModule php5_module "d:/etc/php/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
PHPIniDir "d:/etc/php"
- Change server admin email address
ServerAdmin info@yoursite.com
- Change the document root:
DocumentRoot "d:/etc/www"
<Directory "d:/etc/www">
- If you want to allow .htaccess ("分布式配置文件")to be used under document root do the following under <Directory “d:/etc/www”>
AllowOverride All
- Find the follwoing and replace the path:
ScriptAlias /cgi-bin/ "d:/etc/apache/cgi-bin/"
<Directory "d:/etc/apache/cgi-bin">
- Add index.php in directory index
DirectoryIndex index.html index.php
PHP
- Rename php.ini-development to php.ini
- Find extension directory setting and set the path as per your installation.
extension_dir = "d:\etc\php\ext"
- Uncomment (remove the simicolon ; from the beginning of the line) the extensions that you want to enable them. i.e.
extension=php_curl.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
extension=php_soap.dll
Rest of the changes/configurations are totally depends on requirement project wise.
Set Environment Variables for PHP/Apache (Windows 7)
PATH in Environment variables. PATH ENVIRONMENT (System Properties | Advanced | Environment Variables | System variables | Path).
Example:
; d:\etc\php; d:\etc\apache; d:\etc\apache \bin
Install Apache as Service
Since we have just copied the files in a folder, the Apache is not yet not a windows service. To install it as a service follow the steps.
- Run the command line (cmd.exe) As Administrator. Browse the folder c:\Windows\System32\ and right click on cmd.exe and select Run as Administrator.
- Change directory to d:\etc\apache\binin the command line
cd d:\etc\apache\bin
- Run the command to install it
httpd -k install (or sometimes httpd.exe -k install if that does not work)
Now restart the computer and test both PHP and Apache. To test both together create a PHP file phpinfo.php in d:\etc\www. Now browse in the browser as http://localhost/phpinfo.php.
Note:
To make sure the apache service is started, you need click 我的电脑右键 ---选管理---左边一栏选服务与应用---再选Apache服务
MySQL
Download and install mysql-installer-community-5.5.29.0.msi.(http://dev.mysql.com/downloads/mysql/) Change installation directory to d:/etc/mysql instead of Program files as there could be permissions issues. Once the installation is completed you can let the configuration wizard run and setup the database server. The defaults will work just fine, but remember what you set the password to for root.
If it prompts current root password inputting, do not panic. You can reset it with the MySQL Workbench.