描述了如何设置一个体面的开发环境,容许轻松设置多个站点。它已经假定您已经安装并配置了PHP,MySql和
Apache已经运行的Debian或Ubuntu操做系统 。你还须要一个有效的sudo。php
虽然其中一些东西是Debian / Ubuntu特定的,但将它应用于任何其余发行版并不困难。web
咱们须要作的第一件事是建立一个'www'组。该群组中的任何人均可以建立新网站。apache
sudo groupadd www
把本身放在这个群体中。ide
sudo gpasswd –a username www && newgrp www
如今,咱们须要确保咱们全部站点的存储位置都由www拥有和写入。测试
sudo chown :www /var/www
sudo chmod g+ws /var/www
chmod的s开关设置粘滞位并确保在/ var / www中建立的全部目录也属于www组。网站
咱们须要确保www能够写入保存vhost配置的目录。ui
sudo chown :www /etc/apache2/sites-*
接下来,咱们将建立模板vhost配置。咱们将使用它来为咱们的每一个站点生成配置。this
<VirtualHost *:80>url
ServerName {SITE}.local DocumentRoot /var/www/sites/{SITE}.local/htdocs DirectoryIndex index.php <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/sites/{SITE}.local/htdocs> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog /var/www/sites/{SITE}.local/logs/error.log LogLevel warn CustomLog /var/www/sites/{SITE}.local/logs/access.log combined
</VirtualHost>
将其保存为/etc/apache2/sites-available/example.conf操作系统
如今,让咱们建立一个简单的测试站点。
mkdir -p /var/www/sites/foo.local/{htdocs,logs}
echo '<?php phpinfo(); ?>' > /var/www/sites/foo.local/htdocs/index.php
cd /etc/apache2/sites-available
sed -e 's/{SITE}/foo/g' example.conf > foo.conf
sudo a2ensite foo.conf
sudo /etc/init.d/apache2 restart
echo '127.0.0.1 foo.local' | sudo tee -a /etc/hosts
这里有一些命令,但它很是简单:
The first line creates the minimal required directory structure for a new web site.
We then create an index.php file which has a call to phpinfo() in it.
Next we move into the directory where our vhost configs are stored.
We then create a new vhosy config called foo.conf which is a copy of the example.conf from above, we use sed to replace all instances of '{SITE}' with 'foo'
Next, enable this vhost. This adds a symlink within /etc/apache2/sites-enabled
Restart Apache.
Add foo.local to our hosts file. This enables the url http://foo.local to resolve to our local machine and hence, be served by Apache.
这是真的。你能够在这个基本想法上创建至关多的东西。我在多用户系统中实现的一件事是向'www'组的成员提供新命令。这些命令主要是
围绕须要sudo的东西的包装器 ,但它确实使得从最终用户的角度来看整个过程更加清晰。考虑到机会和兴趣,我可能会在另外一个教程中详细介绍相关细节。
有一点须要注意。若是您但愿网站中的目录可由Apache写入,则必须使它们属于www-data组,而且该组将须要写入权限。例如;
mkdir -p /var/www/sites/foo.local/uploads
sudo chown :www-data /var/www/sites/foo.local/uploads
做者:cen风
来源:CSDN
原文:https://blog.csdn.net/qq_4033... 版权声明:本文为博主原创文章,转载请附上博文连接!