MasterServerBlog › how-to-install-php

How to Install PHP on Linux

← all articles

PHP is probably the most popular programming language used to build modern websites, scripts and other applications.
Its main competitors are Python and PERL.

Key advantages:

  • The PHP programming language is completely free and open source — there is no license to buy.
  • Code is written very quickly with it. The language was originally designed for rapid development of web applications. It is worth mentioning that many good PHP-based frameworks and platforms exist: Joomla, WordPress, CodeIgniter, Laravel and others.
  • Good compatibility with all operating systems and browsers: Microsoft Windows, Linux, MacOS, Android, IOS. It works with Apache, Microsoft IIS, Netscape, and with databases such as MySQL, PostgreSQL and others.
  • Free updates and support. Even after an update, experienced developers adapt easily to the new PHP version.

The main downside, however, is that many unqualified people offer website and software development services in this language. That is simply because the language is fairly simple, convenient, free, universal and widespread.

 How to install PHP on a Linux server

  1. With a single mouse click via a control panel (if one is installed on the server);
  2. By entering a special command in the console as the root user.

Installing PHP 7 on CentOS

Before installing, add two repositories, EPEL and REMI
# yum install epel-release
# rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Now install PHP itself
# yum install php72

Installing PHP 7 on Debian / Ubuntu

Likewise, add the required package source and update it
# sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
# sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
# sudo apt update

Now install PHP 7.1
# sudo apt install php7.1-common php7.1-readline php7.1-fpm php7.1-cli php7.1-gd php7.1-mysql php7.1-mcrypt php7.1-curl php7.1-mbstring php7.1-opcache php7.1-json

 How to check the PHP version

Enter this command in the console
# php -v

or:
# php72 -v

or:
# php72 -r "phpinfo();" | grep "PHP Version"