hiroto-oの日記

毎日起こっている事を何にも考えずに書いています。備忘録代わりです。2009年までは専ら大学での研究日誌、それ以降はPCのTIPS集、ランニング(マラソン)について書いています。
Most entries are in Japanese (click here to read with translation), but several computer TIPS are in English. I used to study Physics, but worked at a bank in London, Tokyo, and now in Singapore.

インターネット / internet

英語版Windowsで5chブラウザを使う

環境:Windows 10

文字化け問題
大抵の5chブラウザはOSの言語設定を日本語以外にすると文字化けしてしまう。
原因はこちらのスレの
古代からある専ブラはUnicodeをベースにしていないため、OSの「地域と言語のオプション」の「標準形式」と「Unicode対応でないプログラムの言語」が日本語に設定されていないと、日本語部分が文字化けする
これは物理的な処理の問題で文字化けしているので、日本語フォントを入れても変わらない(フォント不足で文字が表示されないわけではない)
逆に言えば「Unicode対応でない~」を日本語にすればLive5chやJaneStyleなどのUnicode非対応専ブラを動かすことも可能と思われる(試してないからわからん 弊害があるかも)
もしくはUnicode対応の神専ブラJaneXenoを使う
JaneXenoは英語版Windows対応なのも1つの最大の売り
5ちゃんねる用ブラウザ「Live5ch」part151
https://egg.5ch.net/test/read.cgi/software/1593966079/83

ということだそうです。JaneXenoを使うと解決するらしい。


JaneXenoのダウンロードとインストール
ダウンロードは
https://janexeno.client.jp/
から。殆どのパソコンで64bitで使えると思う。

インストールはちょっと変わっていて、インストーラーがない。ダウンロードした圧縮ファイルを任意のフォルダに解凍する。
ただ、「任意のフォルダ」と言われてもDocumentsにソフトウェアを置くのも気持ち悪いだろうし、反対に他のソフトのようにc:\Program Filesに置くと書き込みのパーミッションで拒否されてJaneXenoがまともに動かない。

お薦めは、
C:\Users\[ユーザー名]\AppData\Local
にJaneXenoという新たなフォルダを作り、そこに圧縮ファイルを解凍する。
このフォルダは個々のユーザー専用のソフトを為のものだから、パーミッションで拒否されることはない(はず)。



Enable XDebug on VSCode with "php artisan serve" from host on Homestead

So far, I run Laravel backend on vagrant exposed to SOMEMYCUSTOMDOMAIN.test via homestead.yaml.
However, to use the backend with frontend, it is better to put the two on the same localhost to avoid any CORS.

To this purpose, I run "php artisan serve" from host not from guest (if you run it from guest, looks like the backend is only exposed to localhost of the virtual machine, not my local computer). Also, I needed to add "HOST = localhost" in .env of the frontend, and run "npm start".

So far, I installed XDebug on the guest virtual machine. But now I will install it on the host side.

https://www.cloudways.com/blog/php-debug/#windows

1. First, create a script "phpinfo.php" under /public (where "index.php" exists) on guest side.
----------
<?php
phpinfo();
?>
----------
And open "localhost:8000/phpinfo.php" on a browser.

2. Copy & paste the result in
https://xdebug.org/wizard
and click "Analyze my phpinfo(); result".

3. Follow its explanation.
4. Download a dll file specified, rename it to php_xdebug.dll, and move it to [php directory(c:/xampp)]/ext/.
5. Open php.ini, and add the following to the end of the file.
-----------
[XDebug for php artisan serve on localhost]
zend_extension = xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
-----------


Laravel + Homestead + XDebug + VSCode: breakpoint is not hit

Successful case is:
  1. On client (as opposed to host), install XDebug as follows:
    A. On a document root (for example, /var/www/), make a new file "info.php" and the content is
    -----------
    <?php
    phpinfo();
    ?>
    -----------
    B. From browser, open the info.php
    C. Copy & paste the result to https://xdebug.org/wizard
    D. Follow the instruction on the webpage. In my case
    D-1. On /tmp/, download xdebug-3.2.2.tgz
    D-2. Install the pre-requisites for compiling PHP extensions.
    ---------------------------------
             apt-get install php8.1-dev autoconf automake
    ---------------------------------
    where 8.1 should be the php version you're currenctly using.
    D-3. Unpack the downloaded file with tar -xvzf xdebug-3.2.2.tgz"
    D-4. Go to a directory xdebug-3.2.2.
    D-5. Run "phpize"
    D-6. Run ./configure
    D-7. Run "make"
    D-8. Run "cp modules/xdebug.so /usr/lib/php/20210902"

  2. For an ini file, make "/etc/php/8.1/fpm/conf.d/20-xdebug.ini"
    -----------------------
    zend_extension=xdebug.so
    xdebug.mode=debug
    xdebug.start_with_request=yes
    xdebug.client_host=10.0.2.2
    xdebug.log="/tmp/xdebug.log"
    -----------------------
    The final line for the log file is optional.

    * If you use XDebug also on command line, create the same file at "/etc/php/8.1/cli/conf.d/".

    If we create a file only in cli instead of fpm, a breakpoint is not hit and the log shows "unresolved" .
    -----------------------
    [5814] Log opened at 2023-08-12 06:24:25.492743
    [5814] [Step Debug] INFO: Connecting to configured address/port: 10.0.2.2:9003.
    [5814] [Step Debug] INFO: Connected to debugging client: 10.0.2.2:9003 (through xdebug.client_host/xdebug.client_port).
    [5814] [Step Debug] -> <init xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" fileuri="file:///usr/local/bin/composer" language="PHP" xdebug:language_version="8.1.21" protocol_version="1.0" appid="5814"><engine version="3.2.2"><![CDATA[Xdebug]]></engine><author><![CDATA[Derick Rethans]]></author><url><![CDATA[https://xdebug.org]]></url><copyright><![CDATA[Copyright (c) 2002-2023 by Derick Rethans]]></copyright></init>

    [5814] [Step Debug] <- feature_set -i 1 -n resolved_breakpoints -v 1
    [5814] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="1" feature="resolved_breakpoints" success="1"></response>

    [5814] [Step Debug] <- feature_set -i 2 -n notify_ok -v 1
    [5814] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="2" feature="notify_ok" success="1"></response>

    [5814] [Step Debug] <- feature_set -i 3 -n extended_properties -v 1
    [5814] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="3" feature="extended_properties" success="1"></response>

    [5814] [Step Debug] <- feature_set -i 4 -n breakpoint_include_return_value -v 1
    [5814] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="4" feature="breakpoint_include_return_value" success="1"></response>

    [5814] [Step Debug] <- feature_set -i 5 -n max_children -v 100
    [5814] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="feature_set" transaction_id="5" feature="max_children" success="1"></response>

    [5814] [Step Debug] <- breakpoint_set -i 6 -t line -f file:///home/vagrant/code/SimmSimmPopcorn/frefretvBackend/routes/api.php -n 17
    [5814] [Step Debug] -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" command="breakpoint_set" transaction_id="6" id="58140001" resolved="unresolved"></response>
    -------------

  3. Start VSCiode, set launch.json as
    -----------------------
    {
        // Use IntelliSense to learn about possible attributes.
        // Hover to view descriptions of existing attributes.
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Listen for XDebug on Homestead",
                "type": "php",
                "request": "launch",
                "pathMappings": {
                    "/home/vagrant/code/SimmSimmPopcorn/frefretvBackend": "${workspaceFolder}",
                },
                "port": 9003
            }
        ]
    }
    -----------------------
    And run this "Listen for XDebug on Homestead"

  4. On host, reload vagrant with "vagrant reload --provision"

外部サイトからLaravelのpublic/storage/内のファイルにCORSを回避してアクセスする

Laravelのバックエンド側がNginxの場合。

ゲスト側のターミナルでフォルダ/etc/nginx/sites-availableを開く。
ドメインが"abc.de"の場合"abc.de"というファイルを開く。
sudo nano abc.de
serverセクションの中に下線の設定を追加:
server {
...
location /storage/ {
add_header 'Access-Control-Allow-Origin' '*';
}
...
}
ファイルをセーブして(CTRL+X)、ターミナルでnginxを再起動。
systemctl restart nginx
参考:
Configuring CORS for Laravel Public Storage
https://zaengle.com/blog/configuring-cors-for-laravel-public-storage





L5-Swaggerの対象にするフォルダの範囲を狭めたい

L5-SwaggerはLaravelのcontrollerファイルを検索して、そのファイルを読みに行く。
僕のプロジェクトでは、
app/Http/Controllers/
以下にcontrollerが入っているが、apiが入ってるのは、
app/Http/Controllers/Api/
フォルダ以下のみ。これに沿うようにL5-SwaggerもApiフォルダ以下のみ検索させたい。
そうでないと、app/Http/Controllers/Controller.phpがbase controllerだと認識されてしまう。このファイルはapiではなくてアプリから使うコントローラーなので、このapiとは無関係なファイルにglobalなapiの情報を書かなければいけない。

これを変えるには、
config\l5-swagger.php
を書き換える:
            ],
            'paths' => [
...
                /*
                 * Absolute paths to directory containing the swagger annotations are stored.
                */
                'annotations' => [
                    base_path('app/Http/Controllers/Api'),
                ],
https://github.com/DarkaOnLine/L5-Swagger/issues/349
これで解決する。

プロフィール / profile

hiroto-o

とある大学の大学院博士課程を何とか卒業して、とある金融(クオンツ)の仕事をロンドン、東京、今はシンガポールでしています。

リンクはご自由に。メールはhirotoo20[at_mark]gmail.comまで。

ランニングベストタイム:
- Marathon: 2:50
(Seoul marathon, Mar 2019)
- Half marathon: 1:21
(Marina Run, Feb 2019)
-10K: 0:38:28
(Seoul marathon, 10k split, Mar 2019)
-100K: 8:28
(サロマ湖ウルトラマラソン, Jun 2018)

-Coming up
かすみがうらマラソン Apr 2019

記事検索 / search
アーカイブ / archive
  • ライブドアブログ