PHP / PHP-FPM ( 7 .2.10 ) Released — Here’s How to Install / Upgrade on Ubuntu 16.04 | 18.04

PHP / PHP-FPM 7.2.10 was recently released which includes few bug fixes… This brief tutorial shows students and new users how to install or upgrade PHP /  PHP-FPM on Ubuntu 16.04 | 18.04 LTS servers…

If you’re going to be developing any PHP application, you’re mostly going to need PHP and related modules installed. PHP / PHP-FPM  is an open source server scripting language use for creating dynamic web applications and websites.

PHP / PHP-FPM is a widely-used, free, and efficient alternative to competitors such as Microsoft’s ASP…. Most popular content management systems like WordPress, Joomla, Drupal use PHP or PHP-FPM to function….

For more about this release, please check its changelog page….

PHP is used with Apache2 HTTP server
PHP-FPM is used with Nginx HTTP server

When you’re ready to set up PHP with Apache2 or PHP-FPM with Nginx, follow the steps below:

Below is  a list of some of the bug fixes with this release:

  • Core:
    • Fixed bug (parent private constant in extends class memory leak).
    • Fixed bug (Generate enabled extension).
    • Fixed bug (Memory leak when using class_alias() in non-debug mode).
  • Apache2:
    • Fixed bug (Apache bucket brigade sometimes becomes invalid).
  • Bz2:
    • Fixed arginfo for bzcompress.
  • gettext:
    • Fixed bug (incorrect restoring of LDFLAGS).
  • iconv:
    • Fixed bug (iconv_mime_decode can return extra characters in a header).
    • Fixed bug (iconv_mime_decode_headers function is skipping headers).
    • Fixed bug  (iconv_mime_decode does ignore special characters).
    • Fixed bug (iconv_mime_decode_headers() skips some headers).
  • intl:
    • Fixed bug (MessageFormatter::formatMessage memory corruption with 11+ named placeholders).
  • libxml:
    • Fixed bug (“public id” parameter of libxml_set_external_entity_loader callback undefined).
  • mbstring:
    • Fixed bug (mb_detect_order return value varies based on argument type).
  • Opcache:
    • Fixed bug (Opcache treats path containing “test.pharma.tld” as a phar file).
  • OpenSSL:
    • Fixed bug (unusable ssl => peer_fingerprint in stream_context_create()).
  • phpdbg:
    • Fixed bug (phpdbg man page contains outdated information).
  • zlib:
    • Fixed bug (Zlib version check fails when an include/zlib/ style dir is passed to the –with-zlib configure option).
    • Fixed bug (Minimal required zlib library is 1.2.0.4).

Step 1: Setup PHP with Apache2 HTTP Server

To use PHP with Apache2 HTTP server, you should first install Apache2… To do that, run the commands below:

sudo apt update
sudo apt install apache2

After installing Apache2, the commands below can be used to stop, start and enable Apache2 service to always startup when the server boots up.

sudo systemctl stop apache2.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service

Step 2: Install PHP 7.2 with Apache2 Support

PHP 7.2 may not be available in Ubuntu default repositories… in order to install it, you will have to get it from third-party repositories.

Run the commands below to add the below third party repository to upgrade to PHP / PHP-FPM 7.2

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php

Then update and upgrade to PHP 7.2

sudo apt update

Next, run the commands below to install PHP 7.2 and related modules.

There are many PHP modules that perform different functions…. however, these are some popular ones that may be needed when developing PHP based websites…

sudo apt-get install php7.2 libapache2-mod-php7.2 php7.2-cli php7.2-mysql php7.2-gd php7.2-imagick php7.2-recode php7.2-tidy php7.2-xmlrpc

The line above will allow PHP to function with many popular PHP based websites and applications.

Step 3: Configure PHP 7.2 for Apache2

Now that Apache2 and PHP are installed, you may want to configure Apache2 to use PHP properly. The default Apache2 PHP configuration file is located at /etc/php/7.2/apache2/php.ini

Open PHP Apache2 configuration file by running the commands below

sudo nano /etc/php/7.2/apache2/php.ini

Then edit the file to suit your environments. Some important lines to consider:

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 64M
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Next, lookup Apache2 dir.conf file and confirm the line below:

<IfModule mod_dir.c>
     DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

If you don’t see the index.php definition on the line, please add it and save the file.

Restart Apache2 and PHP services

sudo systemctl restart apache2.service

Step 1: Setup PHP-FPM with Nginx HTTP server

To use PHP-FPM with Nginx HTTP server, you should first install Nginx… To do that, run the commands below:

sudo apt update
sudo apt install nginx

After installing Nginx, the commands below can be used to stop, start and enable Nginx service to always startup when the server boots up.

sudo systemctl stop nginx.service
sudo systemctl start nginx.service
sudo systemctl enable nginx.service

Step 2: Install PHP-FPM 7.2 for Nginx

If you’re running Nginx then the commands below should get PHP-FPM and related modules installed….

There are many PHP-FPM modules that perform different functions…. however, these are some popular ones that may be needed when developing PHP based websites…

sudo apt-get install php7.2-fpm php7.2-cli php7.2-mysql php7.2-gd php7.2-imagick php7.2-recode php7.2-tidy php7.2-xmlrpc

The line above will allow PHP to function with many popular PHP based websites and applications.

Step 3: Configure PHP-FPM for Nginx

Now that Nginx and PHP-FPM are installed, you may want to configure Nginx to use PHP-FPM properly. The default Nginx PHP-FPM configuration file is located at /etc/php/7.2/fpm/php.ini

Open PHP Apache2 configuration file by running the commands below

sudo nano /etc/php/7.2/fpm/php.ini

Then edit the file to suit your environments. Some important lines to consider:

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 64M
cgi.fix_pathinfo = 0
upload_max_filesize = 100M
max_execution_time = 360
date.timezone = America/Chicago

Save the file and exit….

Restart Nginx and PHP-FPM

sudo systemctl restart nginx.service
sudo systemctl restart php7.2-fpm

At this point Apache2 or Nginx with PHP or PHP-FPM should be installed and ready to use.. you can test  PHP / PHP-FPM settings by creating a blank file…..

sudo nano /var/www/html/phpinfo.php

Then add the line in the file and save.

<?php phpinfo( ); ?>

Save the file and open your browser and browse to the server name or IP address followed by phpinfo.php

You should see something similar to the image below… if you do, then you’re all good!

php loaded configuration file

Enjoy!

Congratulations! You’ve successfully installed and configured Apache2 / Nginx with PHP / PHP-FPM support on Ubuntu servers

You may also like the post below:

Contao 4.6.0 Released — Here’s How to Install / Upgrade on Ubuntu 16.04 / 18.04 LTS

One Reply to “PHP / PHP-FPM ( 7 .2.10 ) Released — Here’s How to Install / Upgrade on Ubuntu 16.04 | 18.04”

  1. Oh excuse me … I typed “Windows” AND Laravel… freaking multiple times so why am I being driven to a fvcking Ubuntu site? These GDamn “extra’ libs should be included with Laravel anyway. It’s a damn framework, so those things should be overloaded with crap people don’t need anyway. At least mine is — except for these dam “GD” libs” … that I freakin’ apparently DO need to create a simple thing like a PD-freaking-F. I can do it almost as quickly in PHP code as I can trying to find out how to install and mitigate this kinda crap.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: