Self – deployment Wafer tips

Recently, take the official demo as an example to configure and deploy wafer, realizing the function of small program authorization login, obtaining user information and small program Websocket chat room. This process stepped on a few small pits, especially to share out, so that we less hit a wall. It’s a good idea to understand wafer’s business process before deploying, prepare the appropriate server environment, the required code, and know exactly what you need to configure.

First, preparation

  • Server: centOS 6.8 + PHP7 + nginx/1.9.10

  • Wafer SDK code, take the official demo as an example to download

  • Provides code downloads for session services

  • Client small program demo code download

Configuration file

1. Configure HTTPS access

How to configure free HTTPS, self baidu

2. Configure the SDK configuration file sdK.config for Wafer

Create a new text file and paste the following code:

{
    "serverHost": "www.xx.com",
    "authServerUrl": "http://www.xx.com/itjaye/wafer-session-server/",
    "tunnelServerUrl": "https://ws.qcloud.com",
    "tunnelSignatureKey": "xxxxxx",
    "networkTimeout": 30000
}
Copy the code
  • ServerHost The domain name of your business server where the Wafer SDK code is deployed
  • AuthServerUrl Session service address used for login authorization. The code to deploy the session service above
  • TunnelServerUrl This is the channel server address. You do not need to deploy the channel server address ws.qcloud.com provided by Tencent
  • TunnelSignatureKey is changed to its own signature key

Save the file as sdk.config and upload it to /etc/qclou/sdk. config (you need to create qcloud directory under /etc/qcloud)

3. Configure the database connection configuration for the session service invocation

Before going online, perform the following configuration on the server

A. Create a cAuth database and import minA_auth /db.sql in the root directory

B. Modify the wafer-session-server/system/db/db.ini code

[db] host = DATABASE server IP address port = 3306 user_name = user name pass_wd = password data_base = cAuthCopy the code

4. Configure the applets management platform

Login micro program management platform mp.weixin.qq.com/ and add the following URL in “Settings” – “Development Settings”

wss://ws.qcloud.com, ws.qcloud.com

5. Configure the client code

Change the host of /config.js in the client demo to the address of wafer SDK on your business server

var host = 'www.xx.com/itjaye/wafer-php-server-demo';
Copy the code

6. Configuration wafer – PHP – server – demo

For the wafer-php-server-demo code, perform composer Install in this folder first to install the wafer SDK

You need to assign the CI framework used by the SDK itself under configuration to support pseudo static and hide index.php

Modify the code in the application/config/config. PHP configuration changes in behavior

    $config['base_url'] = 'https://www.xx.com/itjaye/wafer';
Copy the code

Modify 38 Behavior

    $config['index_page'] = '';
Copy the code

At the same time, add the following Settings in the configuration file of the Nginx server to support the pseudo static ci framework

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

Three, upload the code

Create a folder in the web root directory on the server. My folder is called itjaye and upload the above folder wafer-php-server-demo and wafer-session-server to this folder.

Other issues

The session service needs to be modified as follows because it is PHP7.

  • Mysql functions are supported by mysqli. You can refer to the modification method

  • Replace function names with class names using the function __construct constructor

5. Reference materials

https://github.com/tencentyun/wafer/wiki
Copy the code

Have doubt can add official QQ group communication 216602757


Did this article help you? Welcome to join the wechat group of back-end learning Group: