0

i recently install ubuntu 22.04 and try to use LAMP on it. but i have problem with VirtualHost. i want use virtualhosts with a local domain like: test.local i added this domain to /etc/hosts and add this configuration to my test.local.conf:

<VirtualHost *:80> ServerName test.local ServerAdmin webmaster@localhost DocumentRoot /home/soroush/Sites/test <Directory "/home/soroush/Sites/test" > Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> 

and then run: a2ensite test.local.conf but when i open test.local in my browser, apache show me a 403 error. Sites/test folder and files have 0777 permission and owner is my username. what i should to do for fix this problem?

4 Answers 4

3

Add your user to the apache group then it's working fine

sudo usermod -g www-data <YOUR_USERNAME>

Sign up to request clarification or add additional context in comments.

Comments

1

By default, Ubuntu does not allow access through the web browser to any file apart of those located in /var/www, public_html directories (when enabled) and /usr/share (for web applications). If your site is using a web document root located elsewhere (such as in /srv) you may need to whitelist your document root directory in /etc/apache2/apache2.conf. The default Ubuntu document root is /var/www/html. You can make your own virtual hosts under /var/www.

This is different to previous releases which provides better security out of the box.

To solve the problem:

  1. Move your source code to /var/www

    Example: /var/www/site

2.Fix your Virtualhost

<VirtualHost *:80> ServerName test.local ServerAdmin webmaster@localhost DocumentRoot /var/www/site <Directory "/var/www/site" > Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> 

1 Comment

thanks for your reply, but I need my site files under the home directory. I switch back to fedora ... :) Ubuntu is becoming more and more like Windows ...
0

All tihs info are ok, I only add a row of my site into the /etc/hosts file:

127.0.0.1 my-site

Comments

-1

my soluttion was a downgrade to 20.04 ;) sorry if I can't give you a better solution.

2 Comments

Thanks, I switch back to fedora ... :) Unfortunately, Ubuntu is becoming more and more like Windows ...
Not a valid answer just add your user to apache group

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.