This article will show how with only a few easy steps you can install the Apache web server, the PHP language, and the MySQL databases all under Windows OS. This way you'll be able to develop your own websites and follow up practical web development courses such as:
Star Rating with PHP, MySql and JavaScript
Create contact form with PHP, JavaScript and CSS
Let's begin! Here we will be doing the manual way of installation, if you prefer an automated way you can use XAMPP as shown in the video:
First, download and install the following packages in this way:
1. Apache Win32 Binary http://httpd.apache.org/download.cgi
2. PHP installer http://www.php.net/downloads.php
3. MySQL community server http://dev.mysql.com/downloads/mysql/5.0.html
(optionally: mysql php_mysqli.dll driver from http://dev.mysql.com/downloads/connector/php-mysqlnd/)
APACHE
Check up: After the initial installation in a browser window address bar window type: http://localhost
If working properly the Apache server will show you this message: It works!
PHP
1. Open the file httpd.conf found in directory: C:\Program files\Apache Software Foundation\Apache2.4\conf\ and add after the last LoadModule section:
LoadModule php5_module "C:\Program Files\PHP\php7apache2_4.dll" where php4apache2_4.dll is the file telling Apache to load dynamically the PHP language.
Note: If your file has a different name please use it!
2. Find the AddType line and add the following under:
AddHandler application/x-httpd-php .php
PHPIniDir "C:/PHP"
This tells the webserver to associate all .php files to the interpreter. Otherwise, when you run a .php file in your browser you'll see it as a normal text file followed by the usual Save as dialogue.
Check: Create a new file named index.php and type in the following: <? phpinfo(); ?> . Place it in C:\Program Files\Apache Software Foundation\Apache2.4\htdocs. Open the browser again and load the index.php file. If it loads up properly then your Php is being installed correctly!
MYSQL
0. Get and run the MySql installer from https://dev.mysql.com/downloads/installer/
1. Rename the file php-dist.ini to php.ini and copy it from the directory it's installation directory i.e. Program files\PHP in c:\windows. Then copy the files php_mysql.dll and libmysql.dll in directory c:\windows\system32.
2. Open c:\windows\php.ini and add after the section Dynamic extensions the following 2:
extension=libmysql.dll
extension=php_mysql.dll
Check: If everything is ready, create index.php file with content: <? phpinfo(); ?> inside: C:\Program Files\Apache Software Foundation\Apache2.4\htdocs
Point your browser to: http://localhost and you'll have to see in the information the MySQL section.
When having problems:
If Apache fails to run open Start->Run->eventvwr.msc and check under the Application tab the type of error coming from Apache Service. A most common error is:
Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80
Solution: open httpd.conf and change the listening port used by Apache to 3128 for example.
Other often harder to see the error is being produced when you use the short <? when typing your code - this is forbidden in some of the PHP versions. If you want to use this functionality then change the option:
short_open_tag = On
in php.ini
Cheers, and if you have any questions just ask!