I'm an IIS boy trying to delve into linux developing for the first time, so please, be gentle.
Ok, so... I'm trying to configure my workstation for developing on laravel.
I'm on Ubuntu 18.04, and have installed apache.
I've installed laravel from composer, and created a first project with:composer create-project --prefer-dist laravel/laravel mySite "5.8.*"
This has created a laravel project folder named mySite on /etc/apache2/sites-enabled
I've added a new file /etc/apache2/sites-available/mySite.conf which seems like this:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mySite
ServerAlias
DocumentRoot /etc/apache2/sites-enabled/mySite/public/index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined</VirtualHost>After that I've added a line to /etc/apache2/apache2.conf with:
Include /etc/apache2/sites-available/mySite.confAnd, of course, I've whitelisted my virtual site on the same file with:
<Directory /etc/apache2/sites-available/mySite>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>I've ran a2ensite and restarted apache.
However, I'm consistently receiving 403 errors (Forbidden. You don't have permission to access this resource.) when trying to access or also, using 127.0.0.1 instead of localhost throws the same error.
Any insight on this issue would be welcome.
1 Answer
Hello I've experience setting up virtual hosts for local development, so I hope this helps you.
Remove the line from apache.conf: Include /etc/apache2/sites-available/mySite.conf
And just run sudo a2ensite mySite.conf command to enable the virtualhost. (The mySite.conf file should be the same in ...apache/sites-available/)
In your VHost conf file edit your DocumentRoot like this
<VirtualHost *:80> ServerAdmin webmaster@localhost ServerName mySite.loc ServerAlias DocumentRoot /your/project/path ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>Where ServerName will be the localhost domain for your project and the DocumentRoot /your/project/path will the root folder where your project is hosted (there should be an index.html or index.php). You should only put the path to the folder, not the index.php file, like this: /home/yourusername/projects/mysite/public.
Also, move your project to your home directory so it won't need root permission to access it. You can move the project to /home/yourusername/projects/mysite/public
Now edit with sudo the /etc/hosts file with vim (or nano or sublime or any editor you like). And add this line:
127.0.0.1 mySite.locAnd you probably will see it like this:
127.0.0.1 localhost
127.0.0.1 mySite.locNow run the commands to enable the conf site (if you haven't done it before). Reload apache with: sudo service apache2 reload and restart apache with sudo service apache2 restart.
Ok so by now you will have your Vhosts configured correctly, but you must give correct user and group permissions to the folder in apache:
Edit the apache conf file with sudo, usually found on: /etc/apache2/apache2.conf.
Find this lines:
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}And comment them out and change them to your username and your group name that your project has the owner from, you can find this out by opening the terminal and changing directory to your project using cd and using the command ls -l, you will now see the folder and files username and group name on the left of your files and folders:
~
➜ cd Sites/mySite/public
Sites/mySite/public via 🐘 v7.2.24
➜ ls -l
total 0
-rw-r--r-- 1 mauriciogtz mauriciogtz 0 nov 5 11:15 index.phpMy files permission owner username is mauriciogtz (on the left) and my group is mauriciogtz (on the right).
Add them like this in your apache conf file:
#User ${APACHE_RUN_USER}
#Group ${APACHE_RUN_GROUP}
User mauriciogtz
Group mauriciogtzYou can use Group staff instead of the group name before if that didn't work for you.
Now look for this block of code:
<Directory />
Options FollowSymLinks
AllowOverride None
Require all denied
</Directory>Copy it all and pasted right below and change it to look like this:
<Directory /home/mauriciogtz/Sites/mySite/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>Where the Directory path should be your project path, you can use pwd inside your project folder to get the path.
Restart apache once again sudo service apache2 restart and that should be it. I hope this works for your.