How do I change the root directory of an apache se

2019-01-01 06:33发布

Does anyone know how to change the document root of the Apache server? I basically want localhost to come from /users/spencer/projects directory instead of /var/www.

Edit

I ended up figuring it out. Some suggested I change the httpd.conf file, but I ended up finding a file in /etc/apache2/sites-available/default and changed the root directory from /var/www to /home/myusername/projects_folder and that worked.

17条回答
萌妹纸的霸气范
2楼-- · 2019-01-01 06:35

I had to edit /etc/apache2/sites-available/default. The lines are the same as mentioned by RDL.

查看更多
长期被迫恋爱
3楼-- · 2019-01-01 06:36

In RedHat 7.0: /etc/httpd/conf/httpd.conf

查看更多
何处买醉
4楼-- · 2019-01-01 06:36

If you are (like me) finding this post via Google:

I found it at /etc/apache2/sites-available/000-default.conf

查看更多
ら面具成の殇う
5楼-- · 2019-01-01 06:39

If someone has installed LAMP in the /opt folder then the /etc/apache2 is not what you are looking for.

Look for httpd.conf file in /opt/lampp/etc/httpd.conf.

Change the line in this folder and save it from terminal.

查看更多
与风俱净
6楼-- · 2019-01-01 06:41

Applies to Ubuntu 14.04 and later releases. Make sure to backup following files before making any changes.

1.Open /etc/apache2/apache2.conf and search for <Directory /var/www/> directive and replace path with /home/<USERNAME>/public_html. You can use * instead of .

2.Open /etc/apache2/sites-available/000-default.conf and replace DocumentRoot value property from /var/www/html to /home/<USERNAME>/public_html. Also <Directory /var/www/html> to <Directory /home/<USERNAME>/public_html.

3.Open /etc/mods-available/php7.1.conf. Find and comment following code

<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>

Do not turn ON php_admin_flag engine OFF flag as reason is mentioned in comment above Directive code. Also php version can be 5.0, 7.0 or anything which you have installed.

Create public_html directory in home/<USERNAME>.

Restart apache service by executing command sudo service apache2 restart.

Test by running sample script on server.

查看更多
裙下三千臣
7楼-- · 2019-01-01 06:43

Incase you are using Ubuntu 16.04. Please update the 000-default.conf in the directory /etc/apache2/sites-available.

here--> ServerAdmin webmaster@localhost DocumentRoot /var/www/html/YourFolder

查看更多
登录 后发表回答