4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant+CentOS7.4 httpd自動起動に失敗する

Last updated at Posted at 2018-04-10

httpdのドキュメントルートを共有フォルダ(synced_folder)に設定していると、httpdの起動時にフォルダが存在しなくて、Vagrant起動時にhttpdの起動に失敗する時があります

そんな時は、こんなエラーが出でます
(/vagrant/wwwがドキュメントルート)

# sudo systemctl status httpd.service
... 省略 ...
Apr 10 02:33:55 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
Apr 10 02:33:56 localhost.localdomain httpd[915]: AH00526: Syntax error on line 120 of /etc/httpd/conf/httpd.conf:
Apr 10 02:33:56 localhost.localdomain httpd[915]: DocumentRoot '/vagrant/www' is not a directory, or is not readable
Apr 10 02:33:56 localhost.localdomain systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE
... 省略 ...

解決法

httpdの自動起動を止めて、vagrant up時にhttpd起動コマンドを実行します

httpdの自動起動を停止

# sudo systemctl disable httpd.service

vagrant up時にhttpdを起動

Vagrantfileの最後のendの前に、起動用のスクリプトを追加

Vagrantfile
  config.vm.provision "shell", run: "always", :inline => <<-COMMAND
     sudo systemctl start httpd.service
  COMMAND

end # ファイル最後のend

余談:
複数コマンドを実行したい場合などは、シェルファイルを実行すると便利

Vagrantfile
  config.vm.provision "shell", run: "always", :path => "./startup.sh"

end # ファイル最後のend
../startup.sh
sudo systemctl start httpd.service
4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?