Connect with us


The right way to Set up PHP on Home windows – SitePoint

This text explains methods to set up PHP 8 and Apache 2.4 on Home windows 10 (64-bit).

Linux and macOS customers typically have Apache and PHP pre-installed or obtainable by way of package deal managers. Home windows 10 requires just a little extra effort. The steps under might work with different editions of Home windows, PHP, and Apache, however examine the documentation of every dependency for particular directions.

Why PHP?

PHP stays essentially the most widespread and well-liked server-side programming language on the Net. It’s put in by most internet hosts, and has a easy studying curve, shut ties with the MySQL database, very good documentation, and a very good assortment of libraries to chop your growth time. PHP might not be good, nevertheless it needs to be thought of as an choice in your subsequent internet utility. It’s the language of selection for Fb, Slack, Wikipedia, MailChimp, Etsy, and WordPress — the Content material Administration System which powers 40% of the online.

Why Set up PHP Domestically?

Putting in PHP in your growth PC permits you to safely create and take a look at web sites and functions with out affecting the information or techniques in your dwell server.

Different Set up Choices

Earlier than you leap in, there could also be a less complicated set up choices…

Use an All-in-One package deal

All-in-one packages can be found for Home windows which include Apache, PHP, MySQL, and plenty of different dependencies in a single set up file — akin to XAMPP, WampServer and Net.Developer.

These packages are straightforward to make use of, however they could not precisely match your dwell server. Putting in Apache and PHP manually will provide help to be taught extra concerning the system and configuration choices.

Use a Linux Digital Machine

Microsoft Hyper-V (supplied in Home windows 10 Skilled) and VirtualBox are free hypervisors which emulate a PC so you possibly can set up one other working system.

You’ll be able to set up any model of Linux, then observe its Apache and PHP set up directions. Alternatively, distros akin to Ubuntu Server present them as commonplace (though they’re hardly ever the newest editions).

Use Home windows Subsystem for Linux 2

WSL2 can also be a digital machine, nevertheless it’s tightly built-in into Home windows so actions akin to file sharing and localhost decision is seamless. You’ll be able to set up a number of Linux distros, so check with the suitable Apache and PHP directions.

Use Docker

Docker creates a wrapper (generally known as a container) round pre-configured utility dependencies akin to Apache, PHP, MySQL, MongoDB, and most different internet software program. Containers appear like full Linux Digital Machines however are significantly extra light-weight.

When you’ve put in Docker Desktop on Home windows 10, it’s straightforward to obtain, configure, and run Apache and PHP.

Docker is at present thought of the most suitable choice for establishing a PHP growth surroundings. Try SitePoint’s article “Setting Up a Trendy PHP Growth Atmosphere with Docker” for an entire information to setting it up.

Set up Apache (elective)

When you’re nonetheless studying, the next sections describe methods to set up Apache and PHP immediately on Home windows.

PHP gives a built-in internet server which could be launched by navigating to a folder and operating the PHP executable with an -S parameter to set the localhost port. for instance:

cd myproject
php -S localhost:8000

PHP pages can then be considered in a browser at http://localhost:8000.

This can be satisfactory for fast assessments, however your dwell server will use Apache or comparable internet server software program. Emulating that surroundings as intently as potential will forestall growth errors.

To put in Apache, obtain the newest Win64 ZIP file from and extract its Apache24 folder to the basis of your C: drive. You’ll additionally want to put in the Visible C++ Redistributable for Visible Studio 2015–2019 (vc_redist_x64); a hyperlink is supplied on the identical web page.

Open a cmd command immediate (not PowerShell) and begin Apache with:

cd C:Apache24bin

Chances are you’ll want to simply accept a firewall exception earlier than the server begins to run. Open http://localhost in a browser and an “It really works!” message ought to seem. Word:

  • If you must change any settings, Apache’s configuration file is positioned at C:Apache24confhttpd.conf.
  • The net server root folder is positioned at C:Apache24htdocs. Initially, it incorporates a single index.html file with the “It really works!” message.

Additionally not that, if Apache received’t begin, it’s doubtless one other utility is hogging port 80. (Skype is the prime candidate and the Home windows 10 app received’t allow you to disable it!) If this happens, edit C:Apache24confhttpd.conf and alter the road Pay attention 80 to Pay attention 8080 or some other free port. Restart Apache and, from that time onward, you possibly can load internet information at http://localhost:8080

The server could be stopped with Ctrl + C. The ReadMe file within the ZIP additionally gives directions for putting in Apache as a Home windows service.

Set up PHP

Set up PHP by following the steps under. Word that there are a number of methods to configure Apache and PHP, however that is probably the quickest methodology.

Step 1: Obtain the PHP information

Get the newest PHP 8 x64 Thread Protected ZIP package deal from https://www.php.web/downloads.php.

Create a brand new php folder within the root of your C: drive and extract the contents of the ZIP into it.

PHP could be put in wherever in your system, however you’ll want to alter the paths referenced under if C:php isn’t used.

Step 3: Configure php.ini

PHP’s configuration file is called php.ini. This doesn’t exist initially, so copy C:phpphp.ini-development to C:phpphp.ini. This default configuration gives a growth setup which reviews all PHP errors and warnings.

There are a number of strains chances are you’ll want to alter in a textual content editor (use search to seek out the present worth). Usually, you’ll must take away a number one semicolon (;) to uncomment a setting.

First, allow any required extensions. This can depend upon the libraries you need to use, however the next extensions needs to be appropriate for many functions:


If you wish to ship emails utilizing PHP’s mail() operate, enter the main points of an SMTP server within the [mail function] part (your ISP’s server needs to be appropriate):

[mail function]
; For Win32 solely.
; http://php.web/smtp
; http://php.web/smtp-port
smtp_port = 25

; For Win32 solely.
; http://php.web/sendmail-from
sendmail_from =

Step 4: Add C:php to the PATH surroundings variable

To make sure Home windows can discover the PHP executable, you must change the PATH surroundings variable. Click on the Home windows Begin button and sort “surroundings”, then click on Edit the system surroundings variables. Choose the Superior tab, and click on the Atmosphere Variables button.

Scroll down the System variables record and click on Path adopted by the Edit button. Click on New and add C:php:

Word that older editions of Home windows have a single textual content field the place every path is separated by a semi-colon (;).

Now OK your means out. You shouldn’t must reboot, however chances are you’ll want to shut and restart any cmd terminals you will have open.

Step 5: Configure PHP as an Apache module

Guarantee Apache isn’t operating and open its C:Apache24confhttpd.conf configuration file in a textual content editor. Add the next strains to the underside of the file to set PHP as an Apache module (change the file areas if crucial):

# PHP8 module
PHPIniDir "C:/php"
LoadModule php_module "C:/php/php8apache2_4.dll"
AddType utility/x-httpd-php .php

Optionally, change the DirectoryIndex setting to load index.php as an alternative of index.html when it may be discovered. The preliminary setting is:

<IfModule dir_module>
    DirectoryIndex index.html

Change it to:

<IfModule dir_module>
    DirectoryIndex index.php index.html

Save httpd.conf and take a look at the updates from a cmd command line:

cd C:Apache24bin
httpd -t

Syntax OK ought to seem … until you will have errors in your configuration.

If all went effectively, restart Apache with httpd.

Step 6: Check a PHP file

Create a brand new file named index.php in Apache’s internet web page root folder at C:Apache24htdocs and add the next PHP code:


Open an online browser and enter your server deal with: http://localhost/. A “PHP model” web page will seem displaying the varied PHP and Apache configuration settings.

Now you can create PHP websites and functions in any sub-folder of C:Apache24htdocs. If you must work on a number of initiatives, think about defining Apache Digital Hosts so you possibly can run separate codebases on completely different localhost domains or ports.

Additional data:

Better of luck!

Click to comment

Leave a Reply

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