Using virtual hosts in apache can help you manage multiple Laravel application endpoints.
First, you need to ensure that you have mod_rewrite enabled on your apache setup. If not then you can do that:
sudo a2enmod rewritesudo service apache2 restartNow copy the default configuration and make a new one with a new name:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/secret-project.confNow open the newly added secret-project.conf configuration file. (you can name it whatever you want)
sudo nano /etc/apache2/sites-available/secret-project.confRemove the existing content in this copied file and add the following:
<VirtualHost *:80> ServerAdmin admin@example.com ServerName secret-project.local ServerAlias www.secret-project.local DocumentRoot /var/www/secret-project/public
<Directory /var/www/secret-project/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all Require all granted </Directory>
LogLevel debug ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>In the above configuration, we have registered a name for our Laravel installation so when we open secret-project.local in the browser, we would be able to see our Laravel application.
But before we proceed further and try to access quick.local, we have to add an entry in the hosts file:
sudo nano /etc/hostsAdd this line at the end of the hosts file:
127.0.0.1 secret-project.localEverything is set now. Enable your newly added secret-project.conf configuration and reload the apache2:
sudo a2ensite secret-project.confsudo service apache2 reloadNow you can open your browser and navigate to secret-project.local and you should be able to see the Laravel page.
In case you get an error on the page, make sure you set up the permissions on the cache and storage folder:
sudo chmod 777 -R storage/sudo chmod 777 -R bootstrap/cache/