{"id":941,"date":"2024-04-15T17:41:20","date_gmt":"2024-04-15T08:41:20","guid":{"rendered":"http:\/\/inwelly.com\/?p=941"},"modified":"2024-04-15T17:41:20","modified_gmt":"2024-04-15T08:41:20","slug":"php-laravel-websocke","status":"publish","type":"post","link":"https:\/\/inwelly.com\/?p=941","title":{"rendered":"PHP Laravel &#8211; websocke"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>php 7.1 + ubuntu16.x + apache2 + mysql \n \n-- apach2 \uc124\uce58 \ubc0f \uc124\uc815\n \n#> sudo apt update\n#> sudo apt upgrade\n#> sudo apt install apache2\n#> sudo vim \/etc\/apache2\/apache2.conf\n        &lt;Directory \/home\/\uacc4\uc815\/laravel-websocket\/public>\n            Options Indexes FollowSymLinks \n            AllowOverride None \n            Require all granted \n        &lt;\/Directory> \n \n#> sudo vim \/etc\/apache2\/sites-available\/laravel.conf\n            &lt;VirtualHost *:80> \n                ServerName localhost \n                DocumentRoot \"\/home\/\uacc4\uc815\/laravel-websocket\/public\" \n                &lt;Directory \"\/home\/\uacc4\uc815\/laravel-websocket\/public\">\n                    AllowOverride all \n                &lt;\/Directory> \n             &lt;\/VirtualHost>\n \n#> sudo a2dissite 000-default.conf\n#> sudo a2ensite laravel.conf\n#> sudo a2enmod rewrite\n#> sudo service apache2 restart\n \n\n-- mysql \uc124\uce58\n\n #> sudo apt install mysql-server\n \n-- php 7.1 \uc124\uce58\n#> sudo add-apt-repository ppa:ondrej\/php\n#> sudo apt-get update\n#> sudo apt-cache search php7.1\n#> sudo apt-get install php7.1\n#> sudo apt-get install php7.1-fpm\n \n\n-- composer \uc124\uce58\n\n#> curl -sS https:\/\/getcomposer.org\/installer | php\n\n#> sudo mv composer.phar \/usr\/local\/bin\/composer\n\n\n-- \ub77c\ub77c\ubca8 \uc124\uce58\n#> composer create-project --prefer-dist laravel\/laravel laravel-websocket\n\n-- \uc124\uce58 \ud6c4 \uad8c\ud55c \ubd80\uc5ec\nsudo chgrp -R www-data \/home\/\uacc4\uc815\/laravel-websocket\nsudo chmod -R 775 \/home\/\uacc4\uc815\/laravel-websocket\/storage\n\n \n-- \ub77c\ub77c\ubca8 \uc6f9 \uc18c\uc2a4\ucf13 \uc124\uce58  ( \ucc38\uc870 URL : https:\/\/docs.beyondco.de\/laravel-websockets\/1.0\/getting-started\/installation.html )  - \/\/ step \ucc38\uc870\n \n#> sudo apt-get install php-mbstring\n \n#> sudo apt-get install php7.1-mbstring   \/\/ if your are using php 7.1\n \n#> sudo apt-get install php7.1-xml      \/\/ If PHP version is 7.1, execute the following command\n \n#> sudo apt-get install zip unzip php7.1-zip\n\n#>  sudo apt-get install php7.1-curl\n \n\/home\/\uacc4\uc815\/laravel-websocket  #> composer require beyondcode\/laravel-websockets    \/\/ step 1\n \n\/home\/\uacc4\uc815\/laravel-websocket #> php artisan vendor:publish --provider=\"BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider\" --tag=\"migrations\"    \/\/ step 2\n \n-- \ud655\uc778 1\n#> cd \/home\/\uacc4\uc815\/laravel-websocket\/database\/migrations\n2019_06_10_xxxxxx_create_websockets_statistics_entries_table.php  \n\ud30c\uc77c\uba85\uc774 \ub2e4\ub974\uc9c0\ub9cc \uc704\uc640 \uac19\uc740 \ud30c\uc77c\uc774 \uc788\ub294 \uc9c0 \ud655\uc778 \ud55c\ub2e4.\n \n-- \ub77c\ub77c\ubca8\uc5d0 Mysql \uc124\uc815\n1) Mysql \uacc4\uc815 \uc0dd\uc131 \n \ncreate user '\uacc4\uc815'@'localhost' identified by '\ud328\uc2a4\uc6cc\ub4dc'\n \ngrant all privileges on *.* to '\uacc4\uc815'@'localhost';\n \ngrant all privileges on DB\uc774\ub984.* to '\uacc4\uc815'@'localhost';\n\n\n2) laravel \uc758 \uc124\uc815\ud30c\uc77c .env \ud30c\uc77c\uc758 mysql \uc124\uc815  ( \uc704 \uacc4\uc815 \uc815\ubcf4 \uc785\ub825 )\nDB_DATABASE=DB\uba85\nDB_USERNAME=DB\uc811\uc18d\uacc4\uc815\nDB_PASSWORD=\uacc4\uc815\uc758\ud328\uc2a4\uc6cc\ub4dc\n \n \n3)  php artisan migrate    \/\/ step 3\n \n\n4)  php artisan vendor:publish --provider=\"BeyondCode\\LaravelWebSockets\\WebSocketsServiceProvider\" --tag=\"config\"     \/\/ step 4\n \n-- \ud655\uc778 2 \ubc0f \uc218\uc815 \n \n#> cd \/home\/\uacc4\uc815\/laravel-websocket\/config\nwebsockets.php   \uc774 \uc124\uce58 \ub418\uc5c8\ub294\uc9c0 \ud655\uc778\n\uc704 \ud30c\uc77c\uc5d0\uc11c \n \n'path' => 'adm\/ws'       \n \n\uc774\ub807\uac8c \uc6d0\ud558\ub294 \ud615\ud0dc\ub85c \uc218\uc815\ud55c\ub2e4.\n\uc544\uc6b8\ub7ec .env \ud30c\uc77c\uc744 \uc5f4\uc5b4 pusher \uad00\ub828\uc73c\ub85c \uc801\ub2f9\ud788 \ub123\uc5b4\uc900\ub2e4.\n \n#> cd \/home\/\uacc4\uc815\/laravel-websocket\/.env\n\uc704 \ud30c\uc77c\uc5d0\uc11c \n \nPUSHER_APP_ID=anyID\nPUSHER_APP_KEY=anyKey\nPUSHER_APP_SECRET=anySecret\n \n\uc774\ub7f0\uc2dd\uc73c\ub85c \uc218\uc815\ud55c\ub2e4.\n \n \n-- \uc2e4\ud589 1\n\/home\/\uacc4\uc815\/laravel-websocket #>   php artisan serve --host=\ub3c4\uba54\uc778\ub610\ub294IP\uc785\ub825 --port=8000\n \n \n-- \uc2e4\ud589 2\n\ube0c\ub77c\uc6b0\uc838\uc5d0\uc11c \"\ub3c4\uba54\uc778\ub610\ub294IP\uc785\ub825:8000\/admin\/websocket\"  \uc744 \uc2e4\ud589\ud558\uba74 \uc544\ub798\uc640 \uac19\uc774 \ub098\uc624\uac8c \ub41c\ub2e4. \ub610\ub294 \uac04\ud639 \n \n\"No application encryption key has been specified\"  \uc5d0\ub7ec\uac00 \ub098\uac8c \ub420\ub54c\ub294 \n \n#> php artisan key:generate\n \n\uc744 \uc2e4\ud589 \ud6c4  \"\ub3c4\uba54\uc778\ub610\ub294IP\uc785\ub825:8000\/adm\/ws\"  \uc744 \uc2e4\ud589\ud558\uba74 \uc815\uc0c1\uc801\uc73c\ub85c \ub098\uc624\ub294\uac83\uc744 \ud655\uc778 \ud560 \uc218 \uc788\ub2e4.<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1121\" height=\"321\" src=\"http:\/\/inwelly.com\/wp-content\/uploads\/2024\/04\/image-477.png\" alt=\"\" class=\"wp-image-942\" style=\"width:920px;height:auto\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \ub77c\ub77c\ubca8 \uc6f9\uc18c\ucf13 \uc124\uc815 ( \ucc38\uc870 https:\/\/docs.beyondco.de\/laravel-websockets\/1.0\/basic-usage\/pusher.html#requirements ) \/\/ step \ucc38\uc870\n \n \n#> composer require pusher\/pusher-php-server \"~3.0\"\t\/\/ step 4\n \n#> cd \/home\/\uacc4\uc815\/laravel-websocket\/.env\n\uc704 \ud30c\uc77c\uc5d0\uc11c   \n \nBROADCAST_DRIVER=pusher\n \n\uc774\ub807\uac8c \uc218\uc815\ud55c\ub2e4.\n \n \n-- \ub77c\ub77c\ubca8 \uc6f9 \uc18c\ucf13 \uc124\uc815 ( \ucc38\uc870 https:\/\/docs.beyondco.de\/laravel-websockets\/1.0\/basic-usage\/pusher.html#pusher-configuration )\n \n \n#> cd \/home\/\uacc4\uc815\/laravel-websocket\/config\/broadcasting.php  \uc218\uc815\n \n        'host' => '127.0.0.1',\n        'port' => 6001,\n        'scheme' => 'http'\n \n\uc704 URL \uc744 \ucc38\uc870 \ud558\uc5ec \uc218\uc815\ud558\uc5ec \uc900\ub2e4.\n \n \n-- \ub77c\ub77c\ubca8 \uc6f9\uc18c\ucf13 \uc124\uc815 Echo ( \ucc38\uc870 https:\/\/docs.beyondco.de\/laravel-websockets\/1.0\/basic-usage\/pusher.html#usage-with-laravel-echo )\n \n#> sudo apt-get install npm  \uc744 \uc6b0\uc120 \uc124\uce58\ud55c\ub2e4.\n \n\/home\/\uacc4\uc815\/laravel-websocket #> npm install   \uc2e4\ud589\n \/home\/\uacc4\uc815\/laravel-websocket #> npm install laravel-echo pusher-js\n \nhome\\\uacc4\uc815\\laravel-websocket\\resources\\js\\bootstrap.js \uc218\uc815\n- \uc704 \ud574\ub2f9 \ud30c\uc77c\uc758 \ud558\ub2e8\uc5d0 \ub0b4\uc6a9 \uc8fc\uc11d \uc81c\uac70 , \uc0ad\uc81c , \ucd94\uac00\n-----------------------------------------------------------------------------------------\nimport Echo from 'laravel-echo'\n \nwindow.Pusher = require('pusher-js');\n \nwindow.Echo = new Echo({\n    broadcaster: 'pusher',\n    key: process.env.MIX_PUSHER_APP_KEY,\n    wsHost: window.location.hostname,\n    wsPort: 6001,\n    disableStats: true\n});\n-----------------------------------------------------------------------------------------\n \n\/home\/\uacc4\uc815\/laravel-websocket #> npm run watch\n \n\uc704   watch  \ub97c \uc2e4\ud589 \uc2dc\ucf1c \ub193\uc740 \uc0c1\ud0dc\uc5d0\uc11c \uc0c8\ub85c\uc6b4 \ud130\ubbf8\ud138 \ucc3d\uc744 \uc5f4\uc5b4\uc11c\n\uc544\ub798\uc640 \uac19\uc774 \uc2e4\ud589\ud55c\ub2e4. <\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1419\" height=\"311\" src=\"http:\/\/inwelly.com\/wp-content\/uploads\/2024\/04\/image-478.png\" alt=\"\" class=\"wp-image-943\" style=\"width:920px;height:auto\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\/home\/\uacc4\uc815\/laravel-websocket #> php artisan websocket:serve\n\uc2e4\ud589 \uc774\ud6c4 \ube0c\ub77c\uc6b0\uc838\uc5d0\uc11c\n \nhttp:\/\/192.168.219.105\/admin\/ws    \ub97c \uc544\ub798 \uadf8\ub9bc\uacfc \uac19\uc774  \uc0c8\ub85c\uace0\uce68 \uc774\ud6c4  \"connect\" \ubc84\ud2bc\uc744 \ub20c\ub974\uba74\n\uc2e4\ud589 \ub418\uace0 \uc788\ub294 \uc0c1\ud0dc\ub97c \ud655\uc778 \ud560 \uc218 \uc788\ub2e4.<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1286\" height=\"915\" src=\"http:\/\/inwelly.com\/wp-content\/uploads\/2024\/04\/image-479.png\" alt=\"\" class=\"wp-image-944\" style=\"width:920px;height:auto\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\uc0c8\ub85c\uc6b4 \ud130\ubbf8\ub110\uc744 \uc5f4\uc5b4\uc11c \uc544\ub798\uc640 \uac19\uc774 \uc2e4\ud589\n\/home\/\uacc4\uc815\/laravel-websocket #> php artisan make:event wstestEvent\n \n- \uc544\ub798 \ud30c\uc77c\uc744 \uc218\uc815\ud55c\ub2e4. \nlaravel-websocket\\app\\Events\\wstestEvent.php  <\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>class wstestEvent<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>&nbsp; &nbsp; use Dispatchable, InteractsWithSockets, SerializesModels;<\/p>\n\n\n\n<p>&nbsp; &nbsp; public $somedata ;<\/p>\n\n\n\n<p>&nbsp; &nbsp; \/**<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;* Create a new event instance.<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;*<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;* @return void<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;*\/<\/p>\n\n\n\n<p>&nbsp; &nbsp; public function __construct($somedata)<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; $this-&gt;somedata = $somedata;<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>&nbsp; &nbsp; \/**<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;* Get the channels the event should broadcast on.<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;*<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;* @return \\Illuminate\\Broadcasting\\Channel|array<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp;*\/<\/p>\n\n\n\n<p>&nbsp; &nbsp; public function broadcastOn()<\/p>\n\n\n\n<p>&nbsp; &nbsp; {<\/p>\n\n\n\n<p>&nbsp; &nbsp; &nbsp; &nbsp; return new Channel(&#8216;TestChannel&#8217;);<\/p>\n\n\n\n<p>&nbsp; &nbsp; }<\/p>\n\n\n\n<p>}<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \uc544\ub798 \ud30c\uc77c\uc5d0 \uc811\uadfc\ud558\uc5ec \uc218\uc815 \ucd94\uac00\ud55c\ub2e4.\nlaravel-websocket\\routes\\web.php<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>class wstestEvent { &nbsp; &nbsp; use Dispatchable, InteractsWithSockets, SerializesModels; &nbsp; &nbsp; public $somedata ; &nbsp; &nbsp; \/** &nbsp; &nbsp; &nbsp;* [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-941","post","type-post","status-publish","format-standard","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/941","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=941"}],"version-history":[{"count":1,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/941\/revisions"}],"predecessor-version":[{"id":945,"href":"https:\/\/inwelly.com\/index.php?rest_route=\/wp\/v2\/posts\/941\/revisions\/945"}],"wp:attachment":[{"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=941"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=941"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/inwelly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=941"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}