首页 文章

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

提问于
浏览
1

我在创建我的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 回答

  • 1

    如果您只为 development 安装它(例如,在您的笔记本电脑上),那么 don't 需要像nginx这样的网络服务器 . 您可以使用内置的Web服务器 . 在你的项目root执行:

    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 .

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

    See super speed symfony

    您可能必须为缓存,日志和上载目录设置权限 . 见Symfony Documentation

相关问题