Home  >  Q&A  >  body text

Real-time web chat using PHP+Swoole, advanced learning for intermediate and advanced programmers

Configure the client directory into the virtual host directory of Nginx/Apache to make client/index.html accessible. Modify client/config.js so that the IP and port are corresponding configurations. php webim_server.php Detailed deployment instructions 1. Install composer (php dependency package tool)

curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer Note : If the php interpreter program is not set to the environment variable PATH, it needs to be set. Because the first line of the composer file is #!/usr/bin/env php, it cannot be modified.

2.composer install

Switch to the PHPWebIM project directory and execute the command composer install. If it is very slow,

composer install --prefer-dist 3.Ningx/Apache configuration (The Web AppServer provided by swoole_framework is not used here)

nginx

server
{
    listen       80;
    server_name  im.swoole.com;
    index index.shtml index.html index.htm index.php;
    root  /path/to/PHPWebIM/client;
    location ~ .*\.(php|php5)?$
    {
        fastcgi_pass  127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
    }
    access_log  /Library/WebServer/nginx/logs/im.swoole.com  access;
}

apache

<VirtualHost *:80>
    DocumentRoot "path/to/PHPWebIM/client"
    ServerName im.swoole.com
    AddType application/x-httpd-php .php
    <Directory />
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
        DirectoryIndex index.php
    </Directory>
</VirtualHost>

4. Modify the configuration PHPWebIM/config.php

$config['server'] = array(
    //监听的HOST
    'host' => '0.0.0.0',
    //监听的端口
    'port' => '9503',
    //WebSocket的URL地址,供浏览器使用的
    'url' => 'ws://127.0.0.1:9503',
);

server. The host server.port item is the IP and port of the WebIM server, that is, the WebSocket server. The other options are modified according to the specific situation. The server.url corresponds to the server IP or domain name and the port of the websocket service. This is the WebSocket address webim provided to the browser. data_dir is used to modify the directory where chat records are stored, and must have writable permissions

5. Start the WebSocket server php PHPWebIM/webim_server.php IE browser does not support WebSocket, you need to use FlashWebSocket simulation, please modify flash_policy.php Corresponding port, and then start flash_policy.php. php PHPWebIM/flash_policy.php 6. Bind host and access chat window (optional) If the URL directly uses IP:PORT, no setting is required here. vi /etc/hosts Add 127.0.0.1 im.swoole.com Open with a browser: http://im.swoole.com


蘑菇宝蘑菇宝2164 days ago1429

reply all(0)I'll reply

No reply
  • Cancelreply