微信小程序开发环境搭建

/ 0评 / 1

本文示例以centos7.2系统为例,装之前先配置lnmp环境

1、nginx安装
yum install nginx –y
systemctl enable nginx.servie //配置开机启动
systemctl start nginx.servie //启动服务

2、php安装
由于云上提供的yum版本太低,这里php和mysql都使用第三方的yum源安装
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum install php56w-fpm php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 //安装php
systemctl enable php-fpm.servie //配置开机启动
systemctl start php-fpm.servie //启动服务

3、mysql安装
rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm //安装源
yum -y install mysql-community-server //安装mysql5.6
systemctl enable mysqld //配置开机启动
systemctl start mysqld //启动服务
mysql_secure_installation //初始化服务
先回车
y,配置root密码
y,删除匿名用户
y,禁止root远程登录
y,删除test数据库
y,刷新权限

4、下载业务和会话sdk到服务器上
https://github.com/tencentyun/wafer-php-server-demo //wafer(业务)demo
https://github.com/tencentyun/wafer-session-server //session(会话)demo
下载之后解压出来,两个文件夹单独命名,这里我将两个demo放在/data/目录下分别命令wafer和session

5、配置ningx和ssl,这里我用了两个域名来区别业务和会话服务器
server {
listen 80;
server_name session.xxx.net;

location / {
root /data/session/;
index index.php index.html index.htm;
}

location ~ \.php$ {
root /data/session;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

error_log /var/log/nginx/error_session.log error;
access_log /var/log/nginx/access_session.log main;
}

server {
listen 443;
server_name xcx.xxx.net;
ssl on;
ssl_certificate /etc/nginx/ssl/1_xcx.xxx.net_bundle.crt;
ssl_certificate_key /etc/nginx/ssl/2_xcx.xxx.net.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

location ~ \.php$ {
root /data/wafer;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

location / {
index index.html index.php;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}

error_log /var/log/nginx/error_wafer.log error;
access_log /var/log/nginx/access_wafer.log main;
}

6、配置sdk.config
在/etc/qcloud/下创建sdk.config文件,配置如下,qcloud目录也需手动创建
{
"serverHost": "xcx.xxx.net", //小程序域名
"authServerUrl": "http://session.xxx.net/ ", //会话服务器地址,这里也可以配置IP
"tunnelServerUrl": "https://ws.qcloud.com", //信道通信域名,需要添加到公众平台request合法域名中
"tunnelSignatureKey": "xxxxxx", //自定义一串密钥
"networkTimeout": 30000
}

7、导入数据库
此时会话demo的根目录下有一个db.sql文件
mysql –uroot –p //登录数据库
create database cAuth; //创建cAuth数据库
source /data/wafer/db.sql; //导入数据库

8、安装wafer sdk
cd /data/wafer //进入目录
yum install composer //安装composer
composer install //安装sdk
修改配置application/config/config.php
修改26行为
$config['base_url'] = 'https://xcx.xxx.net/';
修改38行为
$config['index_page'] = '';

9、修改数据库配置
cd /data/session/ system/db/db.ini
[db]
host = 数据库服务器IP
port = 3306
user_name = 用户名
pass_wd = 密码
data_base = cAuth

如上已经配置完毕,下载客户端sdk进行调试
https://github.com/tencentyun/wafer-client-demo //下载客户端demo
然后在开发工具中config.js文件里面修改var host为自己的小程序域名,即可调试。

发表评论

电子邮件地址不会被公开。 必填项已用*标注