Running Symfony2 on ISPConfig3
Asked Answered
M

2

15

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
Maiolica answered 22/2, 2016 at 15:21 Comment(3)
can you provide your .conf file?Smilax
@OliverQueen which .conf do you prefer?Maiolica
whichever holds the server setup and redirects for the applicationSmilax
S
7

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.

Schooner answered 26/2, 2016 at 20:30 Comment(6)
This works indeed. Thank you. But when I change something in the ISPConfig web interface my changes are overwritten. Do you know how I can prevent this?Maiolica
Unfortunately I am not familiar with ISPConfig - maybe you can edit the Nginx config from within the web interface, so ISPConfig writes the changes itself/knows what to write to the config file?Schooner
As an ugly workaround you can try to chmod the config to be non writeable by root. If it works, grate!, if it crashes, the logs may show who's touching them.Lone
@Maiolica try pasting the code into the nginx Directives field on the Options tab of the website in ISPConfigMagnien
@Magnien That helped a lot. Though my other domains redirect to the symfony page now too.. Can I include a server_name param without any issues as well there? (Could you make this into an answer?)Maiolica
@Peter, that's very strange because ISPConfig generates a configuration file per each website instance which has to have a domain specified. Can you check the generated nginx config what server_name it has?Magnien
M
1

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.

Magnien answered 15/3, 2016 at 14:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.