小程序后台php配置及https申请配置

系统

  1. 以centos为例
  2. 开放80,20,21,3389,3309,15699-15799端口

nginx

  1. 安装EPEL: yum install epel-release -y
  2. 安装nginx:yum install nginx -y
  3. 启动nginx:systemctl start nginx
  4. 检查是否安装成功:主机host:80访问

PHP7.1

yum install php-devel

  1. 安装包换php所需的软件包
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7.rpm
  1. 启动
yum install yum-utils -y
yum-config-manager --enable remi-php71
  1. 安装PHP
yum --enablerepo=remi,remi-php71 install php-fpm php-common
  1. 安装PHP的其他模块
yum --enablerepo=remi,remi-php71 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml

配置nginx与PHP-FPM

  1. 用Vim打开: vim /etc/nginx/conf.d/default.conf
    输入一下配置(root路径可以改成其他的)
server {
        listen   80;
        server_name  your_server_ip;
    
        # note that these lines are originally from the "location /" block
        root   /usr/share/nginx/html;
        index index.php index.html index.htm;
    
        location / {
            try_files $uri $uri/ =404;
        }
        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root /usr/share/nginx/html;
        }
    
        location ~ \.php$ {
            try_files $uri =404;
            fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
  1. 配置PHP-FPM:vim /etc/php-fpm.d/www.conf
user = apache 改为 user = nginx

group = apache 改为 group = nginx

listen.owner = nobody 改为 listen.owner = nginx

listen.group = nobody 改为 listen.group = nginx

最后在listen = 127.0.0.1:9000添加此行:listen = /var/run/php-fpm/php-fpm.sock
  1. 重启nginx和PHP-FPM
systemctl restart nginx
systemctl start php-fpm.service
systemctl enable php-fpm.service

测试

  1. 在配置的路径新建phpinfo.php(也就是上方文件配置的路径root /usr/share/nginx/html可以自己定义)
    内容:
<?php
	echo phpinfo();
?>
  1. 访问http://host/phpinfo.php (host为自己服务器的ip地址)

  2. 出现以下页面为配置成功
    在这里插入图片描述

使用git导入后台代码

  1. 安装git 参考GIthub入门1

数据库MariaDB

  1. 下载:yum install mariadb-server mariadb -y
  2. 开启启动服务:
systemctl start mariadb
systemctl enable mariadb
  1. 初始化配置:根据提示输入设置密码等
mysql_secure_installation

出现内容
Enter current password for root (enter for none): –>初次运行直接回车
Set root password? [Y/n] –>是否设置root用户密码,输入y并回车或直接回车
New password: –>设置root用户的密码
Re-enter new password: –>再输入一次你设置的密码
Remove anonymous users? [Y/n] –>是否删除匿名用户,回车
Disallow root login remotely? [Y/n] –>是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] –>是否删除test数据库,回车
Reload privilege tables now? [Y/n] –>是否重新加载权限表,回车
4. 登录设置远程访问:

进入数据库:mysql -u root -p

切换数据库:use mysql

Mariadb[mysql]>GRANT ALL PRIVILEGES ON *.*TO ‘root’@’%'IDENTIFIED BY ‘123456’ WITH GRANT OPTION; //给账户权限,密码为之前设置密码,不一定为123456
Mariadb[mysql]>flush privileges; //刷新缓存
5.重启:systemctl restart mariadb
6.可以通过Navicat或其他软件进行远程连接该数据库进行数据导入

域名申请及部署解析

  1. 前往腾讯云或阿里云购买域名,之后为之前购买的服务器添加域名解析;
  2. 对购买的域名进行备案,这在腾讯云购买的域名可以通过腾讯云进行域名备案,阿里云的可以通过阿里云进行备案;
  3. 这时候得到域名,只能使用http进行访问,这不是安全的访问,而且微信小程序只承认https登陆的域名,所以这时候需要为购买的域名申请SSL证书认证;
  4. SSL证书认证:腾讯云和阿里云都有免费的SSL证书认证,当然没有要钱的安全;
  5. 域名的购买,备案,SSL证书的申请都在对应平台(阿里云,腾讯云)都有详细的流程,很容易理解,直接申请就好;

nginx的https的配置

  1. 点击下载申请好的SSL证书
    在这里插入图片描述
    下载后得到很多文件,这里选择Nginx文件夹里的两个文件
    在这里插入图片描述
    这里需要把这两个文件导入到服务器上
    2.这里使用rz sz指令将这两个文件上传到服务器上;
    在服务器运行:
yum install lrzsz

之后进入你你需要将这两个文件保存到哪里的文件夹,此处我进入路径/home/ssl这个文件夹(没有就使用mkdir命令创建),然后运行rz指令就会弹出窗口导入这两个文件。
3. 最后只要创建一个配置文件就可以了,用Vim打开:vim/etc/nginx/conf.d/文件名.conf(文件名自己定义)
输入一下配置(root路径可以改成其他的)

server {
    listen  443 ssl;
    server_name  此处填写自己的域名;

    # note that these lines are originally from the "location /" block
    root   /usr/share/nginx/html/hsyii;
    index index.php index.html index.htm;
     ssl_certificate "/home/ssl/my147.crt"; #这里填写刚刚导入两文件的路径
        ssl_certificate_key "/home/ssl/my147.key";
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_protocols SSLv2 SSLv3 TLSv1.2;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers on;
    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值