banner



How To Install Php On Windows

This article explains how to install PHP 8 and Apache ii.4 on Windows 10 (64-bit).

Linux and macOS users often have Apache and PHP pre-installed or available via package managers. Windows 10 requires a little more attempt. The steps below may work with other editions of Windows, PHP, and Apache, only check the documentation of each dependency for specific instructions.

Why PHP?

PHP remains the virtually widespread and popular server-side scripting linguistic communication in web development.

It's installed past nigh spider web hosts, and has a uncomplicated learning curve, close ties with the MySQL database, superb documentation, and an excellent drove of libraries to cut your development time.

PHP may not be perfect, but it should exist considered as an option for your adjacent spider web application. It'due south the language of choice for Facebook, Slack, Wikipedia, MailChimp, Etsy, and WordPress — the Content Management Arrangement which powers forty% of the web.

Why Install PHP Locally?

Installing PHP on your evolution PC allows you to safely create and test websites and applications without affecting the data or systems on your live server.

Alternative Installation Options

Before you jump in, there may be a simpler installation options…

Use an All-in-One package

All-in-one packages are available for Windows which comprise Apache, PHP, MySQL, and many other dependencies in a unmarried installation file — such as XAMPP, WampServer and Spider web.Developer.

These packages are easy to utilise, simply they may not exactly lucifer your live server. Installing Apache and PHP manually will help you learn more than about the system and configuration options.

Utilize a Linux Virtual Machine

Microsoft Hyper-V (provided in Windows ten Professional) and VirtualBox are free hypervisors which emulate a PC then y'all tin install another operating system.

You can install any version of Linux, then follow its Apache and PHP installation instructions. Alternatively, distros such as Ubuntu Server provide them as standard (although they're rarely the latest editions).

Apply Windows Subsystem for Linux 2

WSL2 is also a virtual car, but it's tightly integrated into Windows and then activities such equally file sharing and localhost resolution is seamless. You tin install several Linux distros, so refer to the appropriate Apache and PHP instructions.

Use Docker

Docker creates a wrapper (known as a container) around pre-configured application dependencies such as Apache, PHP, MySQL, MongoDB, and about other web software. Containers wait similar full Linux Virtual Machines just are considerably more lightweight.

Once you've installed Docker Desktop on Windows 10, it'southward easy to download, configure, and run Apache and PHP.

Docker is currently considered the best pick for setting up a PHP development surroundings. Read our complete guide to setting up a PHP evolution environment with Docker.

Install Apache (optional)

If y'all're still reading, the following sections draw how to install Apache and PHP straight on Windows.

PHP provides a built-in spider web server which can exist launched past navigating to a binder and running the PHP executable with an -Southward parameter to set the localhost port. for example:

                      cd            \myproject php -Due south localhost:8000                  

PHP pages tin can then exist viewed in a browser at http://localhost:8000.

This may be adequate for quick tests, but your live server will use Apache or like web server software. Emulating that environment as closely as possible will foreclose evolution errors.

To install Apache, download the latest Win64 ZIP file from https://world wide web.apachelounge.com/download/ and extract its Apache24 folder to the root of your C: drive. Y'all'll besides need to install the Visual C++ Redistributable for Visual Studio 2015–2019 (vc_redist_x64); a link is provided on the same page.

Open a cmd command prompt (not PowerShell) and start Apache with:

                      cd            C:\Apache24\bin httpd                  

You may demand to accept a firewall exception before the server starts to run. Open http://localhost in a browser and an "It works!" message should appear. Annotation:

  • If y'all demand to modify any settings, Apache's configuration file is located at C:\Apache24\conf\httpd.conf.
  • The spider web server root folder is located at C:\Apache24\htdocs. Initially, it contains a single index.html file with the "It works!" message.

Too non that, if Apache won't start, it'southward likely another awarding is hogging port 80. (Skype is the prime candidate and the Windows ten app won't allow you disable it!) If this occurs, edit C:\Apache24\conf\httpd.conf and alter the line Listen lxxx to Mind 8080 or any other costless port. Restart Apache and, from that point onward, you can load web files at http://localhost:8080

The server can exist stopped with Ctrl + C. The ReadMe file in the ZIP also provides instructions for installing Apache equally a Windows service.

How to Install PHP

Install PHP past following the steps beneath. Note that there are several ways to configure Apache and PHP, but this is possibly the quickest method.

Step ane: Download the PHP files

You'll demand the PHP Windows installer. There are a number of versions of PHP available. Make sure you become the latest PHP 8 x64 Thread Safe ZIP bundle from https://www.php.internet/downloads.php.

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

PHP can be installed anywhere on your system, just you'll demand to modify the paths referenced below if C:\php isn't used.

Step 3: Configure php.ini

PHP's configuration file is named php.ini. This doesn't exist initially, and then re-create C:\php\php.ini-evolution to C:\php\php.ini. This default configuration provides a development setup which reports all PHP errors and warnings.

There are several lines you may need to alter in a text editor (utilize search to observe the current value). In well-nigh cases, you'll need to remove a leading semicolon (;) to uncomment a setting.

Get-go, enable any required extensions. This volition depend on the libraries you want to apply, but the following extensions should be suitable for most applications:

          extension=ringlet extension=gd extension=mbstring extension=pdo_mysql                  

If you want to ship emails using PHP's postal service() function, enter the details of an SMTP server in the [mail function] section (your Internet service provider's server should be suitable):

          [post office] ; For Win32 only. ; http://php.net/smtp SMTP = mail.myisp.com ; http://php.net/smtp-port smtp_port = 25  ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = my@emailaddress.com                  

Step 4: Add C:\php to the path surroundings variable

To ensure Windows tin can find the PHP executable, you demand to change the PATH surround variable. Click the Windows Get-go button and type "environment", then click Edit the system environment variables. Select the Avant-garde tab, and click the Environment Variables button.

Scroll downwards the Organisation variables list and click Path followed past the Edit button. Click New and add together C:\php:

PHP path environment variable

Note that older editions of Windows take a single text box where each path is separated past a semi-colon (;).

Click OK until you're out. Yous shouldn't need to reboot, but you may demand to close and restart any cmd terminals you have open.

Stride v: Configure PHP as an Apache module

Ensure Apache isn't running and open its C:\Apache24\conf\httpd.conf configuration file in a text editor. Add the following lines to the bottom of the file to set PHP as an Apache module (alter the file locations if necessary):

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

Optionally, change the DirectoryIndex setting to load index.php instead of index.html when it can be found. The initial setting is:

          <IfModule dir_module>     DirectoryIndex index.html </IfModule>                  

Alter it to:

          <IfModule dir_module>     DirectoryIndex alphabetize.php alphabetize.html </IfModule>                  

Save httpd.conf and exam the updates from a cmd command line:

                      cd            C:\Apache24\bin httpd -t                  

Syntax OK should appear … unless you have errors in your configuration.

If all went well, restart Apache with httpd.

Step half-dozen: Exam a PHP file

Create a new file named index.php in Apache's web page root binder at C:\Apache24\htdocs and add the following PHP code:

                                    <?php              phpinfo              (              )              ;              ?>                              

Open up a web browser and enter your server address: http://localhost/. A "PHP version" page will appear showing the various PHP and Apache configuration settings.

You tin can at present create PHP sites and applications in any sub-folder of C:\Apache24\htdocs. If yous need to piece of work on multiple projects, consider defining Apache Virtual Hosts and so you lot can run split codebases on different localhost domains or ports.

Further data:

  • How to Install Apache
  • How to Install MySQL
  • MySQL: the Pros and Cons of MyISAM Tables
  • MySQL: the Pros and Cons of InnoDB Tables
  • How to Employ MySQL Strange Keys for Quicker Database Development
  • Book: PHP & MySQL: Novice to Ninja, 6th Edition
  • Book: Jump First PHP Surroundings, also as many more books in our library.

If you're more comfortable with Linux, you lot might prefer to set up your PHP surround under Windows Subsystem for Linux ii. Cheque out our WSL2 guide and in-depth Windows Terminal tutorial for more than.

How To Install Php On Windows,

Source: https://www.sitepoint.com/how-to-install-php-on-windows/

Posted by: fosterager1944.blogspot.com

0 Response to "How To Install Php On Windows"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel