How do i download php from terminal?

PHP installation is required for command line use only


A. Windows 

Follow instructions at noted here 

  1. Download PHP 7.2.28
  2. Unzip and rename the folder to PHP
  3. Move PHP folder to C:/
  4. Add new Environment Variables for PHP
  5. Restart computer
  6. Test PHP on terminal/command prompt

B. Mac OS

Recent versions of Mac OS already ship with php7.2.x+


C. Linux

Install with root privileges 

On Debian/Ubuntu see article here

# Only the following items are needed for foldershare client
apt-get install php7.2-cli php7.2-curl php7.2-mbstring

On CentOS

yum -y install centos-release-scl.noarch
yum search php72-
yum install rh-php72-php-cli.x86_64
yum install rh-php72-php-mbstring.x86_64

Building minimal PHP from source

Download latest PHP7.2.x then unzip and build as follows 

# Fetch php7.2.28 source
curl -o php-7.2.28.tar.gz -L http://php.net/get/php-7.2.28.tar.gz/from/this/mirror

# untar php source
tar xzf php-7.2.28.tar.gz

cd php-7.2.28

# Configure php for minimal build that we need for the FolderShare client
# Optionally add --prefix=/path/to/install
./configure --disable-all --disable-cgi --enable-cli --enable-filter --enable-json --enable-mbstring --with-curl --with-readline 

# build
make
# make install #if you added prefix

# Add environment path to find php
export PATH=`pwd`/sapi/cli:$PATH" #change this path if you added prefix

# Check if php is now in environment path
php -v

# Consider adding the php path in your shell profile (e.g. basic)

Add environment path

After installing PHP, add php to your environment path for e.g. append the following to your ~/.bashrc

export PATH="/full/path/to/php:$PATH"

Introduction

PHP stands for Hypertext Preprocessor, and it’s a script-based server-side programming language.

PHP is often used to automate server tasks. It handles tasks like dynamic content, database requests, and processing and displaying data.

Read our tutorial on how to install PHP 7.4 and 8.0 on Ubuntu 18.04 or 20.04 including integration with Apache and Nginx.

How do i download php from terminal?

Prerequisites

  • A Linux system running Ubuntu 18.04 or 20.04
  • Access to an Ubuntu user account with sudo privileges
  • Access to a command line/terminal window (Ctrl-Alt-T)
  • A running web server (Apache or Nginx)

Installing PHP on Ubuntu

Like many developer tools, PHP has several different release versions. At the time of writing, PHP 7.4. and 8.0 are the currently supported versions of the software.

1. Install PHP with Apache on Ubuntu

If you are running an Apache web server, you want to install PHP with the Apache module. Below you will find installations for PHP 7.4 and PHP 8.0.

1. Ensure you are using the latest Ubuntu updates by entering the following command into a terminal window:

sudo apt update && sudo apt upgrade

2. Install software-properties-common to help you manage distributions and independent software sources:

sudo apt install software-properties-common

3. Next, add the ondrej/php PPA which provides all the latest releases of PHP for Ubuntu 18.04:

sudo add-apt-repository ppa:ondrej/php

4. Update the repository to include the new packages:

sudo apt update

5. Now you can install PHP.

  • To install PHP 7.4, run the command:
sudo apt -y install php7.4
  • To install PHP 8.0, run:
sudo apt -y install php8.0

Note: The command for installing PHP 8.0 should automatically install the PHP module for Apache 2. If it fails to do so, run the following command instead: sudo apt -y install php8.0 libapache2-mod-php8.0.

6. Verify the installation with:

php -v

The output should display the PHP version you installed. If you installed version 7.4, the output appears as in the image below.

How do i download php from terminal?

If you installed PHP 8.0, the output shows:

How do i download php from terminal?

2. Install PHP with Nginx on Ubuntu

If you are using an Nginx server instead of Apache, follow the steps below to install PHP 7.4 or 8.0 to work with Nginx.

  1. Enter the following command into a terminal window to ensure you are using the latest software:
sudo apt update && sudo apt upgrade

. 2. To install PHP for Nginx, use one of the following commands:

  • For PHP 7.4:
sudo apt install php7.4-fpm
  • For PHP 8.0:
sudo apt install php8.0-fpm

The system will reach out to download and install the package and its dependencies.

How do i download php from terminal?

2. Once the installation finishes, restart the service to apply the changes by entering:

sudo systemctl restart nginx

3. Next, you need to enable PHP support by editing the server block. Open the server block with the command:

sudo nano /etc/nginx/sites-available/default

4. Add the following code to your server block file for Nginx to make use of PHP:
server

# . . . existing configuration

location ~ \.php$ {

include snippets/fastcgi-php.conf;

fastcgi_pass unix:/run/php/php8.0-fpm.sock;

}

}

4. Save the file and exit.

5. Finally, restart Nginx on Ubuntu and reload PHP:

sudo systemctl restart nginx
sudo systemctl reload php[version_number]-fpm

Installing PHP Modules on Ubuntu

To install additional PHP modules, use the following syntax:

sudo apt install php[version_numeber]-[package_name]

You can also install multiple modules at once. For example, to install modules mysql, zip, json, common, and bcmath on PHP 7.4, you would run:

sudo apt install php7.4-{mysql,zip,json,common,bcmath}

To list all loaded PHP modules run the command:

php -m

The output lists all compiled PHP modules, as in the example below.

How do i download php from terminal?

Conclusion

After reading this article, you should have successfully installed PHP 7.4 or 8.0 with Apache or Nginx on your Ubuntu 18.04 and 20.04 system.

One important thing to remember is that PHP works in tandem with an existing server, so you need to install it specifically to your server software. Alternatively, you can always install a stable version from the default Ubuntu software repositories.

How do I download PHP on Mac terminal?

Install PHP on macOS Monterey.
brew --version. Installing PHP. ... .
brew install php. This will take a while and will produce some output in the Terminal window. ... .
command -v php. The command should display something like..
/usr/local/bin/php. or..
/opt/homebrew/bin/php. ... .
#!/usr/bin/env php. ... .
b) You can include inline scripts in expansions..

How do I manually download PHP?

Step 1: Visit https://www.php.net/ website using any web browser and click on Downloads..
Step 2: Click on the Windows “Downloads” button. ... .
Step 7: Now paste the copy folder in your windows drive in the Program files folder. ... .
Step 12: Now go to the “System variables” Path option and double click on Path..

How do I download and install PHP?

Install PHP on Windows manually You have to download zipped binary version of PHP from http://www.php.net/downloads.php. Extract the downloaded file to php folder which must be created at the root of any of your windows drives (e.g. c:\php or d:\php). Enter php folder and rename the file php. ini-recommonded to php.

What is the command to install PHP?

How to Install PHP.
Step 1: Download the PHP files. You'll need the PHP Windows installer. ... .
Step 2: Extract the files. ... .
Step 3: Configure php. ... .
Step 4: Add C:\php to the path environment variable. ... .
Step 5: Configure PHP as an Apache module. ... .
Step 6: Test a PHP file..