温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

一个简单的基于Debian的开发环境。

发布时间:2020-08-06 19:36:45 来源:ITPUB博客 阅读:190 作者:cenfeng 栏目:web开发

这只是一个快速演练,描述了如何设置一个体面的开发环境,允许轻松设置多个站点。 它已经假定您已经安装并配置了PHP,MySql
Apache已经运行的 Debian或Ubuntu操作系统  你还需要一个有效的sudo。

虽然其中一些东西是Debian / Ubuntu特定的,但将它应用于任何其他发行版并不困难。

我们需要做的第一件事是创建一个'www'组。 该群组中的任何人都可以创建新网站。

sudo groupadd www

把自己放在这个群体中。

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配置的目录。

sudo chown :www /etc/apache2/sites-*

接下来,我们将创建模板vhost配置。 我们将使用它来为我们的每个站点生成配置。

<VirtualHost *:80>
    
    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
sudo chmod g+w /var/www/sites/foo.local/uploads


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI