Apache Virtual Hosts DocumentRoot path - apache

[1] DocumentRoot /var/www/example.com/public_html
[2] DocumentRoot /var/www/example_com/public_html
Which one option is it more preferable? Dotted or underscored?
And once file /etc/apache2/sites-available/example.com.conf is changed, is it needed to re-run also $ sudo a2ensite example.com.conf ? Or change itself is enough? Thanks!

Each option is ok, it's as you want. For my part, on my dedicated server, I'll use example.com syntax.
When you run $ sudo a2ensite example.com.conf for the first time, a symlink is created from /etc/apache2/sites-available/example.com.conf to /etc/apache2/sites-enabled/example.com.conf.
You can change this file at two location, because it's the same file.
If you want to disable your vhost, you should run $ sudo a2dissite example.com.conf

Related

Host Multiple Domains on One Server/IP

I have phpList already setup and Codeigniter project that I want to add in one server.
The phpList configuration which is located /etc/httpd/conf.d/phplist.conf has:
<VirtualHost *:80>
ServerName phplist.example.com
ServerAdmin admin#example.com
DocumentRoot /var/www/phplist-3.0.5/public_html
LogLevel warn
ErrorLog /var/log/httpd/phplist_error.log
CustomLog /var/log/httpd/phplist_access.log combined
</VirtualHost>
Here is my possible setting for the CI project, but I don't know how to create one.
<VirtualHost *:80>
ServerName listcsv.com
ServerAdmin admin#listcsv.com
DocumentRoot /var/www/citest/index.php
</VirtualHost>
Below the /etc/httpd/conf/httpd.conf file has a IncludeOptional conf.d/*.conf so I think this would include the configuration file on phplist.
I don't know what settings and where configuration file should I go,
should I edit on /etc/httpd/conf/httpd.conf or just add it together with the phpList configuration at /etc/httpd/conf.d/phplist.conf?
I tried accessing phplist at http://phplist.example.com but the site cannot be reached.
I could access the phpList by going to http://server-ip-address/lists/admin on the browser.
Also, I cannot access the CI project.
I would recommend creating the directory that the virtual hosts will be stored in, as well as the directory that tells Apache that a virtual host is ready to serve the website
sudo mkdir /etc/httpd/sites-available # vhost files
sudo mkdir /etc/httpd/sites-enabled # symbolic links for vhost enabled
Tell Apache where to look for virtual hosts
sudo vim /etc/httpd/conf/httpd.conf
Add this line at the end of the file
IncludeOptional sites-enabled/*.conf
Save and exit.
For each website/domain create its own vhost
sudo vim /etc/httpd/sites-available/example1.com.conf
sudo vim /etc/httpd/sites-available/example2.com.conf
sudo vim /etc/httpd/sites-available/example3.com.conf
Enable the virtualhost
sudo ln -s /etc/httpd/sites-available/example1.com.conf /etc/httpd/sites-enabled/example1.com.conf
sudo ln -s /etc/httpd/sites-available/example2.com.conf /etc/httpd/sites-enabled/example2.com.conf
sudo ln -s /etc/httpd/sites-available/example3.com.conf /etc/httpd/sites-enabled/example3.com.conf
We done, restart your Apache server for the changes to take affect
sudo apachectl restart
Don't forget to point your domains to the web server's public IP address.

VHost Not Working using AWS AMI httpd

I'm currently creating an application using AWS AMI, and it comes w/ an httpd 2.4.10. Here was the steps I followed on creating the vhost
sudo mkdir /etc/httpd/sites-available
sudo mkdir /etc/httpd/sites-enabled
edited /etc/httpd/conf/httpd.conf to have IncludeOptional sites-enabled/*.conf
created realtydig.conf inside /etc/httpd/sites-available
symlinked it to /etc/httpd/sites-enabled
sudo apachectl restart
sudo service httpd restart
*still the default httpd page is the one showing, vhost not pointing to domain
here's the vhost
xml
<VirtualHost *:80>
ServerName beta.realtydig.com
DocumentRoot /var/www/realtydig/laravel
<Directory "var/www/realtydig/laravel/public">
AllowOverride all
</Directory>
</VirtualHost>
I would like to understand, what happened wrong. It seems to be loading up since error occured w/ some of my previous typos when i was trying to restart the application.
If "nothing happened" then I assume that you see just white empty page in browser. Usually some other vhost will be see if current vhost is not activated.
DocumentRoot must be pointing to the public folder like this
DocumentRoot /var/www/realtydig/laravel/public
You can debug by creating test.html inside the DocumentRoot and try to access it from the browser.

Error with DocumentRoot in new Vagrant

I'm attempting to use Jeffrey Way's Vagrant setup (https://github.com/JeffreyWay/Vagrant-Setup) and it almost works for me on a Mac running Yosemite. When Apache restarts at the very end, I get an error stating:
==> default: AH00112: Warning: DocumentRoot [/var/www/html] does not exist
==> default: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Prior to that in his install.sh, he's deleting the html directory and doing a symlink it looks like (I'm new to this, sorry).
To fix it, I ssh into Vagrant, edit /etc/apache2/sites-available/000-default.conf and change the DocumentRoot from /var/www/html to just /var/www and then I'm able to view my site on localhost:8080.
How should I be doing this though so it just works out of the box?
Add the below line after the line sudo ln -fs /vagrant/public /var/www (#38) in install.sh
sed -i "s#DocumentRoot /var/www/html#DocumentRoot /var/www#g" /etc/apache2/sites-available/000-default.conf
Running the updated install script should automatically replace the DocumentRoot from /var/www/html to just /var/www

Error starting apache from terminal after removing MAMP

I removed MAMP recently.
When I try to start apache from Terminal using:
sudo apachectl -k restart
I am getting the message
Warning: DocumentRoot [usr/docs/dummy-host.example.com] does not exist.
First, make sure you're actually trying to execute the proper version of apachectl by issuing the following command:
which apachectl
(You don't want to see any MAMP references there).
Next, find your virtual hosts config (which is likely here if your MAMP references are gone)
/etc/apache2/extra/httpd-vhosts.conf
Make sure your virtual host definitions are good. (Sounds like you're referencing a bad one).
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot "/Users/yourusername/Sites/mysite"
ServerName mysite.local
ErrorLog "/private/var/log/apache2/mysite-error_log"
CustomLog "/private/var/log/apache2/mysite-access_log" common
</VirtualHost>
(If you're using a custom server name other than 'localhost' like I've defined above, just be sure your /etc/hosts file is up to date with that entry like this:
127.0.0.1 mysite.local
Don't forget to restart apache!
sudo apachectl restart
You probably need to go to apache config file (something like etc/apache2/apache2.conf) and set it an existing document root directory. That is usually done with DocumentRoot directive in this file, or one of the included virtual host config definitions.
Make sure you comment out all the lines inside the /etc/apache2/extra/httpd-vhosts.conf file otherwise you will get the errors.

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...