Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
Prerequisites
3.
PHP on Linux
4.
PHP on Windows
4.1.
Step 1: Download PHP files
4.2.
Step 2: Extract files
4.3.
Step 3: Configure php.ini
4.4.
Step 4: Add C:\php path to the environment variable
4.5.
Step 5: Configure PHP as Apache module
5.
PHP on macOS
6.
Frequently Asked Questions
7.
Key Takeaways
Last Updated: Mar 27, 2024

PHP Installation

Author Abhay Trivedi
0 upvote

Introduction

PHP is a backend scripting language used for web development. It is an open-source, interpreted server-side scripting language and supports object-oriented programming. This article sees how to download and install PHP on your preferred OS.

Prerequisites

Before installing PHP, there are some requirements you need to fulfill. Luckily they are relatively basic and already fulfilled by your system.

Here are the PHP prerequisites for Linux:

  • Add an ANSI C compiler.
  • You should have Module-specific components like GD graphics libraries or PDF libraries.
  • Optional Additions: Autoconf 2.59+ (for PHP versions < 7.0), Automake 1.4+, Autoconf 2.64+ (for PHP versions > 7.2), Libtool 1.4+, re2c 0.13.4+, and Bison.

Now the PHP requirements for Windows:

  • PHP supports Multiple Windows OS on PHP 5.5+, but 7.2.0+ users cannot use Windows 2008 or Windows Vista.
  • Visual C Runtime (CRT).
  • Depending on your PHP version, Visual Studio 2012, 2015, 2017, or Microsoft Visual C++ Redistributable for Visual Studio 2019.

There are no prerequisites for macOS since PHP comes bundled with the system.

PHP on Linux

Firstly, make sure that your packages are up to date. Run this command in the Terminal to check. 

sudo apt-get update && sudo apt-get upgrade

Now to install PHP, run the command below to do so effortlessly.

sudo apt-get install php

It would install the latest version of PHP along with several extensions. To see your current version, run the following code.

php –v

PHP on Windows

Step 1: Download PHP files

Go to https://www.php.net/downloads.php and install the latest PHP 8 x64 Thread Safe ZIP package.

Step 2: Extract files

Please create a new PHP folder in the root of your C:\ drive and extract the ZIP into it.

You can install PHP anywhere on your system, but you'll need to change the paths referenced below if you do not use C:\php.

Step 3: Configure php.ini

PHP’s configuration file is php.ini. Copy C:\php\php.ini-development to the C:\php\php.ini

Firstly, enable any required extensions.

extension=gd
extension=curl
extension=mbstring
extension=pdo_mysql

To send emails using PHP's mail() function:

[mail function]
; 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 = email@domain.com

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

Click the Windows Start button, type "environment," then click Edit the system environment variables. On the Advanced tab, click the Environment Variables button.
 

Go to the System variables list and click Path, followed by the Edit button. Click New and add C:\php.

Step 5: Configure PHP as Apache module

Add the following lines to the bottom of the file to set PHP as an Apache module.

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

PHP on macOS

Most macOS systems come preinstalled with PHP, so you usually don't need any manual installation.

To enable Apache, go to /private/etc/apache2/httpd.conf and uncomment the following files

# LoadModule php5_module libexec/httpd/libphp5.so
# AddModule mod_php5.c

If you need to download PHP manually, run:

brew install php

To check the version of your PHP version, run:

php –v

Must Read PHP Projects With Source Code

Frequently Asked Questions

  1.  What is PHP?

PHP is a backend scripting language used for web development. It is an open-source, interpreted server-side scripting language and supports object-oriented programming.

2.  What are the advantages of using PHP?

There are many advantages of using PHP over other languages. PHP is a server-side scripting language suited for creating dynamic web pages. It is highly flexible and provides compatibility and easy integration. It provides efficiency in performance and is cost-efficient. 

3.  Can you replace PHP with Python?

Yes, you can use both PHP and Python for backend development. But it is tough to compare two programming languages. Because the significant reason for this is there are always going to be cases in which one will be a way better option than the other.

Key Takeaways

This article teaches about PHP Installation. We saw why it could be beneficial for a developer to learn. Click here to read about PHP Interview Questions.

Recommended Readings:


Click here to see other related blogs on PHP.

Also, check out our web development course and blogs on Backend Web Technologies.

If you are preparing for your DSA interviews then, Coding Ninjas Studio is a one-stop destination. This platform will help you acquire effective coding techniques and overview student interview experience in various product-based companies.

Live masterclass