Ubuntu 16.04 Xenial
Serve PHP7 using PHP7-fpm and Apache 2.4
By default, in Ubuntu 16.04 Xenial, installing the packages for PHP, PHP-fpm, and Apache does not result in a working php website. The extra configuration required follows:
Install Apache2
> sudo apt-get -y install apache2
Install php, with some common packages
> sudo apt-get -y install php php-cli php-mbstring php-gd php-mcrypt php-pgsql php-mysql php-xml php-curl php-intl
Create your own apache vhost config
> vi /etc/apache2/sites-available/vhosts
<VirtualHost *:80>
ServerName tutorial.localhost
DocumentRoot /path/to/tutorial/web
SetEnv APP_ENV "dev"
<Directory /path/to/tutorial/web>
AllowOverride All
Require all granted #<-- 2.4 New configuration
</Directory>
</VirtualHost>
Enable your vhost config
> sudo a2ensite vhosts
Disable the defualt config
> sudo a2dissite 000-default
And the missing parts of conflagration:
Enable php7-fpm
> sudo a2enconf php7.0-fpm
Enable rewrite so frameworks such as Symfony, Zend, Larvel, etc work with 'pretty' urls
enable proxy so apache can send php requests to php7-fpm
> sudo a2enmod rewrite proxy proxy_fcgi
And restart apache
> sudo systemctl restart apache2
PHP should be working now
> vi /path/to/webroot/phpinfo.php
<?php
phpinfo();
End of document. Thanks for reading.