There is a point to this story, but it has temporarily escaped my mind...
Contact Me MyFaceBook MyLinkedIn MyGitHub MyTwitter

PHP

Unfortunately, PHP and FPM under Ubuntu use the version of PHP installed to name the UNIX socket that NGINX will use to communicate with PHP so depending on the version of Ubuntu installed, the name will be different:

# Ubuntu 16.04 LTS
VERSION=7.0
 
# Ubuntu 18.04 LTS
VERSION=7.2

Install PHP and configure initial settings:

sudo apt-get -y install php$VERSION-common php$VERSION-cli php$VERSION-fpm php-apcu
 
cat > /tmp/myphpconfig.ini << EOF
cgi.fix_pathinfo=0
date.timezone = "$(cat /etc/timezone)"
expose_php = Off
default_charset = "UTF-8"
EOF
 
sudo mv /tmp/myphpconfig.ini /etc/php/$VERSION/fpm/conf.d/
 
cat > /tmp/www_local.conf << EOF
[www]
;Switch from the dynamic process manager to the ondemand manager
    pm=ondemand
 
;Bump up PHP's max_children to support more concurrent connections
    pm.max_children=8
EOF
 
sudo mv /tmp/www_local.conf /etc/php/$VERSION/fpm/pool.d

Once PHP is installed, you can test it to make sure it is installed correctly:

cat > /tmp/php-test << EOF
server {
  listen 8080;

  root /usr/share/nginx/html;

  location / { 
    index info.php;
  }

  location ~ \.php\$ {
    include fastcgi_params;
    fastcgi_pass unix:/run/php/php$VERSION-fpm.sock;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
    fastcgi_param PATH_INFO \$uri;  # necessary for URL rewrite
    fastcgi_index info.php;
  }
}
EOF

sudo mv /tmp/php-test /etc/nginx/sites-available/
sudo ln -s /etc/nginx/sites-available/php-test /etc/nginx/sites-enabled/php-test

cat > /tmp/info.php << EOF
<?php phpinfo(); ?>
EOF

sudo mv /tmp/info.php  /usr/share/nginx/html/info.php

Then restart the server for the changes to take effect.

sudo service php$VERSION-fpm restart
sudo service nginx restart

Test the PHP installation opening the info.php which should display the PHP information page. After testing, delete the file to prevent “exposing” too much information to the public about your installation.

sudo rm -f /usr/share/nginx/html/info.php
sudo /bin/rm /etc/nginx/sites-enabled/php-test
sudo /bin/rm /etc/nginx/sites-available/php-test
sudo service nginx stop


Last Updated: February 17, 2019

Copyright © 2022 by Julian Easterling. SOME RIGHTS RESERVED.
Privacy Policy              Terms of Use             


Creative Commons License
Except where otherwise noted, content on this site is
licensed under a Creative Common Attribution-Share Alike 4.0 International License.


All of the opinions expressed on this website are those of Julian Easterling and
do not represent the views of any of my current and previous clients or employers in any way.

If you notice an error on the site or content that has not been properly attributed, bring
it to my attention using the contact page and I will endeavor to fix it as soon as I can.

I accept no responsibility or liability for any damages incurred by following any of
my advice or by using any of the information on my site or of those sites that I link to.