LoginSignup
1
1

More than 3 years have passed since last update.

rewrite_moduleが効かないときに行った対応メモ

Posted at

概要

webサーバーを立ち上げて、php入れて、フレームワークも導入して、ある程度開発した!!けど、
[:domain]/myaction/hoge
にアクセスしても、

Not Found
The requested URL /discussion_board was not found on this server.

って言われた・・・

その時に行った対応ログ

環境

# apache : apache2.4
$ dpkg -l | grep apache
ii  apache2                               2.4.29-1ubuntu4.6                        amd64        Apache HTTP Server
ii  apache2-bin                           2.4.29-1ubuntu4.6                        amd64        Apache HTTP Server (modules and other binary files)
ii  apache2-data                          2.4.29-1ubuntu4.6                        all          Apache HTTP Server (common files)
ii  apache2-utils                         2.4.29-1ubuntu4.6                        amd64        Apache HTTP Server (utility programs for web servers)
ii  libapache2-mod-php7.2                 7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        server-side, HTML-embedded scripting language (Apache 2 module)

# os : ubuntu18.04
$ cat /etc/os-release 
NAME="Ubuntu"
VERSION="18.04.1 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.1 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

$ php -v
PHP 7.2.18-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: May  3 2019 09:24:01) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.18-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
$ dpkg -l | grep php   
ii  libapache2-mod-php7.2                 7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        server-side, HTML-embedded scripting language (Apache 2 module)
ii  php-common                            2:69+ubuntu18.04.1+deb.sury.org+2+php7.3 all          Common files for PHP packages
ii  php7.2                                7.2.18-1+ubuntu18.04.1+deb.sury.org+1    all          server-side, HTML-embedded scripting language (metapackage)
ii  php7.2-cli                            7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        command-line interpreter for the PHP scripting language
ii  php7.2-common                         7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        documentation, examples and common module for PHP
ii  php7.2-fpm                            7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php7.2-json                           7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        JSON module for PHP
ii  php7.2-mbstring                       7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        MBSTRING module for PHP
ii  php7.2-mysql                          7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        MySQL module for PHP
ii  php7.2-opcache                        7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        Zend OpCache module for PHP
ii  php7.2-readline                       7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        readline module for PHP
ii  php7.2-xml                            7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        DOM, SimpleXML, WDDX, XML, and XSL module for PHP
ii  php7.2-zip                            7.2.18-1+ubuntu18.04.1+deb.sury.org+1    amd64        Zip module for PHP

行ったこと

apache.confのAllowOverrideを変更

使用しているapacheの設定ファイルを修正する。
(今回は /etc/apache2/apache2.conf を修正した)
必要なpathのAllowOverride設定値をAllに変更する。
これにより、.htaccessを読み込ませられるようになる。
(今回はrewrite ruleを.htaccessに記載しているため)

変更前

<Directory /var/www/>                                                                                                                                                                                     
    Options Indexes FollowSymLinks                                                                                                                                                                        
    AllowOverride None                                                                                                                                                                                     
    Require all granted                                                                                                                                                                                   
</Directory> 

変更後

<Directory /var/www/>                                                                                                                                                                                     
    Options Indexes FollowSymLinks                                                                                                                                                                        
    AllowOverride All                                                                                                                                                                                     
    Require all granted                                                                                                                                                                                   
</Directory>

apache.confにrewrite_moduleの使用を記載

使用しているapacheの設定ファイルを修正する。
(今回は /etc/apache2/apache2.conf を修正した)

rewrite_moduleが存在するか確認

$ ls -l /usr/lib/apache2/modules/mod_rewrite.so
-rw-r--r-- 1 root root 67624 Apr  3 22:22 /usr/lib/apache2/modules/mod_rewrite.so

以下をconfに追記する

LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so 

apacheをrestart

sudo systemctl restart apache2.service

対応完了

以上の作業で、rewrite ruleが有効になった。

1
1
0

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
1
1