apacheでwordpressとpassenger/railsを共存させる
railsをルートとしてwordpressを入れ込む形での共存はよく見かけたけども逆のパターン(wordpressの下部にrailsを入れ込む)がなかなか見つからなかったのでメモっとく。
1.
railsのプロジェクトをapacheのユーザー権限が届く位置に設置する
たとえばapacheユーザがuser_1だった場合、/home/user_2/*に置いても参照されない
なので/home/user_1/*とかに置く
2.
DocumentRoot(ここでは/home/user_1/localhost)配下にrailsプロジェクト(publicディレクトリ)のシンボリックリンクを貼る
ln -s /home/user_1/rails/public /home/user_1/localhost/utils
3.
あとはapacheのconfig設定。
ここではvconf.d/hoge.confのような例を示す
# railsの基本設定 RackEnv production RackBaseURI /utils # wordpress <VirtualHost *:8081> ServerName localhost ServerAdmin root@localhost DocumentRoot /home/user_1/hogehoge.public_html ErrorLog /var/log/httpd/localhost/error_log CustomLog /var/log/httpd/localhost/access_log combined ErrorDocument 404 /404.html DirectoryIndex index.php # wordpress内はpassengerを動かさない PassengerEnabled off PassengerResolveSymlinksInDocumentRoot On </VirtualHost> # wordpressのディレクトリディレクティブ <Directory "/home/user_1/localhost"> Options FollowSymLinks MultiViews ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> # railsのディレクトリディレクティブ <Directory "/home/user_1/localhost/utils"> PassengerEnabled on Options FollowSymLinks -MultiViews AllowOverride All Order allow,deny Allow from all # URI書き換えによってrailsディレクトリ以下はrailsのルーティングに入るようにする RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !utils RewriteRule . /index.php [L] </Directory>