What is PHP?
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
What distinguishes PHP from something like client-side JavaScript is that the code is executed on the server, generating HTML which is then sent to the client. The client would receive the results of running that script, but would not know what the underlying code was. You can even configure your web server to process all your HTML files with PHP, and then there's really no way that users can tell what you have up your sleeve.
The best part about using PHP is that it is extremely simple for a newcomer, but offers many advanced features for a professional programmer. Don't be afraid to read the long list of PHP's features. You can jump in, in a short time, and start writing simple scripts in a few hours.
How to install it
Depending on your operating system there are a few ways to install PHP and get started. Here are the simplest ways:
Windows
- Head to php.net
- Click Download button
- Click Windows Downloads
- Download Thread safe 32/64 bit zip package for your system type
- Extract the zip package
- Paste the extracted folder onto your desired drive (C?D?E?)
- Rename this folder to php8
- One this folder and look for php.ini-development file
- Make a copy of this file and rename copy version to php.ini
- Open php.ini file with your preferred text editor and uncomment PHPIniDir “ext”
- Save the file and close the editor.
Afterward you will need to add it to the system's PATH.
- Open php8 folder and copy and folder path
- Press Windows Key on your keyboard and type 'variable' and hit Enter
- Click Environment Variables
- Click Edit and Click NEW on the right
- Paste the php8 folder path
- Click OK, OK, OK
Next, open up a terminal window ( command prompt ) and type: php -v.
This command should output the version of PHP you have installed. You are now ready to go.
Mac OSx
First step for mac os users is to make sure you have "Homebrew" package manager installed. To check that, open up a terminal window and type brew -v.
If a version shows up, Homebrew is installed. If it is not, paste the following command in your terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
The second step is actually installing PHP using brew. In the same terminal window type:
brew install php
This command will install the latest version of PHP on your system.
To check if everything was in order, type php -v in your terminal and the outcome should be the current version installed. It is now ready to use.
Debian, ubuntu
First step is to make sure the package repos are up to date and the system is up to date:
sudo apt update
sudo apt upgrade
After that proceed to install the required dependencies, add the apt repository and add the GPG key:
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
wget -qO - https://packages.sury.org/php/apt.gpg | sudo apt-key add -
sudo apt update
sudo apt install php8.0
And that is it. PHP is now ready to use on your system. Type in php -v to check if it was properly installed and ready to use.