Ubuntu: What Steps are need to host a Website on Ubuntu using Apache2?


I successfully run one website on apache2 using a tutorial. My second website, I can't reach locally, and I don't know why.

Here are the steps I follow :

  1. copy my website to folder /data/mywebsite
  2. create symlink to /var/www/mywebsite
  3. configurate /etc/apache2/sites-available/mywebsite like this :
<VirtualHost *:80>          ServerAdmin me@localhost.de          ServerName localhost          DocumentRoot /var/www/mywebsite            <Directory /var/www/mywebsite>                  Options Indexes FollowSymLinks MultiViews                  AllowOverride All                  Order allow,deny                  Allow from all          </Directory>  </VirtualHost>  

now I enable this page using apache2 and then restart apache2

sudo a2ensite mywebsite  sudo service apache2 restart  

but instead of my page, I only see my www folder. I guess I linked something wrong. Is it necessary to have this slash / behind mywebsite or something ?

I tried EVERYTHING that I can think of for some hours now.

I also tried to run it on different port and adding a Port to my apache2 ports.conf. still no success.

Any advice would be most helpful.


If you have multiple sites on one Apache httpd server, you should post the complete configuration (both VirtualHost).

I'm going to post an example config of a two site Apache server, one which serves to www.example.com and one for www.example.org:

file: /etc/apache2/sites-available/example-com

<VirtualHost>  DocumentRoot /var/www/example.com/  ServerName www.example.com    # Other directives here ...    </VirtualHost>  

file: /etc/apache2/sites-available/example-org

<VirtualHost>  DocumentRoot /var/www/example.com/  ServerName www.example.com    # Other directives here ...    </VirtualHost>  

If both your sites point to: localhost, only one site will show, one precedes the other, in other words, has a higher priority. That's wha the "ServerName" directive is there for. It will serve those who try to ener that ServerName.

So if you're only testing things on your localhost, just use the same VirtualHost and use subfolders. One site in: /var/www/site1 and the other in /var/www/site2, and point your browser to: http://localhost/site1 or http://localhost/site2.

Another solution if you don't want to have subfolders in your URL is to bypass your DNS lookup and just force some domain lookups throught the /etc/hosts file. Here is an example (You want to add to the line at the end):

file: /etc/hosts localhost example.com example.org  

Your /etc/hosts file might look different, just remember to add the two domains to the end because as I explained earlier, Apache will only serve you one VirtualHost to the same ServerName.

For more information: http://httpd.apache.org/docs/2.2/vhosts/examples.html


I didn't know about this, but I played around for a few minutes to see how it works.

I think you were doing it right but, as already mentioned, you must add something like ServerName www.site1.com to the configuration (not localhost). Then enable the site, restart Apache, etc.

Also, as noted in http://httpd.apache.org/docs/current/vhosts/examples.html : "Apache server does not magically cause DNS entries to be created for those host names. You must have the names in DNS, resolving to your IP address".

For local testing, you can edit the /etc/hosts file and add the site name (the www.site1.com used above) as alias for localhost, by changing the line that says localhost to localhost www.site1.com (replace www.site1.com by the name of your site). Then restart your browser and point it to the name of your site, to see if it works.

Or you could forget all these configurations and simply write localhost/mywebsite in your browser to access your site, but it seems it's not what you want.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »