搭建共享的内网 PHP 开发环境

PHP Samba 环境搭建

写在前头

最近一则新闻《微软将终止在Windows上提供PHP官方支持》,小伙伴们心里一惊,毕竟作为世界上最好的语言还是很多人都很喜欢的呀,而且入门的小白也相对较多。作为管理层的也犯难了啊,难道以后入职一个小伙伴都要我去给搭建一套,那不要吐血了。

本文是作为福利发放,赶紧准备好纸巾,[色]

Samba 知识普及

Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件,由服务器及客户端程序构成。SMB(Server Messages Block,信息服务块)是一种在局域网上共享文件和打印机的一种通信协议,它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务。
SMB协议是客户机/服务器型协议,客户机通过该协议可以访问服务器上的共享文件系统、打印机及其他资源。通过设置“NetBIOS over TCP/IP”使得Samba不但能与局域网络主机分享资源,还能与全世界的电脑分享资源。
简单理解就是可以作为一个网盘的服务,各种网盘的爷爷,各种系统都支持。

安装环境

CentOs 7,能自己分配IP的局域网

先关闭防火墙

firewall-cmd --state  # 检查防火墙
systemctl stop firewalld.service  # 临时关闭
systemctl disable firewalld.service  # 永久关闭

getenforce   # 查看 selinux 状态
vi /etc/selinux/config  # 改成 SELINUX=disabled

# 重启
reboot  

安装 samba

yum -y install samba samba-common samba-client

cat <<EOF >> /etc/samba/smb.conf
[test]
        comment = this is the info
        path= /home/test
        writable = yes
        public = no
EOF

# 启动
systemctl start smb
systemctl enable smb   # 开机自启

创建测试账号

useradd www -U  # 添加 www 运行用户
useradd -g www test # 创建系统账号
passwd test  # 设置密码

pdbedit -a -u test # 创建 samba 账号,设置密码建议跟系统账号密码一样

cd /home/test/
touch test1 test2 test3
mkdir a1 a2 a3
ll

测试连接

右键“此电脑”选择“映射网络驱动器”

输入samba的地址,点击“完成”

新增其他用户

useradd -g www test1 # 创建系统账号
passwd test1  # 设置密码

pdbedit -a -u test1 # 创建 samba 账号,设置密码建议跟系统账号密码一样

cd /home
chmod 755 test1
# 然后测试连接

PHP 安装

Centos7 源码安装 PHP7.2

Nginx 安装

Centos7 源码安装 Nginx

Nginx 配置

server {
    listen       80 default_server;
    server_name 192.168.101.200;

    set $wwwroot "/home/test/www";       # 这里是关健
    if ($remote_addr ~ "192.168.101.5"){   # 根据不同的用户IP,分别指向到不同用户的项目目录
        set $wwwroot "/home/test1/www/xxx";
    }
    if ($remote_addr ~ "192.168.101.61"){      # 根据不同的用户IP,分别指向到不同用户的项目目录
        set $wwwroot "/home/test2/www/xxx";
    }

    root $wwwroot;    # 这里是关健

    index index.html index.htm index.php;

    access_log /var/log/nginx/xxx.log;
    error_log /var/log/nginx/xxx-error.log;

    add_header X-Frame-Options "SAMEORIGIN";
    add_header X-XSS-Protection "1; mode=block";
    add_header X-Content-Type-Options "nosniff";

    charset utf-8;

    if ($request_method ~ ^(HEAD|TRACE)$) {
        return 403;
    }

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    error_page 404 /index.php;

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/dev/shm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
   }

    location ~ /\.(?!well-known).* {
        deny all;
    }
}
posted @ 2020-07-20 17:44  天明听歌  阅读(652)  评论(0编辑  收藏  举报