【问题标题】:Make my php server a symfony server使我的 php 服务器成为 symfony 服务器
【发布时间】:2018-01-13 15:12:36
【问题描述】:

我正在尝试使我的 php 服务器成为 Symfony 服务器。
我已经安装了 Symfony,并在 /var/www/project_name
中创建了一个项目 如果我让server:run my_local_ip:8000 服务器正常运行,我也可以从另一个网络上的计算机访问它:http://public_ip:8000,相反,如果我写http://public_ip,它会在我的 index.php 上运行。
好吧,现在,如果我写 http://public_ip 它会继续 http://public_ip:8000 或者至少可以让 Symfony 在端口 80 上运行或让 Symfony 在 php 内置服务器上运行,我会喜欢它。
我尝试创建一个虚拟主机,我创建了这个文件:
project_name.conf

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    ServerName project_name
    <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
      RewriteRule .* - [F]
    </IfModule>
    DocumentRoot /var/www/project_name
    <Directory /var/www/project_name>
      Options Indexes FollowSymlinks Multiviews
      AllowOverride All
      Require all granted
    </Directory>
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

但它不起作用,如果我写 http://public_ip 它总是运行我的 index.php。
你能给我帮助吗?


已完成的解决方案 - 感谢@Alberto Fecchi 的回答:

  1. 编辑 00-default.conf
  2. 粘贴您在 Alberto Fecchi 的答案中找到的内容并添加此内容
#IT NEEDS "<" BEFORE TAG
Directory /var/www/tcgfiga/web/bundles>
   IfModule mod_rewrite.c>
     RewriteEngine Off
  </IfModule>
/Directory>
  1. 然后让“sudo service apache2 restart”。有时需要,有时不需要
  2. 进入文件夹“/var/www/project/web/”并搜索“.htaccess”文件
  3. 您应该删除它,但如果您的应用程序没有运行,并且您看到并显示文件夹内容的页面,请重新创建并打开它。您必须搜索
<IfModule !mod_rewrite.c>
  <IfModule mod_alias.c>
    # When mod_rewrite is not available, we instruct a temporary redirect of
    # the start page to the front controller explicitly so that the website
    # and the generated links can still be used.
    RedirectMatch 302 ^/$ /app.php/
    # RedirectTemp cannot be used instead
  </IfModule>
</IfModule>
  1. 评论RedirectMatch 302 ^/$ /app.php/

现在可以了:)

【问题讨论】:

    标签: php symfony server ubuntu-server


    【解决方案1】:

    使用这个虚拟主机:

    <VirtualHost *:80>
    
        ServerName project_name
        <IfModule mod_rewrite.c>
          RewriteEngine on
          RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
          RewriteRule .* - [F]
        </IfModule>
        DocumentRoot /var/www/project_name/web
        <Directory /var/www/project_name/web>
            Options Indexes FollowSymlinks Multiviews
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    
    </VirtualHost>
    

    使用sudo a2ensite project_name 启用它并使用sudo service apache2 restart 重新启动(不同操作系统上的命令可能不同)。

    现在您可以访问http://public_ip 查看您的“生产”应用程序。

    【讨论】:

    • 它不起作用。如果我写“public_ip”它会继续“public_ip/app.php”并且它说页面不工作。
    • public_ip/app_dev.php 会发生什么?附:确保 mod_rewrite 已启用。
    • 它说我没有权限查看它,因为我不在本地主机上!
    • 然而 mod_rewrite 是启用的!
    • 这意味着虚拟主机正在工作。转到localhost/app_dev.php(如果可以的话)并修复错误,或者临时编辑 app_dev.php 以接受不仅来自本地主机的连接。这样,您可以轻松查看正在发生的事情,进行修复并让 app.php 正常工作。此外,您可以在不编辑 app_dev.php 的情况下完成它,只需查看 var/logs/prod.log 并查看错误。现在这是一个 symfony 问题,virtualhost 正在工作
    猜你喜欢
    • 2018-07-07
    • 1970-01-01
    • 2016-06-06
    • 2011-11-03
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多