rc.conf :
php_fpm_enable="YES"
edit /usr/local/etc/php-fpm.d/ as needed ...
------------------------------------------------------------------------
I could be wrong !!!, but this is what A.I. says.
In FreeBSD, you need to manually enable the required modules in the Apache configuration file and point it to the PHP-FPM service.
1. Enable Required Apache Modules
Open your main Apache configuration file, usually located at /usr/local/etc/apache24/httpd.conf. Find and
uncomment (remove the #) the following lines:
- LoadModule proxy_module libexec/apache24/mod_proxy.so
- LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so
- LoadModule mpm_event_module libexec/apache24/mod_mpm_event.so
Note: You should
comment out mod_mpm_prefork and mod_php if they are enabled, as they are not used with PHP-FPM.
2. Configure PHP-FPM Socket or Port
FreeBSD's PHP-FPM can listen on either a Unix socket or a network port. Check your PHP-FPM pool configuration (usually /usr/local/etc/php-fpm.d/www.conf) to see the listen directive.
- If using a Unix Socket (common for performance):
apache
<span><FilesMatch "\.php$"><br> SetHandler "proxy:unix:/var/run/php-fpm.sock|fcgi://localhost/"<br></FilesMatch><br></span>
Use code with caution.
- If using a TCP Port (default is often 127.0.0.1:9000):
apache
<span><FilesMatch "\.php$"><br> SetHandler "proxy:fcgi://127.0.0.1:9000"<br></FilesMatch><br></span>
Use code with caution.
3. Enable and Restart Services
Ensure both services are enabled in /etc/rc.conf:
bash
<span>sudo sysrc apache24_enable=</span><span>"YES"</span><span><br>sudo sysrc php_fpm_enable=</span><span>"YES"</span><span><br></span>
Use code with caution.
Then restart them:
bash
<span>sudo service php-fpm restart<br>sudo service apache24 restart<br></span>
Use code with caution.
4. Verification
You can verify the modules are correctly loaded by running:
bash
<span>apachectl -M | grep -E </span><span>'proxy|mpm'</span><span><br></span>
Use code with caution.
Follow-up: Would you like a
sample configuration file to place in your Includes/ directory to keep your main httpd.conf clean?
----------------------------------------------------------------------------------------
To keep your
httpd.conf clean, it is best practice on FreeBSD to create a separate configuration file in the Includes directory.
1. Create the Config File
Create a new file named php-fpm.conf:
bash
<span>sudo vi /usr/local/etc/apache24/Includes/php-fpm.conf<br></span>
Use code with caution.
2. Add the Configuration
Paste the following block. This setup handles the proxying and ensures index files work correctly:
apache
<span># Enable the PHP-FPM handler<br><FilesMatch "\.php$"><br> # Change this to match your 'listen' setting in php-fpm.d/www.conf<br> # Example for Socket: unix:/var/run/php-fpm.sock|fcgi://localhost/<br> # Example for TCP: fcgi://127.0.0.1:9000<br> SetHandler "proxy:fcgi://127.0.0.1:9000"<br></FilesMatch><br><br># Allow index.php to be a directory index<br><IfModule dir_module><br> DirectoryIndex index.php index.html<br></IfModule><br><br># Security: Block access to .user.ini files<br><Files ".user.ini"><br> Require all denied<br></Files><br></span>
Use code with caution.
3. Verify your PHP-FPM Listener
Before restarting, double-check where PHP-FPM is actually listening so the SetHandler line above is accurate:
bash
<span>grep </span><span>"^listen ="</span><span> /usr/local/etc/php-fpm.d/www.conf<br></span>
Use code with caution.
- If it says 127.0.0.1:9000, use the TCP example above.
- If it shows a path like /var/run/php-fpm.sock, use the Unix example.
4. Test and Restart
Run the config test to make sure you didn't miss any modules in httpd.conf:
bash
<span># Check for syntax errors</span><span><br>apachectl configtest<br><br></span><span># If "Syntax OK", restart both</span><span><br>sudo service php-fpm restart<br>sudo service apache24 restart<br></span>