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
.
- Decide on a URL for that project - I would use
example.mylaravelproject.com
. But anything will do.
- Confirm the path of your project folder. For this example, we'll assume it's
/var/www/example/
- Run the following command (assuming you're using Ubuntu) -
sudo nano /etc/apache2/sites-available/example.mylaravelproject.com.conf
- 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>
- Save and close the file
- Run the following command
sudo a2ensite example.mylaravelproject.com.conf
- Run
sudo nano /etc/apache2.conf
- Make sure that this line appears somewhere in this file (preferrably in a
<Directory>
tag - AddType application/x-httpd-php .php
- 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:
sudo nano /etc/hosts
- again, assuming that you're running Ubuntu
Add this line somewhere to your project: localhost example.mylaravelproject.com
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: