1.安裝

#Apache
cd /usr/ports/www/apache22-worker-mpm; make install

#PHP(記得把FPM選項勾起來)
cd /usr/ports/lang/php5; make install

#複製php.ini
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini

#PHP Extensions
cd /usr/ports/lang/php5-extensions; make install

#mod_fastcgi
cd /usr/ports/www/mod_fastcgi; make install

2.修改設定
/usr/local/etc/apache22/httpd.conf

#確認是否有mod_fastcgi.so
LoadModule fastcgi_module libexec/apache22/mod_fastcgi.so

#將httpd-mpm.conf註解拿掉
Include etc/apache22/extra/httpd-mpm.conf

新增/usr/local/etc/apache22/Includes/php.conf

<IfModule prefork.c>
    LoadModule php5_module libexec/apache22/libphp5.so
    AddType application/x-httpd-php .php .html
    AddType application/x-httpd-php-source .phps
</IfModule>

<IfModule worker.c>
    FastCGIExternalServer /usr/local/sbin/php-fpm -socket /tmp/php-fpm.sock -idle-timeout 900
    AddHandler php-fastcgi .php
    Action php-fastcgi /usr/local/sbin/php-fpm.fcgi
    ScriptAlias /usr/local/sbin/php-fpm.fcgi /usr/local/sbin/php-fpm

    <Directory /usr/local/sbin >
        Options ExecCGI FollowSymLinks
        SetHandler fastcgi-script
        Order allow,deny
        Allow from all
    </Directory>
</IfModule>

DirectoryIndex index.php index.html

修改/usr/local/etc/php-fpm.conf

;調整listen接口
;listen = 127.0.0.1:9000
listen = /tmp/php-fpm.sock

修改/etc/rc.conf

#php-fpm
php_fpm_enable="YES"

#apache
apache22_enable="YES"
apache22_http_accept_enable="YES"

3.啟動

/usr/local/etc/rc.d/php-fpm start
/usr/local/etc/rc.d/apache22 start
Categories: FreeBSD