Ensure that you choose to register it as a Windows service (which is a convoluted way of starting the MySQL server automatically on Windows startup), and that you choose to update the PATH environment variable. This will give you the means to test and access MySQL from the command prompt.
Step 2: Install PHP (php-5.2.8-Win32.zip)
Simply unzip the files to a folder of your choice (I placed mine in C:\). There is also a Windows installer for PHP, but I consider it unnecessary.
Now we need to configure PHP to use the MySQL client library, which is located in \php-5.2.8\ext\php_mysqli.dll. This is done in php.ini, which can be copied from one of the templates available in the PHP root folder. The client library is available as a PHP extension, so the first thing we need to do here is to specify where the PHP extensions are to be found. This is done by setting the PHP extensions directive as follows:
; Directory in which the loadable extensions (modules) reside.After which, the extension must be enabled by uncommenting the corresponding line:
extension_dir = C:\php-5.2.8\ext
extension=php_mysqli.dllNotice that there are two extensions available for MySQL: php_mysqli.dll and php_mysql.dll. MySQLi stands for "MySQL, improved", supports an object-oriented programming interface, and supports the Prepared Statements and Multiple Statements API, which is a big deal if you're going to be writing a lot of SQL statements. In any case, MySQLi is meant for newer versions of MySQL, including MySQL 5.1 which we just installed. See http://dev.mysql.com/doc/refman/5.0/en/apis-php.html. Also, the stuff I wrote above about PHP extensions is taken from http://in2.php.net/manual/en/mysqli.installation.php.
Step 3: Install Apache Web Server (apache_2.2.11-win32-x86-openssl-0.9.8i.msi)
After installation, we will need to edit the httpd.conf file at \Apache2.2\conf\httpd.conf. I'll rank the changes by order of importance:
1. Specify the root directory of your web server. I chose to put mine in D:\myserver.
#2. Enable the PHP module, and specify where php.ini is to be found:
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "D:\localserver"
....
#
# This should be changed to whatever you set DocumentRoot to.
#
<directory>
....
</directory>
# PHP 53. Specify that your website's index can be a PHP file. This is the file that gets loaded when you type in your base url in the browser (eg www.google.com)
LoadModule php5_module "C:/php-5.2.8/php5apache2_2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php-5.2.8"
#Be sure to restart the web server after making any changes to httpd.conf or php.ini.
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<ifmodule>
DirectoryIndex index.html index.php
</ifmodule>
Step 4: Test
How do you know if everything is setup correctly? First thing to do is ensure that your web server is up. Create a file index.html containing the following text:
<html>And place it in your webserver's root folder (ie D:\myserver\index.html). Now point your web browser to http://localhost/. You will see a page saying 'Hello World!' with the corresponding title.
<header><title<Hello Title Bar!</title></header>
<body>Hello World!</body>
</html>
To test whether PHP is enabled, rename index.html to index.php, and replace the <body> tag with <body><?php Hello PHP World! ?></body>. After reloading the localhost page, you should be able to see the new message 'Hello PHP World!'.
To test whether MySQL is enabled, create a new file testmysql.php containing the following PHP code:
<?phpPlace this file in the same directory as index.php, and open it using the url http://localhost/testmysql.php.
$connection = @mysqli_connect('localhost', 'yourusername', 'yourpassword');
if (!$connection) {
echo 'Failed to connect to your MySQL database server.
The following error message was reported: '.mysqli_connect_error();
} else {
echo 'MySQL Database connection successful.';
}
?>
No comments:
Post a Comment