The release of PHP7 came with several improvements for PHP. PHP is now fast, fully Object Oriented, and with better security. This guide will show you how to install PHP 7 with Composer and Apache.
Note: A common misconception is that you need a web server like IIS, Apache, or Nginx to get started with PHP7 development. PHP7 has it’s own built-in web server that you can invoke at the console.
There is a tutorial for XAMPP, should in case you want to install PHP using XAMPP.
Let’s get started.
Install PHP 7
Go to http://windows.php.net/ and DOWNLOAD the latest PHP7 (non-thread safe version) zip file. Make sure you choose the right operating system bit: VC15 x64 Non Thread Safe for 64-bit and VC15 x86 Non Thread Safe for a 32-bit operating system.
Unzip or extract the contents of the zip file into the directory C:\PHP7 ( you’re to create PHP7 folder in the C drive).
Inside C:\PHP7 directory, rename the file php.ini-development to php.ini.
Configure PHP to work flawlessly on your machine.
Open the newly renamed php.ini file on a text editor ( e.g Notepad, VSCode)
Uncomment the line that reads ; extension_dir = “ext” by removing the ; so the line is just extension_dir = “ext”. To quickly do this: CTRL F and search for extension_dir = “ext”
You also need to uncomment some bunch of extension lines by removing the ; at the beginning:
If you’re getting started with PHP, I recommend you uncomment this line ; E_ALL to E_ALL
Add C:\PHP7 to your Windows system path:
- Open your System Control Panel.
- Click ‘Advanced System Settings’.
- Click the ‘Environment Variables…’ button.
- Then click on the Path row under ‘System variables’, and click ‘Edit…’
- Click ‘New’ and add the row C:\PHP7.
- Click OK, then OK, then OK, and close out of the System Control Panel.
Photo Source: http://kizu514.com
Now open your command prompt or PowerShell and type php -v to see if PHP is working.
If yours is similar to the above, that means PHP is working correctly. Awesome!
Next, you’re going to install Composer so you can manage dependencies in PHP.
Composer is a dependency manager for PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.
Install in three 3 steps:
- Download the Windows Installer for Composer and run it. Note that the Windows Installer for Composer might ask to make changes to your php.ini file. That’s okay; allow it and continue through the setup wizard.
- Open PowerShell or Command Prompt ( Please close first if any is opened, before opening).
- Type and ENTER composer -V command to verify if Composer is installed correctly.
Awesome! You have PHP 7 and Composer running on your Windows 10 Computer.
Let’s now install Apache Web service.
Download the latest (currently version 2.4) Apache for Windows zip file: https://www.apachelounge.com/download/ . Choose the right operating system bit; Win64 for 64 bits and win32 for 32 bits system.
Extract or Unzip the content and copy the Apache24 contents to the path C:\ Apache24.
Go to the folder C:\Apache24\conf\ and open the httpd.conf file with any text editor.
Change the following lines ( by removing the # at the beginning)
#ServerName www.example.com:80 to ServerName localhost
#LoadModule rewrite_module modules/mod_rewrite.so to LoadModule rewrite_module modules/mod_rewrite.so
Save the file.
Register Apache service: Open your PowerShell or command prompt and move to C:\Apache24\bin and type httpd -k install.
Open your browser and type localhost or 127.0.0 and enter. You should see: it works.
Get PHP to work with Apache:
Inside the C:\Apache24\conf\httpd.conf modify the lines of code:
<IfModule dir_module> DirectoryIndex index.html </IfModule>
<IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
Finally add this at end of the file:
PHPIniDir “C:/PHP7” AddHandler application/x-httpd-php .php LoadModule php7_module “C:/PHP72/php7apache2_4.dll”
That is it. You just install PHP7 with Composer and Apache on your window 10 PC. If you got stuck somewhere, reply in the comment section below post.