How to add an html page in the apache2 root?
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?
Related videos on Youtube
Matei
Updated on September 18, 2022Comments
-
Matei over 1 year
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?
-
Matei over 7 yearsI've tried to modify it but it can't be modified
-
pa4080 over 7 yearsWhat you mean "it can't be modified"? Do you try to use
sudo
when you copy or create files? -
Matei over 7 yearscan you write me the full command that I should write?
-
pa4080 over 7 yearsSure, I need a moment.
-
Matei over 7 yearsI tried to edit it using gedit but I can't save it
-
pa4080 over 7 years@Matei I've updated my answer. Please, let me know if it works :)