Cadz
Cadz

Reputation: 151

Do I really have to move my Symfony project to /var/www directory?

I am following this article in creating my symfony project :

Install Symfony3 with nginx in ubuntu 14.04

It says in here that after creating my symfony project :

symfony new project_name

I have to move my project to directory /var/www

mv /project_name /var/www/your-domain.com

But my project is inside a repository in github which cant be moved. How do I proceed? I'm using nginx by the way

Thanks

Upvotes: 1

Views: 829

Answers (1)

jrswgtr
jrswgtr

Reputation: 2379

If you are installing it for development only (say, on your laptop), you don't need a webserver like nginx. You can use the built-in webserver. In your project root execute:

php bin/console server:start

By default the server listens on http://localhost:8000

If you are installing it on a dedicated server install nginx and create this file in /etc/nginx/sites-available name it yoursite. You only have to serve the web directory of your project.

server {
    server_name yoursite.com;
    root /home/your_user/path/to/your/project/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        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;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        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;
    }
 # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
      return 404;
    }

Symlink the file to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/yoursite /etc/nginx/sites-enabled/yoursite.

Remove the default configuration from the sites-enabled directory. Restart nginx.

See super speed symfony

You may have to set permissions for cache, log and upload directories. See the Symfony Documentation

Upvotes: 1

Related Questions