Apache 2.4 Can only Use htdocs as webroot - osx-yosemite

I set up Apache 2.4 yesterday, and it is working with the htdocs folder I set up in my home directory. However, I do not want to use htdocs, I want to use a folder in my ~/Documents/web/<project> directory. I have tried altering /etc/apache2/httpd.conf and /etc/apache2/users/<username>.conf to no avail. Does anyone have any ideas?

FOR WINDOWS:
please try to modify <your-apache-dir>\conf\http.conf.
Open http.conf in the above directory
Search for DocumentRoot
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "c:/Apache24/htdocs"
Modify the above bolded path.
Restart your apache.
(Note: Restarting apache is important. Any changes you made in apache and php, you have to restart the apache.)
FOR OSX:
Other than modifying the /etc/apache2/httpd.conf and /etc/apache2/users/<username>.conf,
you need to do one more change, otherwise the WebSharing won't be able to turn on again. (according to David_Wang)
Open your httpd.config (Probably need to do this if you haven't change the permission access to this file)
sudo chmod 666 httpd.conf
Open httpd.config, and start editing.
sudo chmod 644 httpd.conf, when it's finished, proceed to step 2 (change it back to original permisson access)
Find DocumentRoot "/Library/WebServer/Documents", and change it to DocumentRoot "/Users/leiwang/Sites" or any other folders you want to.
One important thing is, you need to give the Read/Write permission to the folder you specified.
sudo chmod -R 747 foldername
(ref: change web root apache mac OS X)

You need to add a <Directory> section (with Requrie all granted) each time you add a new DocumentRoot if it's not within the original document root.

Related

How to change Apache root directory

I know that there are several other questions asking this. However, I still have problems.
I am trying to change my Apache root server directory from the default /var/www/html on my Debian server. To do this, I modified /etc/apache2/sites-available/000-default.conf to have DocumentRoot /var/www instead of DocumentRoot /var/www/html. After doing this and saving it, I ran apache2ctl restart to reload the server. However, the server still looks for files in /var/www/html instead of /var/www. Is there something else I need to change?
Just make sure you are "landing" in the VirtualHost you are modifying.
You can check the virtualhosts being loaded with this command:
apachectl -S
Note: It is not ServerRoot what you are describing, it is DocumentRoot, there is a big diffrence between each, so better name them properly.

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

How do I point Apache document root to a specific folder in Ubuntu?

I have a site that the root points to /var/www
I have set up two folders under /var/www
/var/www/old
/var/www/new
for the old folder, I have used the following to deny any access:
touch /var/www/old/.htaccess && echo deny from all >> /var/www/old/.htaccess
I now want the server to point the root to /var/www/new so that when people visit http://example.com the content in /var/www/new will serve, what should I do?
In Ubuntu the Apache configuration is located at /etc/apache2. There should be two folders, sites-available and sites-enabled. Inside sites-enabled are symlinks to config files in sites-available.
You simply have to change the document root in your activated configuration. Thats probably /etc/apache2/sites-enabled/000-default
Have a look for DocumentRoot and change it to /var/www/new, then reload your apache.
depends a LOT on how your apache server is configured.
I don't have an Ubuntu machine around, but what you're looking for is the DocumentRoot directive. On RedHat based machines it's normally in /etc/httpd/conf/httpd.conf but if memory serves Debian based systems use apache instead of httpd.
If that doesn't work be sure to check in /etc/httpd/conf.d since the files there are loaded dynamically.
Hope this helps :)

Apache - multiple websites - allow top folder access

I have multiple websites setup on my Apache2 server. The directory structure is as follows:
/var/www/
/var/www/site1.com
/var/www/site2.com
It is setup such that "www.site1.com" has root folder /var/www/site1, "www.site2.com" has root folder /var/www/site2, and http://server_ip_address has root folder /var/www
However, if I type http://server_ip_address/site1.com, it opens site1.com. I don't want this to happen. (That is, individual sites should be accessible only by typing the correct address).
What is the way to configure this. (Also it would be helpful if you could give tips on best practices for directory structures for multiple websites)?
thanks
JP
The VirtualHost directive can be used to set individual DocumentRoots for each site name.
Have also a look at this document:
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Configure multiple websites on Ubuntu
Create apache configuration file:
sudo nano /etc/apache2/sites-available/site1.com
Minimal configuration for the virtual host:
<VirtualHost *:80>
DocumentRoot /var/www/site1.com
ServerName www.site1.com
# Other directives here
</VirtualHost>
Create the root folder:
sudo mkdir /var/www/site1.com
Change the permissions of the folder:
sudo chmod -R 775 /var/www/site1.com/
Create a new record in /etc/hosts
sudo nano /etc/hosts
Add the following line:
127.0.0.1 www.site1.com
Create a correct symlinks in sites-enabled:
sudo a2ensite site1.com
Restart the apache:
sudo /etc/init.d/apache2 restart
You have to do the same with the site2.com, site3.com etc...