Homesteadはrootとしてコマンドを実行します。

Homesteadはrootとしてコマンドを実行します。

私のホームステッド構成では、after.sh自動的にxdebugを構成してスクリプトを自動的に構成し、すぐに更新または再生成するときに常に手動で再実行せずに構成を適用できるようにします。

スクリプトは次のとおりです。

#!/bin/sh

echo "Configuring Xdebug"
ip=$(netstat -rn | grep "^0.0.0.0 " | cut -d " " -f10)
xdebug_config="/etc/php/$(php -v | head -n 1 | awk '{print $2}'|cut -c 1-3)/mods-available/xdebug.ini"

echo "IP for the xdebug to connect back: ${ip}"
echo "Xdebug Configuration path: ${xdebug_config}"
echo "Port for the Xdebug to connect back: ${XDEBUG_PORT}"
echo "Optimize for ${IDE} ide"
first_line=$(head -n1 ${xdebug_config})

if [ $IDE=='atom' ]; then
  echo "Configuring xdebug for ATOM ide"
  sudo cat <<EOL >${xdebug_config}
${first_line}
xdebug.remote_enable = 1
xdebug.remote_host=${ip}
xdebug.remote_port = ${XDEBUG_PORT}
xdebug.max_nesting_level = 1000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
xdebug.remote_log=xdebug.log
EOL
fi

私のものはHomestead.yml次のとおりです。

ip: 192.168.10.10
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
timeout: 120

keys:
    - ~/.ssh/id_rsa
folders:
    -
        map: /home/pcmagas/Kwdikas/php/apps/ellakcy_member_app/
        to: /home/vagrant/code
sites:
    -
        map: homestead.test
        to: /home/vagrant/code/web
        type: symfony

databases:
    - homestead
    - homestead-test

variables:
  - key: database_host
    value: 127.0.0.1
  - key: database_port
    value: 3306
  - key: database_name
    value: homestead
  - key: database_user
    value: homestead
  - key: database_password
    value: secret
  - key: smtp_host
    value: localhost
  - key: smtp_port
    value: 1025
  - key: smtp_user
    value: [email protected]
  - key: IDE
    value: atom
  - key: XDEBUG_PORT
    value: 9091

name: ellakcy-member-app
hostname: ellakcy-member-app

次の追加の環境変数を設定しました。

  - key: IDE
    value: atom
  - key: XDEBUG_PORT
    value: 9091

したがって、xdebugの細かい構成を提供できます。

ただし、実行するとvagrant provision次のエラーが発生します(スペースを節約するために出力全体をnbotに入れました)。

ellakcy-member-app:/tmp/vagrant-shell:37:/tmp/vagrant-shell: /etc/php/7.2/mods-available/xdebug.ini を生成できません: 権限が拒否されました。

これは彼の命令によって引き起こされた。

sudo cat <<EOL >${xdebug_config}
${first_line}
xdebug.remote_enable = 1
xdebug.remote_host=${ip}
xdebug.remote_port = ${XDEBUG_PORT}
xdebug.max_nesting_level = 1000
xdebug.remote_handler=dbgp
xdebug.remote_mode=req
xdebug.remote_autostart=true
xdebug.remote_log=xdebug.log
EOL

それでは、Homestead Vagrant boxの設定を自動的に設定する方法を知りたいです。 (例:xdebug設定の1つ)

ベストアンサー1

これで、スクリプト全体をrootとして実行するオプションがあります。次のオプションを次に変更しますVagrantfile

    config.vm.provision "shell", path: afterScriptPath, privileged: **false**, keep_color: true

到着

    config.vm.provision "shell", path: afterScriptPath, privileged: **true**, keep_color: true

ただし、.NETから環境変数を読み取ることはできませんHomestead.yml

おすすめ記事