How to install Python and PHP on Windows

Introduction

Python and PHP are the most popular and widely used programming languages, each having its own unique strengths for various applications. Python is known for its simplicity and versatility and is used in data science, web development, and automation tasks. On the other hand, PHP remains a powerful tool for server-side scripting and dynamic web content creation.

In this article, we will guide you through the installation processes for both Python and PHP on your system. We will also show you how to verify their installations by checking their versions, ensuring that your development environment is set up correctly. Whether you are setting up a new development machine or just confirming that your existing setup is up to date, this guide will provide clear, step-by-step instructions to get you started with these essential programming languages.

Python

Python is a user-friendly programming language known for its clear and readable syntax. Python uses indentation to define the structure rather than braces in other programming languages. This makes it easy for beginners as well as experienced developers to tackle various projects. It supports a wide range of applications like data analysis, artificial intelligence, and machine learning. It has a rich ecosystem of libraries.

Prerequisites:

  • Python supports Windows 7 and later versions.
  • Choose an appropriate installer depending on your system architecture (32-bit or 64-bit) from the Python website.
  • You need administrative privileges to install it and modify system PATH variables.

Step-by-Step Guide

1. Go to www.python.org, select Downloads, and click on Download Python 3.12.5.

Download Python 3.12.5 from the official
Download Python 3.12.5 from the official

2. Click on Open File under Downloads in the top-right corner of the window.

Click on 'Open file' under the Downloads section to open the Python file
Click on ‘Open file’ under the Downloads section to open the Python file

3. Firstly,

  • Check the box next to Use admin privileges when installing py.exe
  • Check the box next to Add python.exe to PATH

Secondly, click on Customize Installation (choose location and features).

Check 'Use admin privileges' and 'Add python.exe to PATH,' then click 'Customize installation' to select the location and features for Python
Check ‘Use admin privileges’ and ‘Add python.exe to PATH,’ then click ‘Customize installation’ to select the location and features for Python

4. Under Optional Features, check all the boxes and click on Next.

Check all boxes under Optional Features and click 'Next' to proceed with Python installation options
Check all boxes under Optional Features and click ‘Next’ to proceed with Python installation options

5. Under Advanced Options,

  • Check the box next to Install Python 3.12 for all users.
  • You can change the location of the file you want to install by clicking on Browse.
  • Click on Install.
Check 'Install Python 3.12 for all users,' optionally change the installation location by clicking 'Browse,' and then click 'Install' under Advanced Options
Check ‘Install Python 3.12 for all users,’ optionally change the installation location by clicking ‘Browse,’ and then click ‘Install’ under Advanced Options

6. Once the installation is successful, you can see the screen below.

Click on Close.

View the Python successful installation screen and click 'Close'
View the Python successful installation screen and click ‘Close’

7. Verify the installation of Python by running the below command

Command: python --version

It will show you the Python version installed. Here, Python 3.12.5 is installed.

Verify Python installation by running 'python --version' to display the installed version, such as Python 3.12.5
Verify Python installation by running ‘python –version’ to display the installed version, such as Python 3.12.5

8. Now, to run a Python program, use the command shell. So, to do that, start by running the command below.

Command: python

Now, you are in a python shell.

Examples:

  • Try to enter some information in the print command or arithmetic operation, and the message will be displayed on the screen.
Command: print(“welcome!”)
Output: welcome!
  • Give some arithmetic operation
Command: 2+3
Output: 5
Run 'python' in the command shell to enter the Python interactive shell
Run ‘python’ in the command shell to enter the Python interactive shell

9. Run a Python program using IDLE. Go to the Windows search bar and type IDLE. The Python command prompt will open.

Search for 'IDLE' in Windows to open the Python command prompt and run Python programs
Search for ‘IDLE’ in Windows to open the Python command prompt and run Python programs

10. Here, in IDLE Shell also, you can run Python programs.

  • Go to File > New File.
Open IDLE Shell and go to File > New File to create a new Python script
Open IDLE Shell and go to File > New File to create a new Python script
  • Now, save the file by clicking on Save As. You can browse by selecting the path where you want to save the file.

Note: Here, the file is saved as ‘hi’. It will take ‘py’ as an extension.

Save the Python file by clicking 'Save As' and selecting the desired save location
Save the Python file by clicking ‘Save As’ and selecting the desired save location
  • Now, write a program

Example: print (“hello, welcome”)

Write a Python program in the IDLE editor
Write a Python program in the IDLE editor
  • Run the program by clicking on the Run Module.
Run the Python program by clicking 'Run Module' in IDLE
Run the Python program by clicking ‘Run Module’ in IDLE
  • The screen below shows the message.
The screen displays the output message after running the Python program
The screen displays the output message after running the Python program

Hypertext Preprocessor (PHP)

PHP (Hypertext Preprocessor) is a widely used server-side scripting language designed for web development. It can be embedded directly into web pages, making it easy to integrate dynamic content with static web pages. PHP is commonly used with MySQL and PostgreSQL to create data-driven websites and applications, It can be run on various operating systems like Windows, Linux, and macOS and supports web servers such as Apache and Nginx.

Prerequisites:

  • Python supports Windows 7 and later versions.
  • Choose an appropriate installer depending on your system architecture (32-bit or 64-bit) from the Python website.
  • Having a text editor (like Notepad++, VS Code, or Sublime Text) or an Integrated Development Environment (IDE) will help you write and manage PHP code.
  • Database servers, such as MySQL or MariaDB, are needed to handle data storage and management.
  • You need administrative privileges to install it and modify system PATH variables.

Step-by-Step Guide

  1. Go to www.php.net/downloads.php and click on Windows downloads.
Visit the PHP website and click 'Windows downloads' to access PHP for Windows
Visit the PHP website and click ‘Windows downloads’ to access PHP for Windows

2. A new page opens,

  • Under VS16 x64 Thread Safe (2024-Jul-30 18:09:04), click on Zip [30.81MB].
On the new page, click 'Zip [30.81MB]' under VS16 x64 Thread Safe (2024-Jul-30 18:09:04) for PHP installation
On the new page, click ‘Zip [30.81MB]’ under VS16 x64 Thread Safe (2024-Jul-30 18:09:04) for PHP installation

3. Click on Open File under Downloads in the top-right corner.

Click 'Open file' under Downloads to open the PHP download
Click ‘Open file’ under Downloads to open the PHP download

4. It will navigate to the Downloads section in File Explorer. As it is a zip folder, click on Extract All.

Navigate to the Downloads section in File Explorer, then click 'Extract All' for the PHP zip folder
Navigate to the Downloads section in File Explorer, then click ‘Extract All’ for the PHP zip folder

5. If you want to change the destination of the file, click on Browse. Otherwise, leave it as it is.

  • Click on Extract.
Click 'Browse' to change the destination or leave the default, then click 'Extract' to unzip the PHP folder
Click ‘Browse’ to change the destination or leave the default, then click ‘Extract’ to unzip the PHP folder

6. Now, you can see all the files have been extracted.

View all extracted files in the PHP folder
View all extracted files in the PHP folder

7. Now, add this PHP path to the environment variables.

  • Go to the Windows search bar and type Environment Variables. Select Edit the system environment variables.
Add PHP path in Environment Variables by selecting 'Edit the system environment variables
Add PHP path in Environment Variables by selecting ‘Edit the system environment variables

8. In the System Properties window, click on Environment Variables.

Click 'Environment Variables' in the System Properties window to add the PHP path
Click ‘Environment Variables’ in the System Properties window to add the PHP path

9. Under System Variables, double-click on Path.

Double-click 'Path' under System variables to add the PHP path
Double-click ‘Path’ under System variables to add the PHP path

10. A new window opens.

  • In the Edit environment variable window, click on New, copy the path, and click OK.
In the Edit environment variable window, click 'New,' paste the PHP path, and then click 'OK'
In the Edit environment variable window, click ‘New,’ paste the PHP path, and then click ‘OK’
  • Click OK in the Environment Variables window.
  • Click OK in the System Properties window.

11. Now, type the command prompt in the Windows search bar. Select Command Prompt.

Search for 'Command Prompt' in Windows and select it to verify PHP installation
Search for ‘Command Prompt’ in Windows and select it to verify PHP installation

12.  Check the version of PHP by running the below command.

Command: php -v (or) php --version
Check the PHP version by running 'php -v' or 'php --version' command
Check the PHP version by running ‘php -v’ or ‘php –version’ command

13.  How to create a file with PHP

  • Create a folder on the desktop and name it.

Note: As an example, a folder is created as a PHP folder.

  • Double-click on the folder.
Create a file with PHP
Create a file with PHP

14.  In the php folder, create a text document.

  • Right-click on the empty space.
  • Select New, and select Text Document.
Create a text document within the php folder.
Create a text document within the php folder.

15.  Name the file as filename.php (php is the extension of the file).

  • If you cannot name the file with php as its extension, then
  • Click on View in the menu bar.
  • Check the box next to File name extensions.
  • Now, you should be able to add PHP as an extension.

Note: Here, as an example, demo.php is created.

Name the new file with the .php extension for your PHP file
Name the new file with the .php extension for your PHP file
  • Click on Yes.
Click 'Yes' to confirm changing the file extension to '.php' for your PHP file
Click ‘Yes’ to confirm changing the file extension to ‘.php’ for your PHP file
  • Double-click on the file (here, demo.php).

16. The Visual Studio code editor opens with the file name.

  • Write a sample code in the editor
<?php
echo “Welcome to PHP!”
?>
  • Now, click on File->Save to save the file.
Visual Studio Code opens with the PHP file
Visual Studio Code opens with the PHP file
  • Go to the Windows search bar, type command prompt and select Command Prompt (or)
  • Click on the folder symbol and type cmd, as shown on the below screen. It will navigate to the command prompt directly.
Search for 'Command Prompt' in Windows or type 'cmd' in the folder symbol to open Command Prompt for running PHP
Search for ‘Command Prompt’ in Windows or type ‘cmd’ in the folder symbol to open Command Prompt for running PHP
  • You can see in the command prompt that we are directly in the folder we created (ex: php folder).
  • Check whether you can see the file and its contents by running the below command.
Command: php filename.php

Note: demo.php is the file that is created.

  • You can see the contents in the file.
Output: Welcome to PHP!
Verify PHP file contents in the Command Prompt by running 'php filename.php' in the folder to see the output
Verify PHP file contents in the Command Prompt by running ‘php filename.php’ in the folder to see the output

Conclusion

Python and PHP cater to various aspects of development. Python’s ease of use makes it an excellent choice for a broad spectrum of applications, from data analysis to web development. PHP, with its strong focus on server-side scripting, remains a robust solution for creating dynamic web content and integrating with databases. By following the steps to install and verify these languages, you can ensure a well-configured development environment suited to your project’s needs. Mastering both Python and PHP can significantly enhance your ability to build and manage diverse applications.

FAQs

Q1. What type of language is Python?

Answer: Python is an interpreted, interactive, object-oriented programming language. It incorporates modules, exceptions, dynamic typing, very high-level dynamic data types, and classes. It supports multiple programming paradigms beyond object-oriented programming, such as procedural and functional programming

Q2. What are the uses of PHP?

Answer:

  • It is a server-side scripting language used to design dynamic websites or web applications.
  • It receives data from forms to generate dynamic page content.
  • It can work with databases and sessions, send and receive cookies, send emails, etc.
  • It can be used to add, delete, or modify content within the database.
  • It can be used to set a restriction on the user’s access to the web page.

Q3. Does PHP need a compiler?

Answer: If your server supports PHP, then you do not need to do anything. Just create your PHP files, put them in your web directory and the server will automatically parse them for you. There is no need to compile anything, nor do you need to install any extra tools.

Q4. What are the data types in Python?

Answer: Python has six standard data types. Data types are the classification of data items and represent the kind of value that shows what operations can be performed on a particular data set. Because everything is an object in Python, they are classes. Variables are instances of the classes.

The data types in Python are numbers, strings, lists, tuples, sets, and dictionaries.

Q5. Is PHP a case-sensitive language?

Answer: Not fully. PHP is partly a case-sensitive language, where the variable names are case-sensitive but the function names are not. Also, user-defined functions aren’t case-sensitive, but the rest of the language is.

Q6. What is a Python virtual environment?

Answer: A Python virtual environment is an isolated environment that allows you to manage dependencies and packages for a specific project without affecting the global Python installation. It can be created using tools like Venv or Virtualenv.

Enhance your development environment with our expert documentation and setup guides. At The Scribe, we provide clear, impactful writing for everything from technical manuals to business proposals. Combine this with our detailed guides for installing Python and PHP on Windows to simplify your setup. Contact us today to boost your development projects with top-notch documentation and seamless configuration!

Komal

Komal

Table of Contents

Read More

Scroll to Top