You don't have permission to access / on this server - apache

I'm on linux mint and I want to configure a virtual host for my symfony 3 application.
this is my Vhost on /etc/apache2/sites-available/evaluation.conf :
<VirtualHost *:80>
ServerName evaluation.dev
ServerAlias www.evaluation.dev
DocumentRoot /home/sahnoun/InternshipPFE/Dev/systeme_evaluation/web
<Directory /home/sahnoun/InternshipPFE/Dev/systeme_evaluation/web>
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
I've added the host in /etc/hosts like that :
127.0.0.1 evaluation.dev
That's not wrking for me and it return this error :
Forbidden
You don't have permission to access / on this server.
Apache/2.4.18 (Ubuntu) Server at evaluation.dev Port 8

Maybe you need to grand files access rights
chown -R www-data:www-data /home/sahnoun/InternshipPFE/Dev/systeme_evaluation/web
chmod -R 755 /home/sahnoun/InternshipPFE/Dev/systeme_evaluation/web
and
move the VirtualHost file from /etc/apache2/sites-available/evaluation.conf to /etc/apache2/sites-enabled/evaluation.conf

Related

403 Error - Apache VirtualHost - Ubuntu 22.04

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?
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:
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>
Add your user to the apache group then it's working fine
sudo usermod -g www-data <YOUR_USERNAME>
my soluttion was a downgrade to 20.04 ;) sorry if I can't give you a better solution.

Apache2 ServerName and ServerAlias not working

On a nearly fresh Ubuntu 20.04 LTS computer, I would like to set up a virtual host on my local machine. So I created a index.html under /var/www/test/ with the following content:
you have entered a test page
I have set up a test.conf file under /etc/apache2/sites-available/
with the following content:
<VirtualHost *:80>
ServerAdmin webmaster#zhihu.com
DocumentRoot /var/www/test/
ServerName zhihu.com
ServerAlias www.zhihu.com
<Directory /var/www/test/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The localhost is working:
/etc/hosts config is probably working as indicated by ping
ping zhihu.com
PING zhihu.com (127.0.1.1) 56(84) bytes of data.
64 bytes from xxx (127.0.1.1): icmp_seq=1 ttl=64 time=0.045 ms
but browser cannot bring me to the domain which should now be hosted in /var/www/test/.
I have also a2ensite test.conf and a2dissite 000-default.conf and service apache2 reload
So I think the only possible place for error to occur is ServerName and ServerAlias. Why are they not working?
Could you please enable VirtualHost using a2ensite and access site in incognito mode.
Ensure that the ssl certificate for the site includes both example.com and www.example.com
and ServerAlias is set to www.example.com

Set DocumentRoot on local directory in apache

I got a local directory, which will need a DocumentRoot.
When I go to serverip/nivon-zuidholland I must have a DocumentRoot of public.
How would I manage this in apache2 config?
I inserted this in my apache2.conf. I tried to put this into my sites-available/nivon-zuidholland.conf but this doesn't work as well.
I can't restart apache2 because it returns DocumentRoot not allowed here.
<Directory "/var/www/html/nivon-zuidholland">
AllowOverride All
DocumentRoot /var/www/html/nivon-zuidholland/public
</Directory>
In your /etc/hosts add this:
127.0.0.1 nivon-zuidholland.local
Create a directory: /var/www/nivon-zuidholland (set group to www-data)
Create a Virtual host file: /etc/apache2/sites-available/nivon-zuidholland.conf
<VirtualHost *:80>
ServerName nivon-zuidholland.local
ServerAdmin webmaster#nivon-zuidholland.local
DocumentRoot /var/www/nivon-zuidholland
ErrorLog ${APACHE_LOG_DIR}/nivon-zuidholland_error.log
CustomLog ${APACHE_LOG_DIR}/nivon-zuidholland.log combined
</VirtualHost>
Place a symbolic link to this vhost conf file in sites-enabled directory
ln -s /etc/apache2/sites-available/nivon-zuidholland.conf /etc/apache2/sites-enabled/nivon-zuidholland.conf
Restart Apache server: sudo service apache2 restart
You should be able to access the site by going to: http://nivon-zuidholland.local/

Fedora httpd.conf virtualhost

I trying to move localhost to home folder, but I get an error 403. Here end of httpd.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/valera5505/sites/localhost
ServerName localhost
<Directory /home/valera5505/sites/localhost>
AllowOverride All
Order allow,deny
Require all granted
</Directory>
</VirtualHost>
Try this (I'm not an Apache pro) :
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/valera5505/sites/localhost
ServerName localhost
<Directory /home/valera5505/sites/localhost>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
And try (I'm still not a professional Linux user ):
chmod 755 /home/valera5505
chmod 755 /home/valera5505/sites
chmod 755 /home/valera5505/localhost
Have you assigned correct privileges ?
chown apache:apache -R /home/valera5505/sites
chmod 775 -R /home/valera5505/sites
using -R param is better
also join your user at the apache group
hope you help

Apache: Virtual Host configuration

As i tried to configure my virtual host in apache. I put something like this,
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
And in my hosts file i put something like this,
127.0.0.1 localhost
127.0.0.1 gift.loc
And i run it on the browser,
http://gift.loc - is fine
But when i tried using this,
http://localhost/othersite - can't found
Do i missed somehting to configure? ANy ideas...
Thanks in advance,
You need a VirtualHost entry for every host you want apache to handle. The first one in the config file will be used as the default if no other VirtualHosts match the request.
For example if we have:
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /example/htdocs/gift
ServerName example.com
</VirtualHost>
A request for foobar.org will get handled by the gift.loc virtual host.
you need to put localhost in the vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /xampp/htdocs/gift
ServerName gift.loc
</VirtualHost>
This works fine (Make sure you restart apache). If you need to check your configuration you can (on linux at least) run httpd -S.
There are few steps you need to follow to setup the virtual host on ubuntu:
Let say that your project folder name is myProject
Step 1:Place your folder inside /var/www/html
sudo mv ~/myProject /var/www/html/
Step 2: Give ownership of project folder to www-data
sudo chown -R www-data:www-data /var/www/html/myProject
Step 3:Create new site inside Sites available:
cd /etc/apache2/sites-available/
ls
Here you will see existing 000-default.conf and default-ssl.conf .Copy the content of both file into one file and replace your folder name or copy this one into new file named myProject.conf
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myProject/
ServerName project.com
ServerAlias www.project.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/myProject/
ServerName project.com
ServerAlias www.project.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/mobidev_cert.pem
SSLCertificateKeyFile /etc/ssl/certs/mobidev_key.pem
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
Include the path of self signed certificate also in this as shown ssl key and ssl certificate that can be downloaded easily.
Step 4:Add your project into apache configuration file.
sudo vi /etc/apache2/apache2.conf
put this lines in the file:
DocumentRoot "/var/www/html/myProject"
<Directory /var/www/html/myProject/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Step 5:Add your virtual server name (specified in myProject.conf) into host file.add that line:
sudo gedit /etc/hosts
127.0.1.1 project.com
Step 6:Now all set ,enable site,restart apache
sudo a2ensite /etc/apache2/sites-availabl/myProject.conf
sudo systemctl reload apache2
sudo update-rc.d apache2 defaults
sudo update-rc.d mysql defaults
sudo a2enmod ssl
sudo a2ensite default-ssl
Just hit project.com in your browser.
From the docs, it looks like we need to create a block for each different host that you would like to serve.
Further in the same doc, If you are adding virtual hosts to an existing web server, you must also create a block for the existing host.