- How to Change /var/www/html Document Root in Apache
- Change Apache DocumentRoot
- How To Change The Document Root Of The Apache Server In Linux ?
- Install Apache Web Server
- Copy Files (Optional)
- Modify Default Site Configuration File
- Modify Apache Configuration File
- Restart Apache
- Check If It Is working ?
- Как сменить document_root apache с /var/www/html на /var/www/test/html/public?
How to Change /var/www/html Document Root in Apache
In this quick tutorial, you’ll learn how to change the default Apache document root from /var/www/html/ to something else. This requires you to have root access to your server. If you have that, let’s jump into the tutorial.
Change Apache DocumentRoot
DocumentRoot allows you to specify a different location to host your Apache website. By default, DocumentRoot is set to /var/www/html/. You can see this for yourself by looking at the configuration file for your website at /etc/apache2/sites-available/ and ending in *.conf.
However, for whatever reason you want to change this to another location on your server. For this example, let’s say we want to host a website from the /home/test/ directory.
The best way to demonstrate this is with a new Apache configuration file. Create a file at /etc/apache2/sites-available/ called test.conf and paste the following code.
Options Indexes FollowSymLinks AllowOverride None Require all granted DocumentRoot /home/test
If you are following the tutorial, disable all other websites with a2dissite * and enable the test configuration with the a2ensite test.conf command.
When you have made the necessary changes, restart the apache service with service apache2 restart or similar.
If you did everything correctly, you how have a website or listing that is served out of a directory other than /var/www/html/!
Please let me know below if you have any questions about changing the document root in Apache.
How To Change The Document Root Of The Apache Server In Linux ?
This post shows, how to change The Document Root of The Apache Server. By default, /var/www/html is root directory of Apache Web Server. You need superuser privilege to create and modify file inside the default root directory, that is very tedious. Fortunately, you can change the default root /var/www/html to any other directory, say /home/username/www/html .
The steps in this post are performed on Ubuntu 16.04, but applied to other Linux Distros. So, let’s start.
Install Apache Web Server
First of all, you need to install Apache Web Server on you system. If you’ve already installed, then you can skip to step 2 now.
To install Apache, run the following commands in terminal:
$ sudo apt-get update
$ sudo apt-get install apache2
This will install Apache web Server without any problem. You can check if it is installed and working properly by typing localhost or 127.0.0.1 in the address bar of a web browser. This will open a page that will look something like this:
If you see this page, it means your web server is now installed and working correctly. Now you can proceed to next step.
Copy Files (Optional)
Modify Default Site Configuration File
Modify Apache Configuration File
Now open sudo nano /etc/apache2/apache2.conf and open it:
$ sudo nano /etc/apache2/apache2.conf .
After you open the file, locate this in the file:
Options Indexes FollowSymLinks AllowOverride None Require all granted
Options Indexes FollowSymLinks AllowOverride None Require all granted
Restart Apache
Check If It Is working ?
If this post helps you, the share it and please report us if you found any mistake in the post. Thank you.
Как сменить document_root apache с /var/www/html на /var/www/test/html/public?
Есть vps, на нем apache и php.
из различных статей пробовал разные решения, но в итоге не сработало, не могу выйти за пределы конфига по умолчанию.
в /var/www/ добавил свою папку, создал новый конфиг в /etc/apache/sites-available/*.conf деактивировал старый конфиг с 000-*-.conf, активировал новую (a2dissite 000-default.conf, a2ensite example.com.conf), проверил на ошибки и перезагрузил (apache2ctl configtest, systemctl restart apache2 )
Как можно сменить пути?
Решение — добавил в /etc/apache2/apache2.conf строку с DocumentRoot нужным путем
Если есть решение без правки этого конфига поделитесь
смотри по факту при установке апача есть default
по сути это /dev/null поскольку ЛЮБЫЕ http reffery попадают в него
в конфиге там и стоит или любой домен или * там уже как прийдется
если же ты собираешся создать второй сайт то тебе нужно создать отдельный конифиг и дефоулт там уже не прокатит поскольку нужно явно указать домен и явный поуть
по факту когда у тебя 300 сайтов у тебя все 300 идут через отдельные файлы
а 1 конфио для тех запросов которые пришли по какой-то причине на этот сервер и не смогли по http reffery разобраться по этому отдалась страничка дефолта, типа сервер работает но ты друг попал не туда.