Home » guide » Setup PHP on NGINX

Setup PHP on NGINX

Setup PHP

  1. Add the below software and repository
    > sudo apt-get install software-properties-common
    > sudo add-apt-repository ppa:ondrej/php
    > sudo apt-get update
  2. Install PHP 7.1
    > sudo apt-get install php7.1
  3. Install common PHP modules
    > sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm
  4. Edit the php.ini file
    > sudo vi /etc/php/7.1/cli/php.ini
  5. in the php.ini file type /cgi. and hit enter to find the below line and edit
    cgi.fix_pathinfo=0
  6. Restart the PHP 7.1 service
    > sudo service php7.1-fpm restart
  7. Edit the NGINX config to enable PHP
    > sudo vi /etc/nginx/sites-enabled/default
    Remove the comments from the below php settings
  8. Restart nginx service
    > sudo service nginx restart
  9. Enable PHP and nginx to start on reboot
    > sudo systemctl enable nginx.service
    > sudo systemctl enable php7.1-fpm.service