0

In a Laravel project I have to include multiple projects, so that they are accessible at /example. These projects have the structure of

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

(Usually there are more files then that.)

I have tried to use Redirect::to("example/index.php"), however this breaks all the <link>'s & <src> (where I would need to prepend /example to all of them.

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

What is the best way to include such external projects?

Elwin
  • 491
  • 1
  • 6
  • 11

1 Answers1

0

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

That's an excellent approach. Rather keep Laravel as Laravel and host the stuff just outside of your Laravel project.

Since you're using Apache, here's how to create a Virtual Host for that external project.

Please note - I'm assuming that your project lives in /var/www.

  1. Decide on a URL for that project - I would use example.mylaravelproject.com. But anything will do.
  2. Confirm the path of your project folder. For this example, we'll assume it's /var/www/example/
  3. Run the following command (assuming you're using Ubuntu) - sudo nano /etc/apache2/sites-available/example.mylaravelproject.com.conf
  4. Ensure the new file has the following contents:

<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. Save and close the file
  2. Run the following command sudo a2ensite example.mylaravelproject.com.conf
  3. Run sudo nano /etc/apache2.conf
  4. Make sure that this line appears somewhere in this file (preferrably in a <Directory> tag - AddType application/x-httpd-php .php
  5. Then restart Apache by issuing the following command sudo service apache2 restart

Technically now your site has a valid vhost and should be working.

If you're doing this on a local environment and want to access your example project via the browser, you'll need to complete a few more steps:

  1. sudo nano /etc/hosts - again, assuming that you're running Ubuntu
  2. Add this line somewhere to your project: localhost example.mylaravelproject.com

  3. Save and close that file. You should now be able to access that url via your browser.

If these steps don't work, it's likely that Apache isn't parsing the PHP files. If that's the case, try these links for some good answers on making Apache parse PHP:

Community
  • 1
  • 1
Kyle O'Brien
  • 932
  • 1
  • 11
  • 28