thinkPHP on apache and nginx

1.1 apache site config

add the following into /etc/apache2/sites-enabled/php_82.conf

<VirtualHost *:82>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/spring/p2phunter_cn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory "/home/spring/p2phunter_cn">
        Options Indexes FollowSymLinks MultiViews Includes ExecCGI
        AddHandler cgi-script .cgi
        AllowOverride all
        Require all granted
        AddType text/html .html
        AddOutputFilter INCLUDES .html
        DirectoryIndex index.php
    </Directory>
</VirtualHost>

1.2 apache2 behind nginx

needs to start apache2 with the same user as nginx.
Open /etc/apache2/envvars and set:

export APACHE_RUN_USER=nginx
export APACHE_RUN_GROUP=nginx

2.1 php site config

add .htaccess to php site root dir, this will handle url rewrite. See thinkphp help

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
</IfModule>

2.2 php-fpm behind apache2

If we “grep ‘user’ /etc/nginx/nginx.conf”, we found nginx is started as user ‘nginx’.
Let’s modify “/etc/php5/fpm/pool.d/www.conf" as this:

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

Then restart php-fpm

service php5-fpm restart

Finally confirm the sock file has correct file attributes:

ls -l /var/run/php5-fpm.sock