0

I just created a server with Ubuntu 18.04 and PHP 7.3

But when I check if my server is using PHP-FPM, I realize that not. However, it is well activated.

ubuntu@www-example-com:~$ sudo systemctl status php7.3-fpm
● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-03-07 13:12:45 CET; 3min 22s ago
     Docs: man:php-fpm7.3(8)
  Process: 19779 ExecStopPost=/usr/lib/php/php-fpm-socket-helper remove /run/php/php-fpm.sock /etc/php/7.3/fpm/pool.d/www.conf 73 (code=exit
  Process: 19803 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.sock /etc/php/7.3/fpm/pool.d/www.conf 73 (code=ex
 Main PID: 19781 (php-fpm7.3)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 2303)
   CGroup: /system.slice/php7.3-fpm.service
           ├─19781 php-fpm: master process (/etc/php/7.3/fpm/php-fpm.conf)
           ├─19800 php-fpm: pool www
           └─19802 php-fpm: pool www

Mar 07 13:12:45 www-example-com systemd[1]: Stopped The PHP 7.3 FastCGI Process Manager.
Mar 07 13:12:45 www-example-com systemd[1]: Starting The PHP 7.3 FastCGI Process Manager...
Mar 07 13:12:45 www-example-com systemd[1]: Started The PHP 7.3 FastCGI Process Manager.

But the report shows: Server API: Apache 2.0 Handler

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
Mathieu
  • 5
  • 2
  • 4

1 Answers1

2

It's not enough to just install PHP 7.3 FPM to make Apache use it instead of Apache's mod_php7; you would need to configure it, too. For out-of-the-box global PHP 7.3 FPM configuration you'd probably at least:

sudo a2dismod php7.3
sudo a2enmod proxy_fcgi
sudo a2enconf php7.3-fpm
sudo systemctl reload apache2

But it's probably a better idea to use separate FPM pools for different sites, run as different users. Assuming the document root for your site is /var/www/example.com and the folder is owned by user examplecom, you could e.g.

  1. Add a pool in /etc/php/7.3/fpm/pool.d/example.conf (you could copy www.conf as a base):

    [examplecom]
    user = examplecom
    group = examplecom
    
    listen = /run/php/examplecom.sock
    chdir = /var/www/example.com
    
    . . .
    
  2. Make your virtual host on Apache use this socket to handle .php files:

    <VirtualHost *:80>
        ServerName example.com
        DocumentRoot /var/www/example.com
    
        <FilesMatch ".php$"> 
            SetHandler "proxy:unix:/run/php/examplecom.sock|fcgi://localhost/"          
        </FilesMatch>
    
        . . .
    </VirtualHost>
    
  3. sudo systemctl reload php7.3-fpm apache2

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • Thank you but there is only one site on the server. By reloading apache 2 it works. But I do not understand because the server is on Nginx, to reload apache 2 ? – Mathieu Mar 07 '20 at 13:04
  • How's it Nginx? The `phpinfo()` shows `Apache/2.4.29 (Ubuntu)`. You can also deduce the site from the hostname. That site is on the same IP addess, and there's the Apache2 Ubuntu Default Page saying _It works!_ – Esa Jokinen Mar 07 '20 at 13:29
  • I didn't install Apache, I only installed Nginx on Ubuntu 18.04 so I don't understand why it should reload Apache : https://pastebin.com/fz2hVJKD – Mathieu Mar 07 '20 at 13:43
  • On the IP address from your link there's clearly Apache 2.4.29 installed. Nginx doesn't advertise itself with a response header `Server: Apache/2.4.29 (Ubuntu)` nor have `Apache/2.4.29 (Ubuntu) Server at x.x.x.x Port 80` on error pages. I don't know why you *think* you have installed Nginx, while all the evidence tells the opposite. – Esa Jokinen Mar 07 '20 at 13:51
  • It’s really weird. So that means that Apache is included with Ubuntu. I only installed ubuntu and followed the instructions in pastebin from my previous comment. – Mathieu Mar 07 '20 at 14:25
  • That's probably true, and explains your confusion. Glad you got it working, anyways! – Esa Jokinen Mar 07 '20 at 14:26