如何配置 Apache 在同一域中拥有两个 symfony 项目(不使用子域)?

发布于 2024-08-19 20:38:23 字数 1327 浏览 9 评论 0原文

我正在尝试将 Apache 配置为在同一域下拥有不同的 symfony 项目(每个项目都有自己的框架安装),但我无法使用文件夹使其工作。

这就是我想要的:

  • mydomain.com/projectone/
  • mydomain.com/projecttwo/

我可以使用子域使其工作,但这不是我的首选解决方案,因为我最终拥有疯狂的子域,例如:

  • projectone.mydomain .com
  • backend.projectone.mydomain.com
  • projecttwo.mydomain.com
  • backend.projecttwo.mydomain.com

我在 Apache 中使用此配置以使其与子域一起使用:

<VirtualHost 127.0.0.1:8080>
  ServerName projectone.mydomain.com
  DocumentRoot "/home/projectone/web"
  DirectoryIndex frontend.php
  <Directory "/home/projectone/web">
    Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
    AllowOverride None
    Allow from All

    RewriteEngine On
    # we check if the .html version is here (caching)
    RewriteRule ^$ index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    # no, so we redirect to our front web controller
    RewriteRule ^(.*)$ frontend.php [QSA,L]
  </Directory>

  Alias /sf /home/projectone/lib/vendor/symfony/data/web/sf
  <Directory "/home/projectone/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

关于如何实现文件夹解决方案有什么想法吗?

提前致谢, 埃内科

I'm trying to configure Apache to have to different symfony projects (each with his own installation of the framework) under the same domain, but I can't get it to work using folders.

This is what I would like to have:

  • mydomain.com/projectone/
  • mydomain.com/projecttwo/

I can make it work using subdomains, but is not the preferred solution for me, because I end up having crazy subdomains like:

  • projectone.mydomain.com
  • backend.projectone.mydomain.com
  • projecttwo.mydomain.com
  • backend.projecttwo.mydomain.com

I'm using this configuration in Apache to make it work with subdomains:

<VirtualHost 127.0.0.1:8080>
  ServerName projectone.mydomain.com
  DocumentRoot "/home/projectone/web"
  DirectoryIndex frontend.php
  <Directory "/home/projectone/web">
    Options -Indexes IncludesNOEXEC FollowSymLinks -MultiViews
    AllowOverride None
    Allow from All

    RewriteEngine On
    # we check if the .html version is here (caching)
    RewriteRule ^$ index.html [QSA]
    RewriteRule ^([^.]+)$ $1.html [QSA]
    RewriteCond %{REQUEST_FILENAME} !-f
    # no, so we redirect to our front web controller
    RewriteRule ^(.*)$ frontend.php [QSA,L]
  </Directory>

  Alias /sf /home/projectone/lib/vendor/symfony/data/web/sf
  <Directory "/home/projectone/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

Any idea on how to achieve the folders solution?

Thanks in advance,
Eneko

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

§普罗旺斯的薰衣草 2024-08-26 20:38:23

我一直这样做。这是相关的 Apache 配置。我还设置了 每个 symfony 应用程序的自定义错误处理程序

 # make sure your symfony install dir is available
<Directory "/var/www/symfony1.4">
    AllowOverride All
    Allow from all
</Directory>

# each app under http://mysite/myapp gets a section like this
Alias /myapp/sf "/var/www/symfony1.4/data/web/sf"
Alias /myapp "/var/www/vhosts/myvhost/sf_apps/myapp/web"
<Directory "/var/www/vhosts/myvhost/sf_apps/myapp/web">
    AllowOverride All
    Allow from all
    ErrorDocument 404 /myapp/default/error404
    ErrorDocument 500 /myapp/myThemePlugin/errors/error500.php
</Directory>

您还需要修改 web/.htaccess 文件中的这一行。

# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /myapp

I do this all the time. Here's the relevant Apache config. I also set up custom error handlers for each symfony app.

 # make sure your symfony install dir is available
<Directory "/var/www/symfony1.4">
    AllowOverride All
    Allow from all
</Directory>

# each app under http://mysite/myapp gets a section like this
Alias /myapp/sf "/var/www/symfony1.4/data/web/sf"
Alias /myapp "/var/www/vhosts/myvhost/sf_apps/myapp/web"
<Directory "/var/www/vhosts/myvhost/sf_apps/myapp/web">
    AllowOverride All
    Allow from all
    ErrorDocument 404 /myapp/default/error404
    ErrorDocument 500 /myapp/myThemePlugin/errors/error500.php
</Directory>

You also need to hack this line in your web/.htaccess file.

# uncomment the following line, if you are having trouble
# getting no_script_name to work
RewriteBase /myapp
梦情居士 2024-08-26 20:38:23

我已经尝试过这段代码并且似乎有效。因为我还没有测试过它,所以我不确定这是否没有错误,但它可以给你一个提示。

<VirtualHost 127.0.0.1:8088>
  Alias /badger /home/amqs/proyectos/sales/nuevo/salesprime/web
  DocumentRoot "/home/amqs/proyectos/sales/nuevo/salesprime/web"
  DirectoryIndex frontend_dev.php
  <Directory "/home/amqs/proyectos/sales/nuevo/salesprime/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sales /home/amqs/proyectos/sales/salesprime2/web
  DocumentRoot "/home/amqs/proyectos/sales/salesprime2/web"
  DirectoryIndex frontend_dev.php
  <Directory "/home/amqs/proyectos/sales/salesprime2/web">
    AllowOverride All
    Allow from All
  </Directory>

</VirtualHost>

I have tried this code and seems to work. Since I haven't tested it I am not sure about this being error free, but it can be a hint for you.

<VirtualHost 127.0.0.1:8088>
  Alias /badger /home/amqs/proyectos/sales/nuevo/salesprime/web
  DocumentRoot "/home/amqs/proyectos/sales/nuevo/salesprime/web"
  DirectoryIndex frontend_dev.php
  <Directory "/home/amqs/proyectos/sales/nuevo/salesprime/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sales /home/amqs/proyectos/sales/salesprime2/web
  DocumentRoot "/home/amqs/proyectos/sales/salesprime2/web"
  DirectoryIndex frontend_dev.php
  <Directory "/home/amqs/proyectos/sales/salesprime2/web">
    AllowOverride All
    Allow from All
  </Directory>

</VirtualHost>
她如夕阳 2024-08-26 20:38:23

您可以在 ProjectConfiguration 中使用 setWebDir 方法来指定唯一的 Web在每个项目中提供服务的目录。这将允许您将项目文件(应用程序、配置、lib、插件等)托管在您想要的任何目录(/home/projectone)中,同时通常将 web/ 中的文件移动到完全不同的位置(/home/ mydomain/web/projectone)。您可以选择从 config/ProjectConfiguration.class.php 中的根 ProjectConfiguration 调整整个项目的 Web 目录:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->setWebDir('/home/mydomain/web/projectone');
  }
}

或者如果您希望每个应用程序都有不同的 Web 目录 (/projectone / 对于前端, /projectone/backend/ 对于后端)您可以在 apps/myapp/config/myappConfiguration.class.php 中的每个应用程序配置中设置 Web 目录:

class myappConfiguration extends sfApplicationConfiguration
{
  public function configure()
  {
    $this->setWebDir('/home/mydomain/web/projectone');
  }
}

希望有帮助。

You can use the setWebDir method in your ProjectConfiguration to specify a unique web directory to serve out of in each project. This will allow you to host the project files (apps, config, lib, plugins, etc) in any directory you'd like (/home/projectone) while moving the files normally in web/ to a completely different location (/home/mydomain/web/projectone). You have the option of adjusting your entire project's web directory from your root ProjectConfiguration in config/ProjectConfiguration.class.php:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->setWebDir('/home/mydomain/web/projectone');
  }
}

or if you'd like each of your applications to have a different web directory (/projectone/ for the front-end and /projectone/backend/ for the back-end) you can set the web directory from each of the application configurations in apps/myapp/config/myappConfiguration.class.php:

class myappConfiguration extends sfApplicationConfiguration
{
  public function configure()
  {
    $this->setWebDir('/home/mydomain/web/projectone');
  }
}

Hope that helps.

财迷小姐 2024-08-26 20:38:23

尝试此配置。
此作品适用于 symfony 2 和 3。

<VirtualHost 127.0.0.1:8080>
    Alias /app1 /var/www/public_html/app1/web 
    DocumentRoot "/var/www/public_html/app1/web" 
    DirectoryIndex app.php
    <Directory "/var/www/public_html/app1/web"> 
        AllowOverride All
        Allow from All 
    </Directory>
</VirtualHost>

文档:https:// /symfony.com/doc/3.3/setup/web_server_configuration.html

Try this configuration.
This work for symfony 2 and 3.

<VirtualHost 127.0.0.1:8080>
    Alias /app1 /var/www/public_html/app1/web 
    DocumentRoot "/var/www/public_html/app1/web" 
    DirectoryIndex app.php
    <Directory "/var/www/public_html/app1/web"> 
        AllowOverride All
        Allow from All 
    </Directory>
</VirtualHost>

Documentation: https://symfony.com/doc/3.3/setup/web_server_configuration.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文