Apache服务器 + PHP + MySQL

本文详细介绍了如何在Windows 7上手动安装Apache 2.4、PHP 5.4和MySQL 5.5。包括下载最新版本的软件,配置Apache的httpd.conf文件,设置PHP的php.ini,以及安装Apache服务。此外,还提到了MySQL的安装和配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

  1. 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.
  2. 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.
  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
  1. 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.
  2. Set the server root
ServerRoot "D:/etc/apache"
  1. Enable required Apache modules. I just uncomment one more for mod_rewrite module.
  2. 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"
  1. Change server admin email address
ServerAdmin info@yoursite.com
  1. Change the document root:
DocumentRoot "d:/etc/www"
<Directory "d:/etc/www">
  1. If you want to allow .htaccess ("分布式配置文件")to be used under document root do the following under <Directory “d:/etc/www”>
AllowOverride All
  1. Find the follwoing and replace the path:
ScriptAlias /cgi-bin/ "d:/etc/apache/cgi-bin/"
<Directory "d:/etc/apache/cgi-bin">
  1. Add index.php in directory index

DirectoryIndex index.html index.php

 

PHP
  1. Rename php.ini-development to php.ini
  2. Find extension directory setting and set the path as per your installation.
extension_dir = "d:\etc\php\ext"
  1. 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.

  1. 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.
  2. Change directory to d:\etc\apache\binin the command line
cd d:\etc\apache\bin
  1. 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.

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值