Apache2 403 Forbidden in custom document root - apache

I have searched anything on this topic in the internet and i just cannot get it to work. I am desperate....
I just want to access my index.php inside a custom document root folder but i keep getting this error
The new document root that i want instead of the /var/www/html default is called
/home/ever/FH/SKS/frontend
I have set all the permission recursively to 775 for this folder and all subfolders.
The main apache configuration file /etc/apache2/apache2.conf looks like this:
Most instructions i have found on how to set a new directory root, told me to just change the path inside the /etc/apache2/sites-available/000-default.conf file to point to my new document root.
My 000-default.conf:
I also tried a version of the 000-default.conf file that looked like this:
The symlinks should be corrrect:
I have not set up any .htaccess file or changed anythign else.
Please help me... i am desperate. In XAMPP this is done super easy, but i refuse that this cannot be done with the normal Apache server too. It cant be THAT big of a deal can it ?

It seems that in version 2.4 of the apache webserver i have to use
<Directory /var/www/foo>
Require all granted
</Directory>
instead of 2.2 syntax
<Directory /var/www/example.com>
Order allow,deny
Allow from all
</Directory>
furthermore i have to place the configuration inside the
/etc/apache2/apache2.conf
file instead of the
/etc/apache2/sites-available/000-default.conf
file.
My apache2.conf now looks like this:
allowing me to finally access the file WITHOUT PHP support it seems....
but this is another long complicated battle that never happened before with XAMPP i guess.....

Related

Is it possible to change Apache web root directory on Ubuntu except home directory?

Can't change Apache web root directory on Ubuntu.
file exists in sites-enabled folder
I changed /etc/apache2/sites-enabled/mynewsite.conf file document root
<Directory /media/saptarshi/BAAA7114AA70CDFF/webdev>
Options Indexes FollowSymLinks
Allow from all
AllowOverride None
Require all granted
</Directory>
and, also I changed /etc/apache2/apache2.conf file document root
<Directory /media/saptarshi/BAAA7114AA70CDFF/webdev>
Options Indexes FollowSymLinks
AllowOverride None
Allow from all
Require all granted
</Directory>
After changing those I restart the apache then it not worked. Shows
403 error. Forbidden
You don't have permission to access this resource. Apache/2.4.41 (Ubuntu) Server at localhost Port 80
But magically when I change the path within the home directory(/home/saptarshi/test) then it work. So , Is it possible to change apache root directory outside the home folder in ubuntu?
Two things I would like to mention. Firstly, because of something isn't working, don't write the same configurations into multiple apache config files. It will create more problems rather than solving one. Secondly, you should always edit the respective site config file in the /etc/apache2/sites-available/ directory rather than editing the file in the /etc/apache2/sites-enabled/ directory. It's a symlink, so, it's always better to edit the main file and reload the config.
Now your problem might or might not be related to directory path only. It might be a user permission related problem as well. Could you please attach the entire apache2.conf file and the mynewsite.conf file? Also, what's the host you're trying to access it with?

apache2 not using directory specified in site-available/joomla.conf

I am running a ubuntu server.
I installed apache according to this site:
https://help.ubuntu.com/community/Joomla
I then created a file called joomla.conf in the /etc/apache2/sites-available directory. It is the same as the default configuration except I changed the DocumentRoot line to DocumentRoot /var/www/joomla. That is the directory where my joomla site is.
Some websites were saying to change the <Directory> directive but my default file didn't have one so I added it, like this:
<Directory "/var/www/joomla">
</Directory>
I ran a2dissite 000-default and a2ensite joomla.conf.
/var/www/ originally contained a html directory. Even with the above steps having been performed, apache still loads from /var/www/html/index.html. I obviously haven't edited the right file or something, help is appreciated.
Another curious thing, I don't have an /etc/httpd directory, or a httpd.conf file in my apache directory. I don't know if I need that or not?
The problem was that I had edited the files in /etc/apache2/sites-enabled which was over-riding any changes made is sites-available/. The sites-enabled directory is only meant to contain symlinks to the files in sites-available.
To fix it I first removed the non-symlink files from sites-enabled then removed and and re-added the configuration with the following commands:
$ sudo a2dissite joomla
$ sudo a2ensite joomla
(joomla.conf is the name of my config file)
Then I restarted the server with sudo service apache2 reload.
You're missing a leading slash in your directive:
<Directory "var/www/joomla">
</Directory>
Instead, it should be
<Directory "/var/www/joomla">
</Directory>
Change this, disable/enable joomla.conf and restart your apache server.
If there are problems after fixing this - the full joomla.conf listing could help.
Instead of /etc/httpd in Ubuntu you have /etc/apache2. Instead of httpd.conf you have apache2.conf as a main configuration file. This is specific for Ubuntu, feels convenient after being used to it.

How to open a html file by default in my browser when i type the relevant url using apache?

I know this may be long but please bear with me..
I am using Xubuntu. I have installed apache 2.something(I think it is 2.4) using sudo install from commandline. Inside my File System folder there is var folder inside of which there is www folder inside of which there is hello folder which contains a spring mvc application made by me named Fitness Tracker.
So basically the folder structure is (FileSystem/www/hello/FitnessTracker).The root folder is encrypted so all the folder had to be created at someplace at first and then through command line using sudo all were transferred to www/hello.Fitness Tracker has a html page inside it named hellothere.html.
Now when i start apache server from command line and then type following url in my browser localhost/hello/FitnessTracker . I get a directory structure of FitnessTracker meaning it shows the html file and the other subfolders FitnessTracker contains. Now my requirement is when localhost/hello/FitnessTracker is typed in address bar of browser, I have to open hellothere.html page. How can this be done??
P.S. I have already placed a virtual host file inside my sites-available directory which contains the following code
<VirtualHost *:80>
ServerName east.example.org
DocumentRoot /var/www/hello/FitnessTracker
<Directory /var/www/hello/FitnessTracker>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Here for my code localhost/hello/FitnessTracker and http://east.example.org/ calls are synonomous which means both of them return the directory structure.
Add DirectoryIndex hellothere.html to your vhost config.
Also placing in sites-available won't be enough for you to use the vhost, it needs to be sym-linked in sites-enabled, or run sudo a2ensite mysite and sudo /etc/init.d/apache2 restart

Prevent Code Execution from External Acess

Here is my directory structure
root
private
public
Using .htaccess and/or httpd.conf, I want to limit access to the private folder to only code executed from the root folder. So, no external access to anything in the private folder. Honestly, I have tried a lot of options, but nothing seems to work.
My test environment is XAMPP - installed on my local machine.
EDIT
One of the issues I encountered was using the wrong directory path. I created a simple PHP page with just phpinfo()
<?php
phpinfo();
?>
In the PHP Variables section, I looked for _SERVER["CONTEXT_DOCUMENT_ROOT"]. I used this for the directory path and then added private (the folder in the root that I wanted to limit access to). Thus, my completed code in the httpd.conf is below:
<Directory "E:/xampp/htdocs/home/private">
Order deny,allow
Deny from all
</Directory>
Using Order deny,allow and Deny from all should be already sufficient
Order deny,allow
Deny from all
If you put this in a .htaccess in the private folder, all access from outside will be prohibited.
Alternatively, you can put it in a <Directory /path/to/root/private> in httpd.conf, which has the same effect
<Directory /path/to/root/private>
Order deny,allow
Deny from all
</Directory>
Update:
According to Apache HTTP Server Tutorial: .htaccess files you should prefer httpd.conf over .htaccess files
You should avoid using .htaccess files completely if you have access to httpd main server config file. Using .htaccess files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.

How to allow files to be accessed by scripts but not the internet - Apache

I wish to set up an apache server running php. I want all the files in a particular folder (say /site/ ) to be accessible from www.example.com/ . However I wish the files in /site/data/ to be not visible through www.example.com/data/ . I want www.example.com/fun.php script to be able to read/write to /site/data/ . What is the best way to do this through premissions and the apache defalt file?
You need to set up your directory structure slightly differently to what you have proposed. Rather run your site under a directory like:
/site/html
and store your data under a directory like:
/site/data
configuring Apache to only serve files from /site/html and not /site/data
or if you are using a more traditional apache directory structure then put the files you want publicly accessible through the web server in:
/var/www/html
and the private data files you only want your application to have access to in something like:
/var/www/data
Your Apache conf file will then contain something like:
DocumentRoot "/var/www/html"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
This way the files in /var/www/data will not be publicly accessible but these files can still be accessed by php scripts in /var/www/html/
Disable Apache directory listings by putting this in your .htaccess file under /site/data
Options -Indexes