How to install PHP on Ubuntu Linux using terminal commandline

How to install PHP on Ubuntu Linux using terminal commandline. PHP stands for Hypertext Preprocessor (no, the acronym doesn’t follow the name). It’s an open source, server-side, scripting language used for the development of web applications. PHP is script-based (lines of code) program written for the automation of tasks.

Note that HTML is that HTML is a front-end language that runs on the browser, while PHP is back-end and runs on the server.

Installing PHP 7.4 with Apache

sudo apt upgrade
sudo apt update
sudo apt install php libapache2-mod-php
apt-get install php5-common libapache2-mod-php5 php5-cli
sudo systemctl restart apache2

You can also run the following commands for stopping and starting Apache once PHP is installed:

# /etc/init.d/apache2 stop
# /etc/init.d/apache2 start

Installing PHP 7.4 with Nginx

sudo apt upgrade
sudo apt update
sudo apt install php-fpm
systemctl status php7.4-fpm
sudo systemctl restart nginx

You can also install PHP with MySQL, cURL using the following command:

sudo apt upgrade
sudo apt update
sudo apt-get install php5-mysql php5-curl

APT will automatically add the appropriate lines to the different php.ini related files like /etc/php5/apache2/php.ini, /etc/php5/conf.d/pdo.ini, etc. and depending on the extension will add entries similar to extension=foo.so. However, restarting the web server (like Apache) is required before these changes take affect.

Installing PHP extensions

Once PHP is installed, users can also install PHP extensions compiled libraries such as MySQL and GD extensions and many more:

sudo apt install php-[extname]
sudo apt install php-mysql php-gd

After installing a new PHP extension, you miust restart Apache or PHP service.

NOTE:

  1. If the PHP scripts are not parsing via the web server, then it’s likely that PHP was not added to the web server’s configuration file, which on Debian may be /etc/apache2/apache2.conf or similar. See the Debian manual for further details.
  2. If an extension was seemingly installed yet the functions are undefined, be sure that the appropriate ini file is being loaded and/or the web server was restarted after installation.
  3. There are two basic commands for installing packages on Debian (and other linux variants): apt-get and aptitude. However, explaining the subtle differences between these commands goes beyond the scope of this manual.

How to install PHP on Ubuntu Linux using terminal commandline originally posted on Source Digit – Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos.