本地开发,Apache vs Developer - 文件权限

时间:2023-01-29 23:30:47

I am interested in setting up a local php testing / development environment using the lamp stack.
I would like to use the php plugin for eclipse (I typically work with java and am very familiar with eclipse).

我有兴趣使用灯堆建立本地php测试/开发环境。我想使用php插件进行eclipse(我通常使用java并且非常熟悉eclipse)。

  • First of all, is it proper practice to develop my site locally directly within the apache /var/www directory?
  • 首先,在apache / var / www目录中直接在本地开发我的站点是否正确?

  • If this is ok, can somebody describe how to properly set the permissions of the www directory so that eclipse (not being run as root) has access to read/modify php files within that directory?
  • 如果这样可以,有人可以描述如何正确设置www目录的权限,以便eclipse(不以root身份运行)有权访问该目录中的读取/修改php文件吗?

This is strictly for local development so I assume security isn't as high of an issue.

这完全是为了本地开发,所以我认为安全性并不是一个问题。

3 个解决方案

#1


If you prefer to put it somewhere else, like your Eclipse workspace directory, you can change Apache's DocumentRoot (or create a VirtualHost with a different DocumentRoot). Edit Apache's httpd.conf file, and add this at the end:

如果您希望将其放在其他位置(例如Eclipse工作区目录),则可以更改Apache的DocumentRoot(或使用不同的DocumentRoot创建VirtualHost)。编辑Apache的httpd.conf文件,并在最后添加:

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName mytestserver.localhost
  DocumentRoot /path/to/project/dir
</VirtualHost>

The *s can be left as-is; that means they will work regardless of your IP address.

* s可以原样保留;这意味着无论您的IP地址如何,它们都能正常工作

The ServerName can be anything you want, as long as you add a corresponding entry in your /etc/hosts file, e.g.:

ServerName可以是您想要的任何内容,只要您在/ etc / hosts文件中添加相应的条目,例如:

127.0.0.1 mytestserver.localhost

I often make all my local servers end in ".localhost", just as a convention.

我经常让所有本地服务器以“.localhost”结尾,就像一个约定。

Finally, restart Apache. Then you can access the server at http://mytestserver.localhost. Repeat as necessary to use multiple virtual hosts, each pointing to a different project.

最后,重启Apache。然后,您可以访问位于http://mytestserver.localhost的服务器。根据需要重复使用多个虚拟主机,每个主机指向不同的项目。

As long as the files can be read by everyone, which is usually the default, you should be fine.

只要每个人都可以读取文件(通常是默认文件),你应该没问题。

#2


It doesn't matter, I personally placed it in /var/www/ and put it under the www-data group, and placed my username into the www-data group.

没关系,我个人将它放在/ var / www /中并将其放在www-data组下,并将我的用户名放入www-data组。

You add yourself into the group with:

您可以将自己添加到组中:

sudo usermod -a -G www-data <username>

Change the group to www-data just in case you haven't:

将组更改为www-data以防万一:

sudo chgrp -R www-data /var/www

Get new files to inherit the permissions (750)

获取新文件以继承权限(750)

sudo chmod -R 2750 www-data /var/www

Some people prefer to put it in /home/username/www/ which would be easier.

有些人喜欢将它放在/ home / username / www /中,这会更容易。

#3


It's definitely possible to work on your site directly in your server's /var/www/ directory. however, it's probably better practice to setup a local environment (using something like XAMPP) to edit your website on a development machine and then upload it to your live server when it's ready. that way you don't introduce any bugs or errors into the live site temporarily.

您可以直接在服务器的/ var / www /目录中使用您的站点。但是,最好的做法是设置一个本地环境(使用XAMPP之类的东西)在开发机器上编辑你的网站,然后在它准备就绪时将它上传到你的实时服务器。这样您就不会暂时将任何错误或错误引入实时网站。

#1


If you prefer to put it somewhere else, like your Eclipse workspace directory, you can change Apache's DocumentRoot (or create a VirtualHost with a different DocumentRoot). Edit Apache's httpd.conf file, and add this at the end:

如果您希望将其放在其他位置(例如Eclipse工作区目录),则可以更改Apache的DocumentRoot(或使用不同的DocumentRoot创建VirtualHost)。编辑Apache的httpd.conf文件,并在最后添加:

NameVirtualHost *:80
<VirtualHost *:80>
  ServerName mytestserver.localhost
  DocumentRoot /path/to/project/dir
</VirtualHost>

The *s can be left as-is; that means they will work regardless of your IP address.

* s可以原样保留;这意味着无论您的IP地址如何,它们都能正常工作

The ServerName can be anything you want, as long as you add a corresponding entry in your /etc/hosts file, e.g.:

ServerName可以是您想要的任何内容,只要您在/ etc / hosts文件中添加相应的条目,例如:

127.0.0.1 mytestserver.localhost

I often make all my local servers end in ".localhost", just as a convention.

我经常让所有本地服务器以“.localhost”结尾,就像一个约定。

Finally, restart Apache. Then you can access the server at http://mytestserver.localhost. Repeat as necessary to use multiple virtual hosts, each pointing to a different project.

最后,重启Apache。然后,您可以访问位于http://mytestserver.localhost的服务器。根据需要重复使用多个虚拟主机,每个主机指向不同的项目。

As long as the files can be read by everyone, which is usually the default, you should be fine.

只要每个人都可以读取文件(通常是默认文件),你应该没问题。

#2


It doesn't matter, I personally placed it in /var/www/ and put it under the www-data group, and placed my username into the www-data group.

没关系,我个人将它放在/ var / www /中并将其放在www-data组下,并将我的用户名放入www-data组。

You add yourself into the group with:

您可以将自己添加到组中:

sudo usermod -a -G www-data <username>

Change the group to www-data just in case you haven't:

将组更改为www-data以防万一:

sudo chgrp -R www-data /var/www

Get new files to inherit the permissions (750)

获取新文件以继承权限(750)

sudo chmod -R 2750 www-data /var/www

Some people prefer to put it in /home/username/www/ which would be easier.

有些人喜欢将它放在/ home / username / www /中,这会更容易。

#3


It's definitely possible to work on your site directly in your server's /var/www/ directory. however, it's probably better practice to setup a local environment (using something like XAMPP) to edit your website on a development machine and then upload it to your live server when it's ready. that way you don't introduce any bugs or errors into the live site temporarily.

您可以直接在服务器的/ var / www /目录中使用您的站点。但是,最好的做法是设置一个本地环境(使用XAMPP之类的东西)在开发机器上编辑你的网站,然后在它准备就绪时将它上传到你的实时服务器。这样您就不会暂时将任何错误或错误引入实时网站。