<\/span><\/h2>\nCentOS 7 by default is shipped with PHP 5.4 at the time of writing this article, which is a very old and outdated version and it has reached its end of life in September 2015. This also adds security vulnerabilities onto your server if you use PHP in a web setting. Luckily, some trusted and well-maintained repositories offer newer versions of PHP. In this case we will install and use PHP 7.3 from the Remi repository.<\/p>\n
First of all, check if PHP is already installed on your server. If it is installed, check what version your server is running. You can do it with the following command:<\/p>\n
# php -v<\/pre>\nOutput:<\/p>\n
PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)\r\nCopyright (c) 1997-2013 The PHP Group\r\nZend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies<\/pre>\nAccording to the output, PHP 5.4 is installed on our CentOS VPS, which we mentioned that it is the latest available version in the CentOS 7 repositories. In order to install PHP 7.3, we have to remove this version:<\/p>\n
yum remove php*\r\n\r\nRemoving:\r\n php \r\n php-cli \r\n php-common\r\n php-mysql \r\n php-pdo<\/pre>\nThis command will remove PHP and all installed PHP extensions.<\/p>\n
Run the following commands to add the Remi and Epel repositories to your server, and install yum-utils, which is a collection of tools for managing yum repositories:<\/p>\n
yum install http:\/\/rpms.remirepo.net\/enterprise\/remi-release-7.rpm\r\nyum install yum-utils epel-release<\/pre>\nDisable the PHP 5.4 repository, which is enabled by default:<\/p>\n
yum-config-manager --disable remi-php54<\/pre>\nand enable the PHP 7.3 repository:<\/p>\n
yum-config-manager --enable remi-php73<\/pre>\nAfter the Remi repository for PHP 7.3 is enabled, we can easily install it with the yum package manager.<\/p>\n
yum -y install php\r\n\r\nInstalling:\r\n php \r\nInstalling for dependencies:\r\n libargon2 \r\n php-cli \r\n php-common \r\n php-json<\/pre>\nIt will install PHP 7.3 and some of its dependencies, as shown in the output above.<\/p>\n
Once the installation is completed, you can check the installed PHP version:<\/p>\n
php -v\r\n\r\nOutput:<\/pre>\nPHP 7.3.0RC5 (cli) (built: Nov 6 2018 10:22:47) ( NTS )\r\nCopyright (c) 1997-2018 The PHP Group\r\nZend Engine v3.3.0-dev, Copyright (c) 1998-2018 Zend Technologies<\/pre>\nYou can easily install all necessary PHP extensions using the same way, as long as they are available in the repository. For example, if you need the MySQL, Multibyte String (mbstring), Mcrypt and the SimpleXML Parser PHP extensoins, you can install them with the following command:<\/p>\n
yum -y install php-mysqlnd php-mbstring php-pecl-mcrypt php-xml<\/pre>\nYou can test if the extensions is properly installed using the following command:<\/p>\n
php -m |grep extension_name<\/pre>\nFor example, to test if the Multibyte String (mbstring) extension is installed, you can use the following:<\/p>\n
php -m |grep mbstring<\/pre>\noutput:<\/p>\n
mbstring<\/pre>\n