2017-08-06 70 views
1

我想让我的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让我的php服务器成为symfony服务器

<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它始终运行我的索引。 PHP。
你能帮我一下吗?


完整的解决方案 - 由于@Alberto Fecchi答案:

  1. 编辑00 default.conf
  2. 粘贴你阿尔贝托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. 进入文件夹“/无功/网络/项目/网络/”上下而求索“的.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> 
  • 注释行RedirectMatch 302 ^/$ /app.php/
  • 现在工程:)

    回答

    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来查看您的“生产”应用程序。

    +0

    它不起作用。如果我写“http:// public_ip”,它会继续“http://public_ip/app.php”,并表示该页面不起作用。 – ProtoTyPus

    +0

    http://public_ip/app_dev.php上会发生什么?附:确保mod_rewrite已启用。 –

    +0

    它说我没有权限看它,因为我不在本地主机上! – ProtoTyPus