Install PHP 7.2 on Ubuntu
PHP 7.2 stable version has been released. Use the following set of commands to enable PPA for PHP 7.2 in your Ubuntu system and install it. You can use this version for production use also.
Now use the following command to check installed php version on your system.
Install PHP 7.1 on Ubuntu
Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install PHP 7.1 version.
Now use the following command to check installed php version on your system.
Install PHP 7.0 on Ubuntu
Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install PHP 7.0 version.
Now use the following command to check installed php version on your system.
Install PHP 7 Modules
You may also need to install modules based on your application requirements. Use the following command to search available PHP 7 modules in the package repository.
You can install the required PHP modules on your system as below command. Make sure to install packages for correct PHP version by specifying the version with the package name. Without defining package version, it will install the latest package.
Install PHP 7.0 modules
You may need some additional packages and PHP modules in order for PHP to work with your applications. You can install the most commonly needed modules with:
apt-get install php-pear php7.0-dev php7.0-zip php7.0-curl php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-xml libapache2-mod-php7.0
Install PHP 7.2 modules
You may need some additional packages and PHP modules in order for PHP to work with your applications. You can install the most commonly needed modules with:
apt-get install php-pear php7.2-dev php7.2-zip php7.2-curl php7.2-gd php7.2-mysql php7.2-mcrypt php7.2-xml libapache2-mod-php7.2
How to change the PHP version you’re using
If you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one.
To set PHP 7.0 as the default, run:
update-alternatives --set php /usr/bin/php7.0
To set PHP 7.2 as the default, run:
update-alternatives --set php /usr/bin/php7.2
If you’re following our LAMP tutorials and you’re using Apache, you can configure Apache to use PHP 7.2 with the following command:
a2enmod php7.2
And then restart Apache for the changes to take effect:
systemctl restart apache2
Speed up PHP by using an opcode cache
You can improve the performance of your PHP by using a caching method. We’ll use APCu, but there are other alternatives available.
If you have the ‘php-pear’ module installed (we included it in our instructions above), you can install APCu with the following command:
pecl install apcu
There are also other ways you can install APCu, including using a package.
To start using APCu, you should run the following command for PHP 7.2:
echo "extension=apcu.so" | tee -a /etc/php/7.2/mods-available/cache.ini
And the following command for PHP 7.0:
echo "extension=apcu.so" | tee -a /etc/php/7.0/mods-available/cache.ini
If you’re following our LAMP tutorials and you’re using Apache, create a symlink for the file you’ve just created.
For PHP 7.2:
ln -s /etc/php/7.2/mods-available/cache.ini /etc/php/7.2/apache2/conf.d/30-cache.ini
For PHP 7.0:
ln -s /etc/php/7.0/mods-available/cache.ini /etc/php/7.0/apache2/conf.d/30-cache.ini
And finally, reload Apache for the changes to take effect:
systemctl restart apache2
It was a nice post. I would like you to see my blog post on the same topic here https://decodeweb.in/php/how-do-i-install-php-in-my-computer/
ResponderEliminarPlease give suggestions too.