25.1 C
Texas

How to install PHP in Windows 10

Hi, how are you? Today I’m going to talk to you about PHP. It is a general-purpose server-side code and interpreted programming language, also is suitable for web development and can be embedded in HTML. Additionally, PHP has multiple ways of being used, since it can be used with scripts, in a structured way or programming in objects. Likewise, it is mainly used to create web pages, to create dynamic content and to work with databases and HTML. On the other hand, it supports most databases: MySQL, PostgreSQL, SQL Server, MongoDB. Because of these features, millions of web pages use PHP. Therefore, let’s see how to install PHP in Windows 10.

Prerequisite

In this post, we are going to use the PHP language on an Apache server. Obviously it must be successfully configured in Windows. To find out how to do it, please look here.

Downloading PHP

The first thing we have to do is download the latest version of PHP. With this in mind, please go to the download section and select the latest version (VC15 x64).

Download the latest version of PHP, for the time of this post, is VC15 x64
Download the latest version of PHP, for the time of this post, is VC15 x64

Installing PHP

Once you have downloaded the file, unzip it to the root of the Windows installation. For ease of use rename the folder as php. Finally, the route would be as follows: C:\php. Finally, we have to add the environment variable for php to run from any Command Prompt. For instructions on how to do this, please read here. Please edit the Path variable and add the following address: C:\php.

Adding an environment variable for PHP
Adding an environment variable for PHP
- Advertisement -

You can prove that the configuration is successful by running any php command on a CMD, such as php -v:

Testing PHP in a CMD
Testing PHP in a CMD

Configure Apache to run PHP

Next, we are going to configure the Apache server to correctly interpret the php language. With this in mind, we are going to edit the httpd.conf file located in the following path: C:\Apache24\conf. Once the file is selected, open it with your favorite text editor.

Select httpd.conf
Select httpd.conf

After opening the file, please locate the Directory Index line. Just leave a space after index.html and add index.php.

Locate the DirectoryIndex line. It is usually number 290. After index.html leave a space and type index.php
Locate the DirectoryIndex line. It is usually number 290. After index.html leave a space and type index.php

With this modification, we are instructing the server to search for both an index.html file and an index.php file. Next, we will edit the server configuration file to allow loading the PHP module. With this intention, copy the following lines of code:

LoadModule php7_module C:/php/php7apache2_4.dll
	<IfModule php7_module>
	    AddHandler application/x-httpd-php .php
	    PHPIniDir "C:/php"
	</IfModule>

Please move through the configuration file to line 72 LoadModule foo_module modules/mod_foo.so. Press enter to leave a blank line and add the previous code.

Add the code to load the PHP module
Add the code to load the PHP module

Finally, save the file. Please note that to make the changes effective on the server, you have to stop and restart the service from Windows Services. The following command runs services.msc, once the window is open it locates the Apache server. Then I restart, clicking on the icon that I show you in the image:

Restarting the Apache Server
Restarting the Apache Server

These are the previous steps to install PHP in Windows 10.

Running PHP

In order for the Apache server to correctly interpret the PHP language, it is necessary to rename the index.html file located in the following path: C:\Apache24\htdocs. Once the file is selected, change its extension to .php. In this way, the server will correctly interpret the PHP language.

Modify the index.html file
Modify the index.html file

All right, all settings are ready. Now let’s modify this file to run a simple PHP command. In this case Echo. With this in mind, please edit the file with the following configuration:

<html>
<body>
	<h1>it works!</h1>
	<?php
		echo "Hello from osradar!";
	?>
</body>
</html>

In the text editor, it should look like this:

Edit index.php
Edit index.php

We save the file and open localhost in the web browser. If we have done everything correctly, then we should see this result:

Opera browser showing PHP correctly
Opera browser showing PHP correctly

Finally, we have seen how to install PHP in Windows 10. This language is very popular worldwide, so being able to count on it is a great advantage for our projects. This is all for now, I hope to see you soon!

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

1 COMMENT

  1. Thank you for the great tutorial. The only thing I would note is that the code above for http.conf has been changed with version 8 of php and should read:

    LoadModule php_module C:/php/php8apache2_4.dll
    <IfModule php_module>
    AddHandler application/x-httpd-php .php
    PHPIniDir "C:/php"
    </IfModule>

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article