3

I've installed apache2 on ubuntu and I want to add an html page on it's root to see if it works. How can I do it?

1 Answer 1

2

The default Apache2 Document Root directory on Ubuntu is: /var/www/html.

It is defined in the configuration file /etc/apache2/sites-available/000-default.conf. You can enable and disable this default virtual host via these commands:

sudo a2ensite  000-default.conf    # which means Apache2 enable site
sudo a2dissite 000-default.conf    # which means Apache2 disable site

You can create other virtual hosts, that points to other directories. After each of these steps or after some edits in the configuration files you must reload (or restart) Apache2:

sudo systemctl reload apache2.service
sudo systemctl restart apache2.service

By default, the directory /var/www/html is owned by root. This means when you want to edit a file in this directory you have to use sudo command.

For example. There is a file that contains the default welcome page. This file is called /var/www/html/index.php. To edit it, open a terminal window (ctrl+alt+T) and use this command:

sudo -i gedit /var/www/html/index.html

It is not good practice, but for testing purposes (while using the web server only locally) you can change the owner of this directory and files in it. Use this command:

sudo chown -R $USER /var/www/html/

After that you will be able to edit and create files there, with your current user (try the command echo $USER).

About the permissions of this folder, please read this topic: How to avoid using sudo when working in /var/www?

6
  • I've tried to modify it but it can't be modified
    – Matei
    Jan 26, 2017 at 19:56
  • What you mean "it can't be modified"? Do you try to use sudo when you copy or create files?
    – pa4080
    Jan 26, 2017 at 19:58
  • can you write me the full command that I should write?
    – Matei
    Jan 26, 2017 at 20:02
  • Sure, I need a moment.
    – pa4080
    Jan 26, 2017 at 20:03
  • I tried to edit it using gedit but I can't save it
    – Matei
    Jan 26, 2017 at 20:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .