Comments on Using PHP-FPM with Apache on Ubuntu 16.04
This tutorial shows how to install an Apache webserver on an Ubuntu 16.04 server with PHP 7 (through PHP-FPM) and MySQL support. PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation with some additional features useful for sites of any size, especially busier sites.
26 Comment(s)
Comments
This part seems pretty empty to me :-)
Next we have to adjust a setting in the php.ini file. Open /etc/php/7.0/fpm/php.ini with the nano editor:
nano /etc/php/7.0/fpm/php.ini
apache wont start with the conf file you typed "... and put the following section somewhere between <VirtualHost></VirtualHost>:"
SetHandler need to change to AddHandler?
And after all processed, my server api is sill Apache 2.0 Handler. totally not work.
The config from the tutorial works fine here, just checked that again. There must be a typo in your config, the apache log shows you which line is wrong in your config. And yes, it has to be SetHandler and not AddHandler.
Yes you need to change to AddHandler, and then also (as seen here http://blog.koenreiniers.nl/guide-to-combining-apache-virtual-hosts-and-php7-fpm/ - I didnt need to do all the user stuff, just followed this guide and snagged the snippet below to my 000-default.conf)
You need to instruct apache to use it for PHP files:
<IfModule mod_fastcgi.c>
<FilesMatch ".+\.ph(p[345]?|t|tml)$">
SetHandler php7-fcgi
</FilesMatch>
</IfModule>
This worked for me on a fresh Xenial install as of March 2017
Thank you for making this tutorial. There seems to be very little on the web about making FPM work with PHP 7. Having said that, I am having trouble getting my PHP7 install to work with FPM on Apache 2.4 (on Ubuntu 16.04 LTS). I have followed your instructions. I have placed the AddHandler part of the config in /etc/apache2/conf-available/php7.0-fpm.conf file, which is being symlinked via the conf-enabled directory. As far as I can tell, it is being properly scanned. I placed the SetHandler part of the config (the second block in your example) in the /etc/apache2/sites-available/000-default.conf file as you instructed. However, having done this I cannot restart the apache server without an error. Running systemctl status apache2.service gives the following results:
liverpool apache2[3182]: AH00526: Syntax error on line 34 of /etc/apache2/sites-enabled/000-default.conf:liverpool apache2[3182]: SetHandler takes one argument, a handler name that overrides any other configured handlerliverpool apache2[3182]: Action 'configtest' failed.liverpool apache2[3182]: The Apache error log may have more information.liverpool systemd[1]: apache2.service: Control process exited, code=exited status=1liverpool systemd[1]: Failed to start LSB: Apache2 web server.liverpool systemd[1]: apache2.service: Unit entered failed state.liverpool systemd[1]: apache2.service: Failed with result 'exit-code'.
Can you help me?
Allen above is correct about the wrong command in the example in step 5. After the comment...
and put the following section somewhere between <VirtualHost></VirtualHost>
...it should read:
AddHandler php7-fcgi .php
And not
SetHandler php7-fcgi .php
Using SetHandler instead of AddHandler in the 000-default.conf worked form me. Thanks Superuser!
Needs
a2enmod actions fastcgi alias proxy proxy_http proxy_fcgi
to run in Ubuntu 16.04.1
Thank you Bu Huy!!!
You only need:
a2enmod alias proxy proxy_http
I followed this tutorial step by step but I still have Apache2.0 Handler as server api. Is there something more I must do ?
I also had problems in step 5, but got it fixed by putting the line below in 000-default.conf (instead of the <ifModule>)ProxyPassMatch ^/(.*\.php(/.*)?)$ unix:/run/php/php7.0-fpm.sock|fcgi://localhost/var/www/html/
source: geoffstratton.com/ubuntu-1604-web-server-apache-php-and-mysql
This worked thank you !
This worked for me too.
Had almost the same issues described above. This worked for me.
http://blog.koenreiniers.nl/guide-to-combining-apache-virtual-hosts-and-php7-fpm/
Firstly, thank you for putting this tutorial, Till! Its awesome!
Just FYI, there is a typo in Step 5: Configure Apache
In one section you use AddHandler and in next section you use SetHandler instead of AddHandler.
Cheers!
Jay
1. config in 000-default.conf
<FilesMatch \.php$> SetHandler "proxy:unix:/var/run/php/php7.0-fpm.sock|fcgi://localhost/"</FilesMatch>
2. sudo a2enmod proxy_fcgi
I agree with the others AddHandler, not SetHandler. SetHandler gave an error when I tried to reload apache (specificlly that line).
This writeup leaves me with apache prefork mpm. Command #apachectl -V gives:
Server version: Apache/2.4.18 (Ubuntu)
Server built: 2016-07-14T12:32:26
Server's Module Magic Number: 20120211:52
Server loaded: APR 1.5.2, APR-UTIL 1.5.4
Compiled using: APR 1.5.2, APR-UTIL 1.5.4
Architecture: 64-bit
Server MPM: prefork
I have a 1GB ram VPS and would like to use apache event mpm with php7.0 and php-fpm.
What should I do to accomplish that?
hello, thanks for your tutorials, i'm reading a lot fo articles on your website.
may i ask you what about the apache configuration for php custom installation directory?
just like this https://www.howtoforge.com/tutorial/how-to-install-php-7-on-debian-8-jessie/
what's the best way to set up apache with php installed as shown in the link?
thanks.
The custom php tutorial is made for the ISPConfig perfect server guides like this one: https://www.howtoforge.com/tutorial/perfect-server-ubuntu-16.04-with-apache-php-myqsl-pureftpd-bind-postfix-doveot-and-ispconfig/
ISPConfig is able to create a vhost configuration in php-fpm or php-fcgi mode that uses the additional PHP version.
THANK YOU THANK YOU THANK YOU!
There's an extra space under AddHandler and SetHandler.
MariaDB error: ERROR 1698 (28000): Access denied for user 'root'@'localhostSolution here: https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost
$ sudo mysql -u root [mysql] use mysql; [mysql] update user set plugin='' where User='root'; [mysql] flush privileges; [mysql] \q
Very good tutorial!I've set up Apache2.4 with PHP-FPM 7.0 using virtual hosts on Ubuntu 16.04. These are my recommendations/changes to the tutorial:
Step 4 change: a2enmod actions fastcgi alias proxy proxy_fcgi
Step 5 only: a2enconf php7.0-fpm (use default of apache2.4)
For virtual hosts do:a) create virtual-host directory/s including user/group ownership and 751 permissionb) optionally set umask to 026 for shell (~/.profile), sftp (/etc/ssh/sshd_config) and php (/lib/systemd/system/php7.0-fpm.service)c) create Apache-config for virtualhost based on /etc/apache2/sites-available/000-default.conf:
set ServerName, DocumentRoot, ErrorLog, CustomLog and<FilesMatch ".+\.ph(p[3457]?|t|tml)$">
SetHandler "proxy:unix:/run/php/php7.0-fpm-web1.sock|fcgi://localhost"</FilesMatch><Directory /var/www_vhosts/web1/>
Options Indexes FollowSymlinks
AllowOverride None
Require all granted</Directory>d)
activate with a2ensite web1e)
create PHP-config for virtualhost based on /etc/php/7.0/fpm/pool.d/web1.conf:set pool name, user/group, listen-socket (listen = /run/php/php7.0-fpm-web1.sock), listen user/group, listen mode (listen.mode = 0666), virtual-host specific php-settings (eg. php_admin_value[open_basedir] = /var/www_vhosts/web1)f) restart and check with: ps -efH | grep php-fpm OR systemctl status php7.0-fpm.service
Cool + for the post