如何更改本地主机的位置?

如何更改本地主机的位置?

我安装了 apache2、mysql、php 和 phpmyadmin。根位置/var/www现在在,但我想将其更改为类似/home/user/sites或 之类的位置。在其他线程中,解决方案是在文件夹000-default.conf中的文件中添加一些代码sites-enabled,但我的文件夹中没有这样的文件,事实上文件夹中没有文件/etc/apache2/sites-enabled。那么我现在如何更改位置?

$ ls -l  /etc/apache2/sites-enabled
total 0

$ ls -l /etc/apache2/sites-available
total 16
-rw-r--r-- 1 root root 1582 अक्टूबर 17 07:26 000-default.conf
-rw-r--r-- 1 root root 1338 अक्टूबर 13 22:51 000-default.conf~
-rw-r--r-- 1 root root 6432 जुलाई  21  2013 default-ssl.conf

$ apt-cache policy apache2
Installed: 2.4.6-2ubuntu2.2
  Candidate: 2.4.6-2ubuntu2.2
  Version table:
 *** 2.4.6-2ubuntu2.2 0
        500 http://np.archive.ubuntu.com/ubuntu/ saucy-updates/main i386 Packages
        500 http://security.ubuntu.com/ubuntu/ saucy-security/main i386 Packages
        100 /var/lib/dpkg/status
     2.4.6-2ubuntu2 0
        500 http://np.archive.ubuntu.com/ubuntu/ saucy/main i386 Packages

的内容000-default.conf是:

$ cat /etc/apache2/sites-enabled/000-default.conf     
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /home/buffhead/Sites
    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
DocumentRoot /home/buffhead/Sites/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/buffhead/Sites/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>

新的 DocumentRoot 的内容如下:

$ ls -l /home/buffhead/Sites/
total 4
-rw-r--r-- 1 root root 25 अक्टूबर 13 15:12 info.php

答案1

要更改默认位置,请编辑/etc/apache2/sites-available/000-default.conf。然后执行以下操作:

sudo a2ensite 000-default.conf
sudo service apache2 restart

并在此时升级到 Ubuntu 14.04。13.10 已过时且不再受支持。

权限错误可能是因为它无权访问该/home/buffhead/Sites/文件夹。请执行以下操作:

chmod o+x /home/buffhead
chown :www-data -R /home/buffhead/Sites/
chmod g+rxs /home/buffhead/Sites/

这应该让 apache 访问中的文件/home/buffhead/Sites/,并且在其中创建的文件应该保留该www-data组。

相关内容