はじめに
CodeServer は VSCode をサーバー上で動くように移植したものです。
この記事は少なくとも下記の構築が完了しているところからスタートしています。
Xdebug をインストール
まず必要なものを揃えます。
[root@vm opc]# dnf install lsphp80-devel lsphp80-pear
Xdebugを入れます。
[root@vm opc]# /usr/local/lsws/lsphp80/bin/pecl install xdebug
~(中略)~
+----------------------------------------------------------------------+
| |
| INSTALLATION INSTRUCTIONS |
| ========================= |
| |
| See https://xdebug.org/install.php#configure-php for instructions |
| on how to enable Xdebug for PHP. |
| |
| Documentation is available online as well: |
| - A list of all settings: https://xdebug.org/docs-settings.php |
| - A list of all functions: https://xdebug.org/docs-functions.php |
| - Profiling instructions: https://xdebug.org/docs-profiling2.php |
| - Remote debugging: https://xdebug.org/docs-debugger.php |
| |
| |
| NOTE: Please disregard the message |
| You should add "extension=xdebug.so" to php.ini |
| that is emitted by the PECL installer. This does not work for |
| Xdebug. |
| |
+----------------------------------------------------------------------+
~(中略)~
Build process completed successfully
Installing '/usr/local/lsws/lsphp80/lib64/php/modules/xdebug.so'
install ok: channel://pecl.php.net/xdebug-3.0.4
configuration option "php_ini" is not set to php.ini location
You should add "zend_extension=/usr/local/lsws/lsphp80/lib64/php/modules/xdebug.so" to php.ini
PHP側の設定
PHPの設定を編集
[root@vm opc]# vi /usr/local/lsws/lsphp80/etc/php.ini
最終行に追記
/usr/local/lsws/lsphp80/etc/php.ini
[xdebug]
zend_extension=/usr/local/lsws/lsphp80/lib64/php/modules/xdebug.so
xdebug.mode=debug
xdebug.start_with_request = yes
xdebug.client_host=127.0.0.1
xdebug.client_port=9003
再起動
[root@vm opc]# systemctl restart lsws
ファイアウォールを許可する
[root@vm opc]# firewall-cmd --zone=public --permanent --add-port=9003/tcp
[root@vm opc]# firewall-cmd --reload
CodeServer をインストール
[root@vm opc]# curl -fsSL https://code-server.dev/install.sh | sh
サービス化と同時に起動させて設定ファイル(パスワード込み)を生成させる
[root@vm opc]# systemctl enable --now code-server@$USER
設定ファイルの中にアクセスに必要なパスワードが書かれているので控えておく
[root@vm opc]# cat /home/opc/.config/code-server/config.yaml
bind-addr: 127.0.0.1:8080
auth: password
password: 76f63ca8eef1d011f68bf306
cert: false
ファイアウォールを許可する
[root@vm opc]# firewall-cmd --zone=public --permanent --add-port=8080/tcp
[root@vm opc]# firewall-cmd --reload
LSWS の準備
ドキュメントルートを作ります。
リバースプロキシを組むためこのディレクトリは使用しませんが、LSWSの仕様上これが無いと動きません。
[root@vm opc]# mkdir -m 755 -p /usr/local/lsws/virtual/ide.vso.mydomain.com/html/
[root@vm opc]# chown -R nobody:nobody /usr/local/lsws/virtual/ide.vso.mydomain.com/
LSWS 上でリバースプロキシを設定します。
いざデバッグ
URLへアクセスします。
例. https://ide.vso.mydomain.com
さいごに
この記事を書いた経緯として、PHP開発入門のサイトやコミュニティで、Xdebugが使えるところまで紹介しないところが見られたので記事にしてみました。
変更履歴
- 2024年5月現在でも手順に変更がないことを確認