Translations:Creating a web server on a cloud/6/en

From Alliance Doc
Jump to navigation Jump to search

Change the web server's root directory

It is often much easier to manage a website if the files are owned by the user who is connecting to the VM. In the case of the Ubuntu image we're using in this example, this is user ubuntu. Follow these steps to direct Apache to serve files from /home/ubuntu/public_html, for example, instead of from /var/www/html.

  1. Use the command
    Question.png
    [name@server ~]$ sudo vim /etc/apache2/apache2.conf
    
    (or some other editor) to change the line <Directory /var/www/> to <Directory /home/ubuntu/public_html>
  2. Use the command
    Question.png
    [name@server ~]$ sudo vim /etc/apache2/sites-available/000-default.conf
    
    to edit the line DocumentRoot /var/www/html to become DocumentRoot /home/ubuntu/public_html
  3. Create the directory in the Ubuntu user's home directory with
    Question.png
    [name@server ~]$ mkdir public_html
    
  4. Copy the default page into the directory with
    Question.png
    [name@server ~]$ cp /var/www/html/index.html /home/ubuntu/public_html
    
  5. Then restart the Apache server for these changes to take effect with
    Question.png
    [name@server ~]$ sudo service apache2 restart
    

You should now be able to edit the file /home/ubuntu/public_html/index.html without using sudo. Any changes you make should be visible if you refresh the page you loaded into your browser in the previous section.