Difference between revisions of "KB00005:Web Server Configuration"

From PartKeepr Wiki
Jump to: navigation, search
(nginx)
Line 14: Line 14:
  
 
<pre>
 
<pre>
     # Use app.php as index
+
server {
     index app.php;
+
     # Listening port and host address
 +
    listen 80;
 +
     server_name partkeepr.example.com;
  
     location /setup {
+
     # Default index pages
        index index.html;
+
    index app.php index.html
     }
+
 
 +
    # Default character set
 +
    charset utf-8;
 +
 
 +
    # Turn off access.log writes
 +
    access_log off;
 +
    log_not_found off;
 +
 
 +
    # Send file is an optimization, but does not work
 +
    # across unix sockets which I use for php fpm so is best
 +
    # used for local static content onlya
 +
    sendfile off;
 +
 
 +
    # Root for / project
 +
     root /var/www/partkeepr/web/;
 +
 
 +
    # Setup rewrite helper
 +
    rewrite ^/setup/webserver-test$ /setup/tests/webservercheck.json;
  
 +
    # Handle main / location to symfony app.php controller
 
     location / {
 
     location / {
        # try to serve file directly, fallback to app.php
+
         try_files $uri $uri/ /app.php?$query_string;
         try_files $uri /app.php$is_args$args;
 
 
     }
 
     }
  
     # This is required for the setup to detect if this KB article has been implemented
+
     # Handle /setup location to symfony setup.php controller
     rewrite ^/setup\/webserver-test$ /setup/tests/webservercheck.json;
+
     location /setup {
 +
        try_files $uri $uri/ /setup.php?$query_string;
 +
    }
  
     location ~ ^/(app_dev|config|setup)\.php(/|$) {
+
    # Handle all locations *.php files via PHP-FPM unix socket
         fastcgi_pass unix:/var/run/php5-fpm.sock;
+
     location ~ \.php$ {
         fastcgi_split_path_info ^(.+\.php)(/.*)$;
+
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
 +
         #fastcgi_pass unix:/var/run/php5-fpm.sock;
 +
         fastcgi_pass unix://var/run/php/php7.0-fpm.sock;
 +
        fastcgi_index index.php;
 
         include fastcgi_params;
 
         include fastcgi_params;
        # When you are using symlinks to link the document root to the
+
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        # current version of your application, you should pass the real
+
         fastcgi_intercept_errors off;
        # application path instead of the path to the symlink to PHP
+
        fastcgi_buffer_size 16k;
        # FPM.
+
        fastcgi_buffers 4 16k;
        # Otherwise, PHP's OPcache may not properly detect changes to
 
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
 
        # for more information).
 
         fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
 
         fastcgi_param DOCUMENT_ROOT $realpath_root;
 
 
     }
 
     }
     # PROD
+
 
     location ~ ^/app\.php(/|$) {
+
     # Deny .ht* access
         fastcgi_pass unix:/var/run/php5-fpm.sock;
+
     location ~ /\.ht {
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
+
         deny all;
        include fastcgi_params;
 
        # When you are using symlinks to link the document root to the
 
        # current version of your application, you should pass the real
 
        # application path instead of the path to the symlink to PHP
 
        # FPM.
 
        # Otherwise, PHP's OPcache may not properly detect changes to
 
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
 
        # for more information).
 
        fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
 
        fastcgi_param DOCUMENT_ROOT $realpath_root;
 
        # Prevents URIs that include the front controller. This will 404:
 
        # http://domain.tld/app.php/some-path
 
        # Remove the internal directive to allow URIs like this
 
        internal;
 
 
     }
 
     }
 +
}
 +
 
</pre>
 
</pre>
 
[[Category:Knowledge Base]]
 
[[Category:Knowledge Base]]

Revision as of 20:16, 9 February 2016

PartKeepr requires special configuration in some cases.

Apache

Apache requires the following settings:

nginx

You need to configure nginx so that it passes the path_info to PHP, that is, everything which is added after a PHP script (like setup.php/test). Also make sure you set your root directory to your PartKeepr web/ directory.

 server {
    # Listening port and host address
    listen 80;
    server_name partkeepr.example.com;

    # Default index pages
    index app.php index.html

    # Default character set
    charset utf-8;

    # Turn off access.log writes
    access_log off;
    log_not_found off;

    # Send file is an optimization, but does not work
    # across unix sockets which I use for php fpm so is best
    # used for local static content onlya 
    sendfile off;

    # Root for / project
    root /var/www/partkeepr/web/;

    # Setup rewrite helper
    rewrite ^/setup/webserver-test$ /setup/tests/webservercheck.json;

    # Handle main / location to symfony app.php controller
    location / {
        try_files $uri $uri/ /app.php?$query_string;
    }

    # Handle /setup location to symfony setup.php controller
    location /setup {
        try_files $uri $uri/ /setup.php?$query_string;
    }

    # Handle all locations *.php files via PHP-FPM unix socket
    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_pass unix://var/run/php/php7.0-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors off;
        fastcgi_buffer_size 16k;
        fastcgi_buffers 4 16k;
    }

    # Deny .ht* access
    location ~ /\.ht {
        deny all;
    }
}