0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Ubuntu24.04] いつも悩む、ApacheでPHPを動作させる

Posted at

経緯

 LAN内にwebサーバーを立てる必要があったので必要なものをさっくりインストールして動作確認してみたところ、Userdirに作成したindex.htmlへアクセスするとがめん真っ白、再起動すると「ファイルのダウンロード」になってしまって画面が表示されない。これで何時間無駄にしたか...

結論:ここを調べろ!

 xは環境に合わせて変更。

vi /etc/apache2/mods-enabled/php8.x.conf

 こいつだ!

 # Running PHP scripts in user directories is disabled by default
# 
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.

### 以下をコメントアウト!
#<IfModule mod_userdir.c>
#    <Directory /home/*/public_html>
#        php_admin_flag engine Off
#    </Directory>
#</IfModule>

 最初の設定ってたまにしかやらんので忘れるわぁ...。

 ちなみに、.htmlでphpを実行したい場合は同ファイル上にあるFilesMatchを以下のように訂正する。

<FilesMatch ".+\.(phar|php|phtml|html|htmls)$">
   SetHandler application/x-httpd-php
</FilesMatch>
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?