banner



How To Install Php Ubuntu 16.04

Using PHP vii.2 on an Ubuntu dedicated server is highly recommended over previous PHP versions for several reasons, kickoff being security. Active Back up for PHP 7.2 goes until November 30th, 2022 and Security Support until Nov. 30, 2022. Older versions like vii.0 and anything 5.6 and beneath are no longer getting whatsoever support and can leave open security holes on a server if they are not replaced. Another main reason to upgrade is the large operation increase over previous versions when PHP vii.2 is installed and is using the OPcache module.  This can greatly subtract the time it takes for your spider web page to load! If yous are developing a site locally or launching it on one of Liquid Web'south Ubuntu VPS or Defended Servers, using PHP 7.2 or newer would exist the mode to become.

How to Install PHP 7.2 on Ubuntu 16.04

Pre-flying: Bank check the Server Environment

  • Right Permissions: First, make certain you lot have proper root or sudo permissions to exist able to manage the system and applications on the server. If you lot only have access to a non-root user on the system, so yous may have to get more than permissions from the server admin.
  • Existing PHP Versions: Check for an existing version of PHP. If you selected the default LAMP stack when first installing the Ubuntu image onto the server, it defaults to PHP 7.0. If you lot used a different image or did a plain install, and so you may not have whatsoever version of PHP on the server. To cheque the PHP version admission the terminal and run:
            user@test:~# php -v  PHP 7.0.30-0ubuntu0.xvi.04.ane (cli) ( NTS )          

If y'all meet an older PHP version, then you will have to install the new version and switch the version Apache connects to later. If it shows "Control php not found" then there is no PHP version currently installed.

  • Creating a Quick Fill-in: If you do have an existing PHP version, y'all may want to make a backup of whatsoever configurations earlier doing the upgrade in case in that location are problems (like if your site code wasn't compatible) and y'all need to downgrade once again. Yous can check on the current configuration directory past running:
            user@test:~# php --ini  Configuration File (php.ini) Path: /etc/php/7.0/cli  Loaded Configuration File:         /etc/php/7.0/cli/php.ini  Scan for additional .ini files in: /etc/php/7.0/cli/conf.d          

This shows the configurations are all in the /etc/php/7.0/ directory. And then if you want to make a quick fill-in, yous can run a control like:

            user@examination:~# sudo cp -a /etc/php/7.0/ /etc/php/seven.0.backup          

Too, you tin relieve a list of existing PHP modules by running:

            user@test:~# sudo cp -a /etc/php/seven.0/ /etc/php/seven.0.backup          

This can help when comparing the existing modules to the modules in PHP 7.2.

Installing PHP 7.2

The official repository for PHP on Ubuntu is from Ondřej Surý on launchpad. To add it to your organization, you lot need to run the post-obit control:

            user@test:~# sudo add-apt-repository ppa:ondrej/php          

Press enter when it prompts you to. This allows your system to utilize the repository as a source for new software. The next command grabs the list of available software packages for your organization:

            user@examination:~# sudo apt-become update          

Subsequently that you can go on with the install:

            user@test:~# sudo apt-get install php7.2          

It should bear witness several dissimilar packages that it will install and how much total disk space they will use. When it prompts you, blazon 'Y' and submit information technology. Afterwards a few moments the install should be consummate, bank check the PHP version with:

            user@test:~# php -5  PHP seven.2.13-one+ubuntu16.04.ane+deb.sury.org+1          

It should now prove PHP 7.two, but now we need to have Apache configured to utilize the newer version.

Configuring Apache to Use PHP 7.2

Ubuntu 16.04 uses a few different commands to assist manage Apache modules so the way it utilizes a specific PHP version depends on which module is loaded. Y'all can view the list of bachelor modules by running:

            user@test:~# ls /etc/apache2/mods-available/php*  /etc/apache2/mods-available/php7.0.conf  /etc/apache2/mods-available/php7.0.load  /etc/apache2/mods-available/php7.2.conf  /etc/apache2/mods-available/php7.ii.load          

Yous may have other modules as well, the default LAMP stack install would have 7.0 and the new 7.2 install nosotros just made, but running the next command shows that seven.0 is still active:

user@test:~# ls /etc/apache2/mods-enabled/php*
/etc/apache2/mods-enabled/php7.0.conf
/etc/apache2/mods-enabled/php7.0.load

To switch that to the newer 7.2 version, outset disable older PHP version:

user@exam:~# sudo a2dismod php7.0

Then enable PHP 7.2:

user@exam:~# sudo a2enmod php7.2

Earlier restarting Apache, bank check the Apache configuration syntax by running:

user@examination:~# apachectl -t
Syntax OK

If it says the syntax is OK, then restart Apache:

user@test:~# sudo service apache2 restart

Verifying Apache's PHP Version

At present to cheque your piece of work, run the previous control again to come across which module is loaded and it should show the PHP 7.two version:

user@examination:~# ls /etc/apache2/mods-enabled/php*
/etc/apache2/mods-enabled/php7.two.conf
/etc/apache2/mods-enabled/php7.two.load

If you do not see the same results as shown in the final few commands, recheck the spelling and syntax of the last few commands and make sure sudo was entered if you are not running as the root user.

Then to test it on your site, we recommend making a phpinfo file you can view on your domain. This shows the PHP version as well as information about current configurations, variables, and all the added modules. Create a new .php file in your site's home folder or in Apache's certificate root (/var/world wide web/html by default) and include this lawmaking:

<?php phpinfo(); ?>

You can tell which PHP version you are using by putting up a PHP Info page.

Then if you visit the page in the browser it should expect something similar this:

If you had a site already up and running on the previous PHP version, exam it out now and meet if at that place are any issues. If your lawmaking isn't compatible or showing errors, you can try to diagnose farther or if y'all need the site back up right away you can downgrade the PHP version over again by running the a2dismod and a2enmodcommands to disable PHP 7.2 and then enable vii.0 or whichever previous version you had on the server so restart Apache again.

Some sites may now bear witness an error proverb a module is missing and can't run, or if you are developing a new site and have a list of modules that are needed, then the adjacent department tin help you add together new modules.

Adding Modules to PHP vii.ii

The switch to PHP 7.2 doesn't automatically keep all the aforementioned modules from previous PHP versions. If yous don't need to compare the list to a previous PHP version then to install whatever basic modules you do need, starting time blazon the comannd below. But don't press enter, if y'all press the TAB key twice you should get a list of bachelor modules specific to 7.2::

@test:~# sudo apt-go install php7.2[tab][tab]

Example Output:
php7.ii php7.2-enchant php7.two-mbstring php7.two-snmp
php7.2-bcmath php7.2-fpm php7.2-mysql php7.2-soap
php7.2-bz2 php7.2-gd php7.2-odbc php7.2-sqlite3
php7.2-cgi php7.2-gmp php7.2-opcache php7.2-sybase
php7.ii-cli php7.2-imap php7.two-pgsql php7.2-tidy
php7.2-common php7.2-interbase php7.ii-phpdbg php7.2-xml
php7.2-gyre php7.2-intl php7.2-pspell php7.2-xmlrpc
php7.2-dba php7.ii-json php7.2-readline php7.2-xsl
php7.2-dev php7.2-ldap php7.ii-recode php7.2-zilch

This is not a complete list so you may need to look up how to install other modules y'all may need. You can type the modules y'all want, and yous can add together multiple in the same install command, similar:

user@exam:~# sudo apt-get install php7.two-opcache php7.ii-mbstring php-memcached

If you did save the listing of modules from a previous PHP version with the command earlier in the guide, you tin save a list of the modules in PHP 7.2 and compare them with the previous version. Run:

php -m > /tmp/7.2.modulelist.txt

And so to compare it to the listing that was created before, run:

user@examination:~# diff  /tmp/7.0.modulelist.txt /tmp/seven.ii.modulelist.txt
fifteen,16d14
< mysqli
< mysqlnd
21d18
< pdo_mysql
28d24
< soap
29a26
> sodium

Or if y'all want a more visual fashion to compare the ii lists, run:

user@test:~# vimdiff  /tmp/7.0.modulelist.txt /tmp/vii.2.modulelist.txt

Run the vimdiff command to see the modules that are different from previous PHP versions.

Which volition show a page like this in the terminal:

In this example, the various MySQL modules and soap show upward on the list of seven.0 modules on the left only are missing from the 7.2 version on the right, and the sodium module is on vii.2 but wasn't in seven.0.

So for this example, we can install the missing modules with:

user@examination:~# sudo apt-go install php7.2-mysql php7.2-lather

After that installs, nosotros can save an updated listing of modules and can compare it once more:

user@test:~# php -m > /tmp/7.2.modulelist.updated.txt
unequal /tmp/7.0.modulelist.txt /tmp/seven.2.modulelist.updated.txt
29a30
> sodium

Merely the sodium module is different betwixt the module lists, and then it is now ready for evolution! Hopefully, this guide helped with your upgrade to PHP 7.2! If you had whatsoever issues or need further help with your Liquid Web Ubuntu Server, please let our Linux Support Team know!

Source: https://www.liquidweb.com/kb/install-php-7-2-ubuntu-16-04/

Posted by: sterlingthwithis.blogspot.com

0 Response to "How To Install Php Ubuntu 16.04"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel