いつかのために

自作サイトができるまで、メモ置き場として使っているブログ

IPアドレス(ドメイン部分)を入れた時のデフォルトの表示ページをWordPressに変更

su -
まずはrootユーザーになります。
vi /etc/httpd/conf/httpd.conf
と打つと、Apacheのいろいろな設定がずらっと出てきます。
ssh接続の時もお世話になりました。
?DocumentRoot
と打って以下の部分を見つけます。

DocumentRoot "/var/www/html"

私は、これを以下のように書き換えました。

DocumentRoot "/var/www/html/{任意のフォルダ名}/app/public"

/{任意のフォルダ名}/app/public のところを最初に表示したいページがあるパスに書き換えましょう。
ついでに、URLにindexファイルのないディレクトリを直叩きすると
Indexof などと出てきて、ファイル一覧が出てきてしまう状況も直します。

<Directory "/var/www/html">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>

これを、こう。

<Directory "/var/www/html">
(中略)
    Options FollowSymLinks
(中略)
    AllowOverride All
(中略)
</Directory>

centOS7では-Indexesとは書かずに、単語自体を消去するみたいなので注意です。
AllowOverride All は後々必要になるので、ついでに。
パーマリンク設定の際に必要になる .htaccessファイル がかかわってきます。

systemctl start httpd.service
そしてApacheの再起動。
以上でhttp://{IPアドレス} だけを入れた時のページがWordPressのindex.phpになりました!

これ以外にもURLに合わせて表示ページを変える方法はいくらでもある気がします…。
ですが、余計なページに行かれたくないのでこれを応急処置とします。

と、これで終わると管理画面に行けなくなってしまいます。
http://{IPアドレス}/wp-admin
と打つと、
http://{IPアドレス}/{任意のフォルダ名}/app/public/wp-admin
といったような、元のURLに合わせたリダイレクトが動いてしまいます。

なので、SQLから直接書き換えちゃいます。
mysql -u root -p
use {wordpressのDB名};
select * from wp_options where option_name = "siteurl" \G

*************************** 1. row ***************************
   option_id: 1
 option_name: siteurl
option_value: {元のURL}
    autoload: yes
1 row in set (0.00 sec)

select * from wp_options where option_name = "home" \G

*************************** 1. row ***************************
   option_id: 2
 option_name: home
option_value: {元のURL}
    autoload: yes
1 row in set (0.00 sec)

update wp_options set option_value ='{http://{IPアドレス}}' where option_name = "site_url" ;
update wp_options set option_value ='{http://{IPアドレス}}' where option_name = "home" ;

これで管理画面にも問題なくいけるようになったかと思います。