Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

linux - 如何更改apache服务器的根目录? [关闭](How do I change the root directory of an apache server? [closed])

Does anyone know how to change the document root of the Apache server?

(有谁知道如何更改Apache服务器的文档根目录?)

I basically want localhost to come from /users/spencer/projects directory instead of /var/www .

(我基本上希望localhost来自/users/spencer/projects目录而不是/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.

(有人建议我更改httpd.conf文件,但我最终在/etc/apache2/sites-available/default找到了一个文件,并将根目录从/var/www更改为/home/myusername/projects_folder并且工作正常。)

  ask by Spencer Cooley translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Please note, that this only applies for Ubuntu 14.04 LTS and newer releases.

(请注意,这仅适用于Ubuntu 14.04 LTS和更新版本。)

In my Ubuntu 14.04 LTS, the document root was set to /var/www/html .

(在我的Ubuntu 14.04 LTS中,文档根目录设置为/var/www/html 。)

It was configured in the following file:

(它在以下文件中配置:)

/etc/apache2/sites-available/000-default.conf

So just do a

(所以,做一个)

sudo nano /etc/apache2/sites-available/000-default.conf

and change the following line to what you want:

(并将以下行更改为您想要的:)

DocumentRoot /var/www/html

Also do a

(还做一个)

sudo nano /etc/apache2/apache2.conf

and find this

(找到这个)

<Directory /var/www/html/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

and change /var/www/html to your preferred directory

(并将/var/www/html更改为您的首选目录)

and save it.

(并保存。)

After you saved your changes, just restart the apache2 webserver and you'll be done :)

(保存更改后,只需重新启动apache2 webserver即可完成:))

sudo service apache2 restart


If you prefer a graphical text editor, you can just replace the sudo nano by a gksu gedit . 如果你更喜欢图形文本编辑器,你可以用gksu gedit替换sudo nano 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...