Skip to main content

How to install and setup PHP and MySql in windows 10 and 7

Install and Setup PHP and MySql on Windows

By installing WAMP server on your windows you can run Apache, PHP and MySql under single package. Run sample php and MySql script.

In traditional web development environment to run php and mysql on your machine you need to install Apache, PHP and Mysql servers as separate entity so that most of time you’ll end up in seeing errors.

Rather than installing each servers seperately how about installing a single package which contains above all 3 servers? Yes, that is were WAMP comes into picture.

WAMP is a open source web development package which in turn stands for Windows Apache MySql and PHP. WAMP is a package for only windows environment, for any other platform like linux, Apple OS you can use XAMP.

Advantages of using WAMP or XAMP

  • No need to install Apache, PHP and MySql servers seperately.
  • Easy to manage and configure all functionality under single menu.

Installing WAMP for Windows 10 and 7

The whole process is automatic and WAMP will take care of all major steps for you. Let’s see where i can find WAMP and what changes are necessary during installation.

  • Download the latest version of wamp server from wamp server website.
  • Run the installer, after accepting their agreement you will prompt to WAMP server location usually c:/wamp/. keep it as it is and click on next for all subsequent windows.wamp change drive location
  • You may ask for set your preferred browser and text editor. leave default if you like else change it.
    wamp setup choose browser
  • Finally, it will ask you to run wamp server or not. Make sure run wamp checkbox checked and click on button below to run wamp server.

If everything is going good you see a green wamp icon running on your system tray.wamp running green on tray

Error: Usually after launch wamp icon color changes from red to green state(wait for some seconds).Even after waiting if you see a color of wamp icon other than green like red or orange, then there may be some errors. Find wamp server possible errors at the end of this article.

Setup MySql database

  • Click on wamp server icon on your system tray and go to phpMyAdmin.Wamp menu
  • you get a browser window asking for username and password. Type root as username and don’t enter anything in password field(by default phpMyAdmin comes with root as mysql username), Click on login button to login. You may set password after login, under general settings → change passwrod. Set root as password if you like.
    wamp setup PhpMyAdmin change password

You are done with setting up mysql database, Now it’s time to run some simple php programs.

Sample program to test

1. Simple Hello world! program.

  • Create test.php file inside c:/wamp/www/ folder.
  • Copy the below code, paste it there and save the file.
    <?php
    
    	echo "Hello World!";
    
    ?>
    
  • Now, open your web browser and type http://localhost/test.php you see output as below.
    PHP run sample program

2. Sample program to fetch data from database.

Here is the step by step procedure to create database and tables.

Adding databse and tables into mysql from phpMyAdmin.

Goto wamp icon → phpMyAdmin. From the left menu of phpMyAdmin page click on New button. Type database name as test and click on create to create new database.

Wamp PhpMyAdmin Create Database

After creating database it will automatically prompt to a window to create table into it. Type table name as tbl_test, number of fields as 3 and click on create to create table.

wamp phpmyadmin create table

Further, it will ask for datatype and size. Enter data shown in below image and click on go.

wamp PhpMyadmin choosing datatype for fields

Inserting values into table.

With table selected in left menu click on insert button(tabbed menu on top) and enter the data as shown in below image. Click on go button to add your first row into table.
wamp phpmyadmin insert data into table
You are done with adding database,tables and data into tables. Now, will see how to fetch those data from php.

Fetching data from Mysql using PHP

  • Create test_db.php file inside c:/wamp/www/ folder.
  • Copy the below code, paste it there and save the file.
  • <?php
    
    $servername = "localhost";
    $username = "root";
    $password = "root";
    $dbname = "test";
    
    try {
        	$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
        	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        }
    catch(PDOException $e)
        {
        	die("OOPs something went wrong");
        }
    
    $sql_query = 'SELECT * from tbl_test';
    $stmt_query = $conn->prepare($sql_query);
    $stmt_query->execute();
    
    if($stmt_query->rowCount())
    {
      while($row= $stmt_query->fetch(PDO::FETCH_ASSOC)){
     	 echo "Welcome, " . $row['first_name'] . " " . $row['middle_name'] . " " . $row['last_name'] . "\n";
      }
    
    }
    elseif(!$stmt_query->rowCount())
    {
      echo "No data found.";		  
    }
    	
    ?>
    
  • Now, open your web browser and type http://localhost/test_db.php to run the program.
    php sample program to connect database and fetch data

The below portion of article is only for one who finds error while installing WAMP.

Possible errors while installing WAMP

1. Missing VCRUNTIME140.dll error

wamp dll missing error while installation

This error can be solved by downloading newer version of visual c++ redistribution from microsoft. Below is the link for visual c++ 2015 redistibution package, download and install it(both 32bit and 64bit versions available and make sure you are downloaded same version you are running in).

Microsoft Visual C++ 2015 Redistribution

Uninstall WAMP and Reinstall.

2. Missing MSVCR110.dll error

Wamp missing MSVCR110.dll error
missing-msvcr110-dll-error

Solved by installing visual c++ 2012 redistribution from microsoft. Below is the link for visual c++ 2012 redistibution package, download and install it(both 32bit and 64bit versions available and make sure you are downloaded same version you are running in).

Microsoft Visual C++ 2012 Redistribution

Uninstall WAMP and Reinstall.

3. Port used by Microsoft IIS Server

This is the very common issue in Windows 10 and 7. Even after proper installation wamp icon does not turn to green. The reason is the port which is assigned to apache server is used by some other services in your PC(usually IIS Server).

Let’s check which service is using port 80. Go to wamp icon → Test port 80.

If port is used by IIS server here is the fix. Go to Services(Go to start menu of your windows
and start typing services to search for it), scroll to bottom and find World Wide Web Publishing Services right click on it and disable.

Wamp disable world wide publishing windows 10

Now exit your wamp from tray by Right click and exit then run it again.

Gururaj P Kharvi

An Entrepreneur, Web and Android developer from India.

2 thoughts on “How to install and setup PHP and MySql in windows 10 and 7

Leave a Reply

Your email address will not be published. Required fields are marked *