How to use several sites in Ubuntu Dedicated Server?

Asked

Viewed 46 times

0

Hello, my friends!

Context: I have a dedicated server to host web applications.

  • The root directory of it is default/var/www/html of any server.
  • I want to host, first, a website.
  • In the root folder (/var/www/html) is the phpmyadmin and the website (that is, two folders)
  • I’m updating the site files via GIT, IE, it has to stay in a separate folder, in case the "site" folder. And also to use GIT pull and not trouble with the folder phpmyadmin

Problem: The problem is that ALL the files I call externally are coming from root, for example

<link href="/css/style.css">

That is, it is calling the following path:

/var/www/html/css/style.css

You have solutions to add the folder website, as follows:

<link href="/site/css/style.css">

But that is not the proposal. If you did so, you would have to change everything in an entire application and it would be harder to work locally and collaborate with other people.

Question: I would like to know what is the right way to do this and to work, in the future, also with more sites and folders within /var/www/html, without changing the path of the entire application and hindering the functioning of git?

Considerations: If it’s not clear enough, please let me know that I’ll try to go into more detail!

1 answer

1


To host multiple applications on a server you need to configure Virtualhosts on Apache.

With this, you have a website in each folder and points each of the domains to a different Directoryroot.

Creating a configuration file for the siteA. This file should be in /etc/apache2/sites-available/sitea.conf

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName sitea.com.br
    DocumentRoot /var/www/sitea/public
    ErrorLog ${APACHE_LOG_DIR}/sitea-error.log
    CustomLog ${APACHE_LOG_DIR}/sitea-access.log combined
</VirtualHost>

Create the folder and upload the sitea in /var/www/sitea/public as defined in the configuration DocumentRoot

Now mark your domain (sitea.com.br in the example) to the IP of this server.

And enable the website with the command a2ensite sitea. Remembering that this command expects to receive the name of the configuration file that is in the directory /etc/apache2/sites-available

Repeat the process for as many Virtualhosts as you need.

Ah! And, if you need a domain name, you can use as many as you want with the Serveralias configuration, but don’t forget to set up your domain’s DNS zone. Example:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName sitea.com.br
    ServerAlias www.sitea.com.br teste.sitea.com.br
    DocumentRoot /var/www/sitea/public
    ErrorLog ${APACHE_LOG_DIR}/sitea-error.log
    CustomLog ${APACHE_LOG_DIR}/sitea-access.log combined
</VirtualHost>

See this tutorial: https://www.digitalocean.com/community/tutorials/como-configurar-apache-virtual-hosts-no-ubuntu-14-04-lts-pt

  • I’ll read the article and I’ll come back and tell you if it worked. Thanks, buddy!

  • Consider installing a Control Panel to assist management. There is a free solution called Vestacp

  • 1

    @Caiqueromero thanks for the guidelines, he was absolutely right. I edited the answer adding essential parts that will help solve the problem

  • Solved. I read the article, and the articles inside the article. I just need to download the domains and configure DNS and stuff.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.