我真的必须将我的Symfony项目移动到/ var / www目录吗?

时间:2017-09-05 18:05:50

标签: php symfony nginx

我在创建我的symfony项目时遵循这篇文章:

Install Symfony3 with nginx in ubuntu 14.04

在这里说,在创建我的symfony项目之后:

symfony new project_name

我必须将我的项目移动到目录/ var / www

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

但是我的项目是在github的一个存储库里面,它无法移动。我该怎么办?我顺便使用nginx

由于

1 个答案:

答案 0 :(得分:1)

如果您仅为 开发 安装(例如,在您的笔记本电脑上),则 不要 < / strong>需要像nginx这样的网络服务器。您可以使用内置的Web服务器。在您的项目根执行:

php bin/console server:start

默认情况下,服务器侦听http://localhost:8000

如果要在专用服务器上安装它,请安装nginx并在/etc/nginx/sites-available中创建此文件,并将其命名为yoursite。您只需要提供项目的web目录。

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;
    }

将文件符号链接到sites-enabled目录。

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

default目录中删除sites-enabled配置。重启nginx。

See super speed symfony

您可能必须为缓存,日志和上传目录设置权限。请参阅Symfony Documentation