This is a step-by-step setup of PHP 7 on Windows 10.
- Download PHP package from PHP website. The latest version as of this time is
7.2.0
. ChooseVC15 x64 Thread Safe
orVC15 x86 Thread Safe for 64-bit
or32-bit
OS. In my case, I downloaded the former.
-
Extract the package to
C:\php
. -
Inside php directory, make a copy of
php.ini-development
and rename it tophp.ini
.
<img class=“img-fluid” src=“/assets/images/blog/installation-of-php-7-on-windows-10/2.PNG” alt=“PHP Ini”)
- Open
php.ini
and uncomment the following (line 732):
; extension_dir = "ext"
- Add
php.exe
toEnvironment Variables's Path
. To add, look forPath
underSystem variables
and clickEdit...
button. Click New button and enterC:\php
.
- To test, create a directory:
C:\workspace\php
. Open your favorite text editor (mine is Visual Studio Code). Add the following codes to a file saved ashello.php
insideC:\workspace\php
:
<?php
echo "Hello, world!";
- Open CMD and cd to
C:\workspace\php
. Run the following command:
php -S localhost:3000 -t .
From PHP site:
As of PHP 5.4.0, the CLI SAPI provides a built-in web server.
This web server was designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.
- Open your browser and point to
http://localhost:3000/hello.php
- Enable extension you want to use. For example, most likely you will be developing database-driven web applications and you’d want to use MySQL, the world’s most popular open-source DBMS. Install MySQL first if you haven’t done so. Then, open
php.ini
and uncomment either or both of the following:
extension=mysqli
...
extension=pdo_mysql
If you’ve configured a web server Apache HTTP Server for PHP, you will have to restart it’s service for the changes to take effect. As for PHP built-in web server, just run it again.
To test PHP and MySQL connection, you can create a PHP script and call the built-in phpinfo()
function to display PHP environment. You should be able to see php_pdo
included under PDO.
<?php
echo phpinfo();
You might also want to create script which creates connection to your database already created in the server.
<?php
$dbProvider = 'mysql';
$dbHost = 'localhost';
$dbPort = '3306';
$dbSchema = 'mydb';
$dbCharSet = 'utf-8';
$dbUser = 'julez';
$dbPassword = 'admin';
$dns = $dbProvider . ':host=' . $dbHost . ';port=' . $dbPort . ';dbname=' . $dbSchema . ';char-set='. $dbCharSet;
$connection = new PDO($dns, $dbUser, $dbPassword);
if ($connection) {
echo 'Database connected!';
} else {
die('Unable to connect to databese!');
}
Save it as php_pdo_mysql_test.php
and load to your browser.
It’s done!
Please post your comments or suggestions.