Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Symfony2 on ISPConfig3

The whole ISPConfig installation, configuration and all that is involved have been a tough road. With bumps and bruises I've finally got the complete package running the way I want it to.

Those bumps and bruises are probably because I am inexperienced with Linux (Debian Wheezy).

However, now everything is set up, I have come to the point of installing Symfony2. This, like all other aspects of ISPConfig, doesn't go as it is supposed to go.

My issues:

  • I don't know how to configure nginx for symfony2 from the Web GUI
  • When running symfony it doesn't redirect to app.php
  • When i go directly to app.php it throws me a 500

The logs tell me there is a problem with the app directory not being accesible by open_basedir().

What I am actually looking for is a little guidence in how to configure this whole thing.

Feel free to ask for additional information. I will gladly update my question.

Thanks in advance.

Nginx site conf

server {
        listen ...:80;

        listen ...:443 ssl;
        ssl_protocols ...
        ssl_certificate ...
        ssl_certificate_key ...;

        server_name mydomain.tld;

        root   /var/www/mydomain.tld/web;



        index index.html index.htm index.php index.cgi index.pl index.xhtml;


        location ~ \.shtml$ {
            ssi on;
        }


        error_page 400 /error/400.html;
        error_page 401 /error/401.html;
        error_page 403 /error/403.html;
        error_page 404 /error/404.html;
        error_page 405 /error/405.html;
        error_page 500 /error/500.html;
        error_page 502 /error/502.html;
        error_page 503 /error/503.html;
        recursive_error_pages on;
        location = /error/400.html {

            internal;
        }
        location = /error/401.html {

            internal;
        }
        location = /error/403.html {

            internal;
        }
        location = /error/404.html {

            internal;
        }
        location = /error/405.html {

            internal;
        }
        location = /error/500.html {

            internal;
        }
        location = /error/502.html {

            internal;
        }
        location = /error/503.html {

            internal;
        }

        error_log /var/log/ispconfig/httpd/mydomain.tld/error.log;
        access_log /var/log/ispconfig/httpd/mydomain.tld/access.log combined;

        location ~ /\. {
            deny all;
            access_log off;
            log_not_found off;
        }

        location = /favicon.ico {
            log_not_found off;
            access_log off;
        }

        location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
        }

        location @php {
            try_files $uri =404;
            include /etc/nginx/fastcgi_params;
            fastcgi_pass unix:/var/lib/php5-fpm/web3.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_intercept_errors on;
        }

}

I would like to note that this configuration is automatically generated by ISPConfig and that this should probably be edited from the Web GUI.

Edit

I have fixed the internal server error by adding all symfony folders to:

ISPConfig Web > Sites > mydomain.tld > Options > PHP open_basedir
like image 807
Peter Avatar asked Feb 22 '16 15:02

Peter


2 Answers

The configuration is missing the actual relaying to PHP. It should work if you exchange the location @php block with the following three blocks:

location / {
  try_files $uri @php;
}

location app.php {
  try_files @php =404;
}

location @php {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass unix:/var/lib/php5-fpm/web3.sock;
    fastcgi_param  SCRIPT_NAME  app.php;
    fastcgi_param  SCRIPT_FILENAME  app.php;
    fastcgi_intercept_errors on;
}

The first block tries to find the requested file in the given root directory, meaning /var/www/mydomain.tld/web - now all Symfony assets will work and be returned, because they are all in the web directory. If the file is not found, it calls PHP.

The second block is used if /app.php is requested directly - instead of delivering that file, we process it with PHP.

The third block configures PHP - the previous two blocks always refer to this block, so any file not directly found is processed by PHP. Symfony only has one front controller, app.php, so we just send all requests to that entry point.

With this setup, it should be quite secure, because only app.php is ever processed by PHP. For a testing environment, you can use app_dev.php instead of app.php (just change the filename in the @php block) - but never for production and without securing the testing environment.

like image 135
iquito Avatar answered Oct 14 '22 13:10

iquito


Try pasting the code into the nginx Directives field on the Options tab of the website in ISPConfig. This should save your settings while config regenerations.

like image 28
max Avatar answered Oct 14 '22 13:10

max