使用vmware 共享 windows下的文件夹 到 centos - windows 下php+nginx 开发环境部署

引言:使用windows系统作为开发的同学,经常有这样的烦恼,如果直接在windows下部署php和nginx环境,安装一些其他服务比较麻烦(比如es,nvm ),还有环境不一样上线的时候会遇到一些很坑的问题,而且很难排查(因为你本地是没有问题的),故有打算使用虚拟机上的linux下部署开发环境变得比较重要,这样可以使用windows下各种编辑软件对代码进行修改,修改完后,即可马上基于linux下的nginx和php服务调试,经过一年多的使用,服务稳定。以下为使用vmware  来使用windows下的目录作为nginx的根目录的步骤。如果有问题可以评论区留言,我尽我所能尽快回复你。

 

 

 

8、vmware-hgfsclient

 

# vmware-hgfsclient

 

 9、

# cd /mnt/ 
# mkdir hgfs

 

  如果下面没有“hgfs”目录就手工建有个: mkdir hgfs

 

 

 

10、安装挂载程序

# yum install open-vm-tools-devel -y

 

11、挂载

如果之前有挂载先取消

# umount /mnt/hgfs

 

执行挂载

# /usr/bin/vmhgfs-fuse .host:/  /mnt/hgfs -o allow_other -o uid=1000 -o gid=1000 -o umask=022 -o nonempty

 

12、查看 hgfs

# cd /mnt/hgfs/
# ls

一个比较奇怪的地方,家里的电脑执行了挂载后,当前窗口怎么都没法看到挂载的文件,一个偶尔机会,重新打开一个xshell,或重开xshell 就出来了,原因不明。 

 

 12、创建 www用户和用户组(用于给php-fpm 的启动用户)

 执行以下命令

groupadd www
useradd -g www -s /sbin/nologin www
 

 

13、修改php-fpm 启动用户和用户组

# vi /etc/php-fpm.d/www.conf

 

14、修改nginx 启动用户

   #  vi /etc/nginx/nginx.conf

 修改为 user www;

 

 

 

# chown www /usr/sbin/nginx

 

15、重启nginx和php-fpm

# systemctl restart php-fpm.service

  

# systemctl restart nginx

 如果报错可以用一下命令看nginx或php-fpm是正常运行

# systemctl status nginx

  

# systemctl status php-fpm

  

 

 至此完成。

 

后续:增加启动时自动执行挂载

创建sh脚本的目录

mkdir -p /usr/local/script/

打开并编辑一个保存sh命令的文件

vi /usr/local/script/automount.sh

把以下红色字体的命令保存到这个文件里

[root@localhost system]# vi /usr/local/script/automount.sh

umount /mnt/hgfs

/usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o allow_other -o uid=1000 -o gid=1000 -oumask=022

systemctl restart nginx
systemctl restart php-fpm

把automount.sh 文件路径加到系统开机启动文件里(下面红色部门是这次加入的命令)

[root@localhost system]# vi /etc/rc.local

#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
./usr/local/script/automount.sh

 ----------------------------------The end-----------------------------------------------------

posted @ 2020-10-27 20:51  i金少  阅读(191)  评论(0编辑  收藏  举报