Laravel – 包括外部项目

Laravel – Include external Project

在一个 Laravel 项目中,我必须包含多个项目,以便可以在 /example 访问它们。 这些项目的结构为

/example
 - index.php
 - main.css
 - app.js

(Usually there are more files then that.)

我曾尝试使用 Redirect::to("example/index.php"),但是这会破坏所有 <link><src>(我需要在所有这些之前添加 /example .

这在理论上可行,但我不想将这些文件存储在 Laravel 项目本身中,因为它们基本上是独立的项目。

包含此类外部项目的最佳方式是什么?

This would theoretically work, however I would rather not store these files in the Laravel project itself, since they are basically self-contained projects.

这是一个很好的方法。而是将 Laravel 保留为 Laravel 并将内容托管在 Laravel 项目之外。

由于您使用的是 Apache,下面是为该外部项目创建虚拟主机的方法。

请注意 - 我假设您的项目位于 /var/www

  1. 为该项目决定 URL - 我会使用 example.mylaravelproject.com。但任何事情都可以。
  2. 确认项目文件夹的路径。对于这个例子,我们假设它是 /var/www/example/
  3. 运行 以下命令(假设您使用的是 Ubuntu)- sudo nano /etc/apache2/sites-available/example.mylaravelproject.com.conf
  4. 确保新文件具有以下内容:

<VirtualHost *:80> ServerAdmin <your email address here> ServerName example.mylaravelproject.com DocumentRoot /var/www/example ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>

  1. 保存并关闭文件
  2. 运行下面的命令sudo a2ensite example.mylaravelproject.com.conf
  3. 运行 sudo nano /etc/apache2.conf
  4. 确保此行出现在该文件的某处(最好在 <Directory> 标记中 - AddType application/x-httpd-php .php
  5. 然后通过发出以下命令重新启动 Apache sudo service apache2 restart

从技术上讲,现在您的网站有一个有效的虚拟主机并且应该可以正常工作。

如果您在本地环境中执行此操作并希望通过浏览器访问您的示例项目,则需要完成更多步骤:

  1. sudo nano /etc/hosts - 再次假设您是 运行 Ubuntu
  2. 将此行添加到项目的某处:localhost example.mylaravelproject.com

  3. 保存并关闭该文件。您现在应该可以通过浏览器访问 url。

如果这些步骤不起作用,Apache 可能没有解析 PHP 文件。如果是这种情况,请尝试这些链接以获得有关使 Apache 解析 PHP:

的一些好的答案
  • Apache 2 server on ubuntu can't parse php code inside html file
  • Apache Virtual Host not parsing PHP