403 error after setting up vhosts - linux

I am running a CentOS 6 server (on Digital Ocean) which has apache 2.2 installed.
I installed ProFTP and have set up a user called 'rator' with whom I can ftp in to the home directory at /home/rator/
I want this directory to be a working web development environment and have set up a further two sub dirs - dev and stage.
In the dev folder I have cloned my git repo and have ended up with the rather long path:
/home/rator/dev/rator/
I want to set up a vhost to this directory. I have set up my hosts file for rator.dev on my local machine, and have the following in the vhosts section of /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
ServerAdmin me#email.com
DocumentRoot /home/rator/dev/rator
ServerName rator.dev
ErrorLog rator.dev-error_log
CustomLog logs/rator.dev-access_log common
<Directory /home/rator/dev/rator>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
When I try to view this in the browser - I get a 403 error. "You don't have permission to access / on this server."
If I chown apache:apache all of the dirs and files below /home/ then the site becomes visible however, I then cannot log in through ftp as the ftp home dir is then owned by apache and I'm logging in as 'rator'.
I have tried many variants on the Vhosts directory permissions but so far have not been able to solve the access problem.
Does anybody know what the correct vhosts should be here?

Ok, turned out to be pretty dumb....
sudo chmod o+rx /home/rator
Execute and read permissions were not set correctly on the home folder....

Related

How do I set up my public_html dir in EC2? [duplicate]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
How can I change the document root of the Apache server? I basically want localhost to come from /users/spencer/projects directory instead of /var/www.
I ended up figuring it out. Some suggested I change the httpd.conf file, but I ended up finding a file in /etc/apache2/sites-available/default and changed the root directory from /var/www to /home/myusername/projects_folder and that worked.
Please note, that this only applies for Ubuntu 14.04 LTS (Trusty Tahr) and newer releases.
In my Ubuntu 14.04 LTS, the document root was set to /var/www/html. It was configured in the following file:
/etc/apache2/sites-available/000-default.conf
So just do a
sudo nano /etc/apache2/sites-available/000-default.conf
and change the following line to what you want:
DocumentRoot /var/www/html
Also do a
sudo nano /etc/apache2/apache2.conf
and find this:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
And change /var/www/html to your preferred directory and save it.
After you saved your changes, just restart the Apache 2 web server and you'll be done :)
sudo service apache2 restart
If you prefer a graphical text editor, you can just replace the sudo nano with a gksu gedit.
You need to change the DocumentRoot setting in your httpd.conf file. Chances are it will be under something like /etc/apache2/conf/httpd.conf.
Use your favourite editor (I recommend Vim) and look for the DocumentRoot and change it to /users/spencer/projects. Also look a little further down for a setting that looks like this:
<Directory "/var/www">
You will also want to change what is in the quotes to your new directory. This gives Apache access to read from that directory when a user makes a request that call on it.
Now restart your Apache service (httpd -k restart) and you should be good to go.
Apache 2 site configuration files are now typically kept in /etc/apache2/sites-available/ (Debian, Ubuntu, etc.).
I had to edit /etc/apache2/sites-available/default. The lines are the same as mentioned by RDL.
This is for Ubuntu 14.04 (Trusty Tahr):
In file /etc/apache2/apache2.conf it should be as below without the directory name:
<Directory /home/username>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And in file /etc/apache2/sites-available/000-default.conf you should include the custom directory name, i.e., www:
DocumentRoot /home/username/www
If it is not as above, it will give you an error when loading the server:
Forbidden You don't have permission to access / on this server
The right way to change directory or run from multiple directories under different port for Apache 2 is as follows:
For Apache 2, the configuration files are located under /etc/apache2 and doesn’t use a single configuration file as in older versions but is split into smaller configuration files, with /etc/apache2/apache2.conf being the main configuration file. To serve files from a different directory we need a new virtualhost conf file. The virtualhost configuration files are located in /etc/apache2/sites-available (do not edit files within sites-enabled). The default Apache installation uses virtualhost conf file 000-default.conf.
Start by creating a new virtualhost file by copying the default virtualhost file used by the default installation of Apache (the one that runs at localhost on port 80). Change into directory /etc/apache2/sites-available and then make copy by sudo cp 000-default.conf example.com.conf, now edit the file by sudo gedit example.com.conf to:
<VirtualHost *:80>
ServerAdmin example#localhost
DocumentRoot /home/ubuntu/example.com
</VirtualHost>
I have deleted the nonimportant lines from the above file for brevity. Here DocumentRoot is the path to the directory from which the website files are to be served such as index.html.
Create the directory from which you want to serve the files, for example, mkdir example.com and change owner and default group of the directory, for example, if your logged in user name is ubuntu change permissions as sudo chown ubuntu:www-data example.com. This grants full access to the user ubuntu and allows read and execute access to the group www-data.
Now edit the Apache configuration file /etc/apache2/apache2.conf by issuing command sudo gedit apache2.conf and find the line <Directory /var/www/> and below the closing tag </Directory>, add the following below:
<Directory /home/ubuntu/example.com>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Now there are two commands to enable or disable the virtualhost configuration files, which are a2ensite and a2dissite respectively. Now since our example.com.conf file uses the same port(80) as used by the default configuration file(000-default.conf), we have to disable the default configuration file by issuing the command sudo a2dissite 000-default.conf and enable our virtualhost configuration file by sudo a2ensite example.com.conf
Now restart or reload the server with command sudo service apache2 restart. Now Apache serves files from directory example.com at localhost on default port of 80.
The a2ensite command basically creates a symbolic link to the configuration file under the site-enabled directory.
Do not edit files within sites-enabled (or *-enabled) directory, as pointed out in this answer.
To change the port and run from multiple directories on different ports:
Now if you need to run the directory on a different port, change the port number from 80 to 8080 by editing the virtualhost file as:
<VirtualHost *:8080>
ServerAdmin user#localhost
DocumentRoot /home/ubuntu/work
</VirtualHost>
and editing /etc/apache2/ports.conf and adding Listen 8080 just below the line Listen 80
Now we can enable the default virtualhost configuration file that runs on port 80 since example.com directory uses port 8080, as sudo a2ensite 000-default.conf.
Now restart or reload the server with command sudo service apache2 restart. Now both the directories can be accessed from localhost and localhost:8080.
If you couldn't find http.conf and followed Nick's way.
Restart Apache using sudo service apache2 restart.
I was working with LAMP and to change the document root folder, I have edited the default file which is there in the
/etc/apache2/sites-available folder.
If you want to do the same, just edit as follows:
DocumentRoot /home/username/new_root_folder
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/username/new_root_folder>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
After this, if you type "localhost" in the browser, it will load the /home/username/new_root_folder content.
For Apache 2 on Linux Mint 17.3 Cinnamon 64-bit, the following works:
In /etc/apache2/sites-available/ open the 000-default.conf file, and change the Document Root to the absolute path of your directory.
sudo vim /etc/apache2/sites-available/000-default.conf
In folder /etc/apache2/ open file httpd.conf, and add a <Directory> tag referencing your directory and containing the exact same settings as the tag for var/www.
sudo vim /etc/apache2/apache2.conf
On my machine it looked like this:
<Directory /home/my_user_name/php/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Note: In the first step you probably want to change Document Root in the default-ssl.conf file as well for SSL purposes. But as far as I can tell, this isn't required to get a general development environment running.
In Apache version 2.4.18 (Ubuntu).
Open the file /etc/apache2/apache2.conf and
search for <Directory /var/www/> and replace to your directory.
Open file /etc/apache2/sites-available/000-default.conf, search for DocumentRoot /var/www/html and replace it with your DocumentRoot.
In case you are using Ubuntu 16.04 (Xenial Xerus), please update the 000-default.conf file in the directory /etc/apache2/sites-available.
Here →
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/YourFolder
The following applies to Ubuntu 14.04 (Trusty Tahr) and later releases. Make sure to back up following files before making any changes.
Open /etc/apache2/apache2.conf and search for <Directory /var/www/> directive and replace path with /home/<USERNAME>/public_html. You can use * instead of .
Open /etc/apache2/sites-available/000-default.conf and change the DocumentRoot value property from /var/www/html to /home/<USERNAME>/public_html. Also <Directory /var/www/html> to <Directory /home/<USERNAME>/public_html.
Open /etc/mods-available/php7.1.conf. Find and comment the following code
php_admin_flag engine Off
Do not turn the php_admin_flag engine OFF flag on as the reason is mentioned in a comment above the Directive code. Also the PHP version can be 5.0, 7.0 or anything you have installed.
Create public_html directory in home/<USERNAME>.
Restart the Apache service by executing command sudo service apache2 restart.
Test by running a sample script on the server.
I had made the /var/www to be a soft link to the required directory (for example, /users/username/projects) and things were fine after that.
However, naturally, the original /var/www needs to be deleted - or renamed.
If someone has installed LAMP in the /opt folder, then the /etc/apache2 folder is not what you are looking for.
Look for httpd.conf file in folder /opt/lampp/etc.
Change the line in this folder and save it from the terminal.
If you're using Linux Mint (personal opinion, from all distributions this one is making me happy), follow this:
Go to folder /etc/apache2/sites-available and edit file 000-default.conf.
Search for DocumentRoot, example DocumentRoot /var/www/html. You change to your respective directory;
Open a terminal and type: sudo service apache2 restart
In Linux Mint, you go for file /etc/apache2/apache.conf. Replace /var/www with your respective path, and then restart the server (step 3).
That's it.
In Red Hat Linux 7.0: /etc/httpd/conf/httpd.conf

Apache on Raspberry Pi - can't serve files from a different drive - causes 403 error

I got a Raspberry Pi yesterday and have mounted an additional hard drive on it. I'm planning to use it on a web server. However, I wish to host my files on the hard drive, not the small SD card where the OS is located.
I installed Apache and created a Virtual Host config file, specifying the DocumentRoot and the directory on the external HDD where the website is located. However, it gives a 403 error. The system log gives the following information:
Permission denied: [client 123.456.789.1250527] AH00035: access to / denied (filesystem path '/media/myusername/myHDD') because search permissions are missing on a component of the path
I've tried a number of different things: setting the DocumentRoot to /var/www/html but specifying the path to the HDD in the Directory tag, changing the DocumentRoot in the default site to the path to the HDD's directory that I want to serve, adding the line DocumentRoot "/media/myusername/myHDD" in the apache2.conf file. I changed the ownership of the /myHDD folder to the www-data user. I eventually deleted the /var/www/html folder and created a symlink to the HDD's directory with the name html, but that causeed this error:
AH00037: Symbolic link not allowed or link target not accessible: /var/www/html
What do I need to do to make Apache serve these websites that are on the HDD and not the system SD (only 16GB)? Here is my VirtualHost config:
<VirtualHost *:80>
ServerAdmin me#myemail.com
ServerName myurl.com
ServerAlias www.myurl.com
DocumentRoot "/var/www/html"
Alias "/webals" "/media/userName/MyHardDrive/public_html/myurl.com/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/media/userName/MyHardDrive/public_html/myurl.com">
Require all granted
Order allow,deny
Allow from all
</Directory>
I'm not sure what is going on here. Haven't really used Apache much in the past - have preferred nginx.
Any help here would be good.

Permission denied for subdirectory in Apache

I have apache running on port 80. I have also created an additional conf file in conf.d that would open up a second port 8010 with a different directory but I am unable to get to subdirectories now of the document root of 8010
Listen 8010
<VirtualHost ip:8010>
DocumentRoot /var/www/boom
ServerName localhost
ErrorLog logs/dm-error_log
CustomLog logs/dm-access_log common
<Directory /var/www/boom>
AuthName "Protected Area"
AuthType Basic
AuthUserFile /var/www/secure/passwords
Require valid-user
</Directory>
</VirtualHost>
If I try to go to ip:8010/banq I get the following error
Forbidden You don't have permission to access /banq/ on this server.
I tried chmod 777 on banq with no luck
I had this all working great for few years and then lost all backups, had to recreate from scratch. I was able to move conf file from 1 server to another without setting any any chown and minor chmod commands. Is it possible to open all subdirectories of /var/www/boom to anyone who authenticates properly?
Two things I have encountered that could cause a similar error would be:
Apache can't access the document root of where the banq/ directory is found. Have you checked permissions on /var/www/boom? Setting the group to apache or nobody, or making the directory world readable would be a good test.
If there is no directory index in banq/ Apache may prevent you from viewing a directory listing. Try adding either an index.html page to the directory for testing, or add "Options +Indexes" to the config file.

Multiple VirtualHosts for Rails sites

I would like to run a rails app under a subdirectory on my Linux VPS, and having trawled the passenger documentation I am unsure as to how to set up the proper virtualhost config and symlinks for my machine.
I have a domain called www.domain.eu and a rails app located at /apps/webapp, and i would like the site to be hosted at www.domain.eu/webapp
Im am unsure of a few areas:
1.) Where should i enter the webapp VirtualHost config details? should it be in the apache2.conf file or should create a file in sites-available called webapp and put the config in there? There seems to be many conflicting examples.
2.) Learning from the previous question, how could I amend this apache2.conf file to serve up the rails app under the directory www.domain.eu/webapp (again read through lots of docs, but there seems to be many ways of doing this)
<VirtualHost *:80>
ServerName domain.eu
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /apps/webapp/public
<Directory /apps/webapp/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
RailsBaseURI /webapp
<Directory /apps/webapp/public>
Options -MultiViews
</Directory>
</VirtualHost>
3.) I realise that a symlink needs to be created to point the directory root to the url. Having tried ln -s /apps/webapp/public ./test it comes back with a missing symlink error. What would be recommended here?
4.) Lastly, rails 3 config.action_controller.relative_url_root = "/webapp" appears to be deprecated, is there a new recommended convention to use?
my setup: Linux VPS server running Ubuntu 10.04, mysql 5, apache2, phusion passenger (latest), ruby 1.9.3 and rails 3.2.3.
If anyone needs more code just shout, thanks in advance!
So after much reading I managed to get this working.
For my purpose I added in the VirtualHost info for a sub URI site into the bottom my apache2.conf file, it may be httpd.conf for you, but you can enter these into /etc/apache2/sites-available if you wish to keep it all seperate.
At the top of this file I specify where the default "homepage" for the server is. I am running apache2 so my homepage is located at /var/www. Below this we set our rails Sub URI options, so firstly specify what URL you would like as your sub URI, then point the directory tag to the public folder of your rails app. MultiViews must be off hence the (-) so our apache2.conf file is complete.
<VirtualHost *:80>
ServerName domain.com
DocumentRoot /var/www
<Directory /var/www>
Allow from all
</Directory>
RailsBaseURI /webapp
<Directory /apps/webapp/public>
Options -MultiViews
</Directory>
</VirtualHost>
Now all we have to do is create a symlink in our sites-enabled folder to point the /var/www/webapp to our /apps/webapp/public folder, which looks like this.
ln -s /apps/webapp/public /var/www/webapp
Now was we are creating a symlink, we don't have to insert any extra code into our rails routes or environment file. You can specify which environment you would like to use using RackENV production (aparently al rails 3 + apps are rack ? please comment if this is not the case)

How do I change the root directory of an Apache server? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 4 years ago.
The community reviewed whether to reopen this question last year and left it closed:
Original close reason(s) were not resolved
Improve this question
How can I change the document root of the Apache server? I basically want localhost to come from /users/spencer/projects directory instead of /var/www.
I ended up figuring it out. Some suggested I change the httpd.conf file, but I ended up finding a file in /etc/apache2/sites-available/default and changed the root directory from /var/www to /home/myusername/projects_folder and that worked.
Please note, that this only applies for Ubuntu 14.04 LTS (Trusty Tahr) and newer releases.
In my Ubuntu 14.04 LTS, the document root was set to /var/www/html. It was configured in the following file:
/etc/apache2/sites-available/000-default.conf
So just do a
sudo nano /etc/apache2/sites-available/000-default.conf
and change the following line to what you want:
DocumentRoot /var/www/html
Also do a
sudo nano /etc/apache2/apache2.conf
and find this:
<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
And change /var/www/html to your preferred directory and save it.
After you saved your changes, just restart the Apache 2 web server and you'll be done :)
sudo service apache2 restart
If you prefer a graphical text editor, you can just replace the sudo nano with a gksu gedit.
You need to change the DocumentRoot setting in your httpd.conf file. Chances are it will be under something like /etc/apache2/conf/httpd.conf.
Use your favourite editor (I recommend Vim) and look for the DocumentRoot and change it to /users/spencer/projects. Also look a little further down for a setting that looks like this:
<Directory "/var/www">
You will also want to change what is in the quotes to your new directory. This gives Apache access to read from that directory when a user makes a request that call on it.
Now restart your Apache service (httpd -k restart) and you should be good to go.
Apache 2 site configuration files are now typically kept in /etc/apache2/sites-available/ (Debian, Ubuntu, etc.).
I had to edit /etc/apache2/sites-available/default. The lines are the same as mentioned by RDL.
This is for Ubuntu 14.04 (Trusty Tahr):
In file /etc/apache2/apache2.conf it should be as below without the directory name:
<Directory /home/username>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
And in file /etc/apache2/sites-available/000-default.conf you should include the custom directory name, i.e., www:
DocumentRoot /home/username/www
If it is not as above, it will give you an error when loading the server:
Forbidden You don't have permission to access / on this server
The right way to change directory or run from multiple directories under different port for Apache 2 is as follows:
For Apache 2, the configuration files are located under /etc/apache2 and doesn’t use a single configuration file as in older versions but is split into smaller configuration files, with /etc/apache2/apache2.conf being the main configuration file. To serve files from a different directory we need a new virtualhost conf file. The virtualhost configuration files are located in /etc/apache2/sites-available (do not edit files within sites-enabled). The default Apache installation uses virtualhost conf file 000-default.conf.
Start by creating a new virtualhost file by copying the default virtualhost file used by the default installation of Apache (the one that runs at localhost on port 80). Change into directory /etc/apache2/sites-available and then make copy by sudo cp 000-default.conf example.com.conf, now edit the file by sudo gedit example.com.conf to:
<VirtualHost *:80>
ServerAdmin example#localhost
DocumentRoot /home/ubuntu/example.com
</VirtualHost>
I have deleted the nonimportant lines from the above file for brevity. Here DocumentRoot is the path to the directory from which the website files are to be served such as index.html.
Create the directory from which you want to serve the files, for example, mkdir example.com and change owner and default group of the directory, for example, if your logged in user name is ubuntu change permissions as sudo chown ubuntu:www-data example.com. This grants full access to the user ubuntu and allows read and execute access to the group www-data.
Now edit the Apache configuration file /etc/apache2/apache2.conf by issuing command sudo gedit apache2.conf and find the line <Directory /var/www/> and below the closing tag </Directory>, add the following below:
<Directory /home/ubuntu/example.com>
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Now there are two commands to enable or disable the virtualhost configuration files, which are a2ensite and a2dissite respectively. Now since our example.com.conf file uses the same port(80) as used by the default configuration file(000-default.conf), we have to disable the default configuration file by issuing the command sudo a2dissite 000-default.conf and enable our virtualhost configuration file by sudo a2ensite example.com.conf
Now restart or reload the server with command sudo service apache2 restart. Now Apache serves files from directory example.com at localhost on default port of 80.
The a2ensite command basically creates a symbolic link to the configuration file under the site-enabled directory.
Do not edit files within sites-enabled (or *-enabled) directory, as pointed out in this answer.
To change the port and run from multiple directories on different ports:
Now if you need to run the directory on a different port, change the port number from 80 to 8080 by editing the virtualhost file as:
<VirtualHost *:8080>
ServerAdmin user#localhost
DocumentRoot /home/ubuntu/work
</VirtualHost>
and editing /etc/apache2/ports.conf and adding Listen 8080 just below the line Listen 80
Now we can enable the default virtualhost configuration file that runs on port 80 since example.com directory uses port 8080, as sudo a2ensite 000-default.conf.
Now restart or reload the server with command sudo service apache2 restart. Now both the directories can be accessed from localhost and localhost:8080.
If you couldn't find http.conf and followed Nick's way.
Restart Apache using sudo service apache2 restart.
I was working with LAMP and to change the document root folder, I have edited the default file which is there in the
/etc/apache2/sites-available folder.
If you want to do the same, just edit as follows:
DocumentRoot /home/username/new_root_folder
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/username/new_root_folder>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
After this, if you type "localhost" in the browser, it will load the /home/username/new_root_folder content.
For Apache 2 on Linux Mint 17.3 Cinnamon 64-bit, the following works:
In /etc/apache2/sites-available/ open the 000-default.conf file, and change the Document Root to the absolute path of your directory.
sudo vim /etc/apache2/sites-available/000-default.conf
In folder /etc/apache2/ open file httpd.conf, and add a <Directory> tag referencing your directory and containing the exact same settings as the tag for var/www.
sudo vim /etc/apache2/apache2.conf
On my machine it looked like this:
<Directory /home/my_user_name/php/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Note: In the first step you probably want to change Document Root in the default-ssl.conf file as well for SSL purposes. But as far as I can tell, this isn't required to get a general development environment running.
In Apache version 2.4.18 (Ubuntu).
Open the file /etc/apache2/apache2.conf and
search for <Directory /var/www/> and replace to your directory.
Open file /etc/apache2/sites-available/000-default.conf, search for DocumentRoot /var/www/html and replace it with your DocumentRoot.
In case you are using Ubuntu 16.04 (Xenial Xerus), please update the 000-default.conf file in the directory /etc/apache2/sites-available.
Here →
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/YourFolder
The following applies to Ubuntu 14.04 (Trusty Tahr) and later releases. Make sure to back up following files before making any changes.
Open /etc/apache2/apache2.conf and search for <Directory /var/www/> directive and replace path with /home/<USERNAME>/public_html. You can use * instead of .
Open /etc/apache2/sites-available/000-default.conf and change the DocumentRoot value property from /var/www/html to /home/<USERNAME>/public_html. Also <Directory /var/www/html> to <Directory /home/<USERNAME>/public_html.
Open /etc/mods-available/php7.1.conf. Find and comment the following code
php_admin_flag engine Off
Do not turn the php_admin_flag engine OFF flag on as the reason is mentioned in a comment above the Directive code. Also the PHP version can be 5.0, 7.0 or anything you have installed.
Create public_html directory in home/<USERNAME>.
Restart the Apache service by executing command sudo service apache2 restart.
Test by running a sample script on the server.
I had made the /var/www to be a soft link to the required directory (for example, /users/username/projects) and things were fine after that.
However, naturally, the original /var/www needs to be deleted - or renamed.
If someone has installed LAMP in the /opt folder, then the /etc/apache2 folder is not what you are looking for.
Look for httpd.conf file in folder /opt/lampp/etc.
Change the line in this folder and save it from the terminal.
If you're using Linux Mint (personal opinion, from all distributions this one is making me happy), follow this:
Go to folder /etc/apache2/sites-available and edit file 000-default.conf.
Search for DocumentRoot, example DocumentRoot /var/www/html. You change to your respective directory;
Open a terminal and type: sudo service apache2 restart
In Linux Mint, you go for file /etc/apache2/apache.conf. Replace /var/www with your respective path, and then restart the server (step 3).
That's it.
In Red Hat Linux 7.0: /etc/httpd/conf/httpd.conf

Resources