質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Smarty

Smartyは、PHPアプリケーションで使用されるテンプレートエンジンです。

Q&A

解決済

2回答

13404閲覧

[Smarty3] templates_cへの書き込みが弾かれる

TeraTaka0614

総合スコア7

Smarty

Smartyは、PHPアプリケーションで使用されるテンプレートエンジンです。

0グッド

0クリップ

投稿2017/01/07 03:24

編集2017/01/07 08:25

###追記
コメントを参考に構成を変更しました。

libsの配置を以下に変更 旧)/var/www/html/smarty-compile-check/libs/ 新)/usr/local/lib/smarty-3.1.30/libs/ ※smarty-3.1.30は、サイトからDLしたものを解凍してそのまま配置しています。

###発生している問題と達成したいこと
$smarty->display(~~) を実行したとき、以下のエラーで弾かれてしまいます。

PHP Fatal error: Uncaught --> Smarty: unable to write file /var/www/html/smarty-compile-check/templates_c/wrt586e97166ea3f4_57131635 <-- \n thrown in /var/www/html/smarty-compile-check/libs/sysplugins/smarty_internal_runtime_writefile.php on line 49

また、上記エラーで検索して、templates_cとcacheに対して以下のコマンドを叩いて権限を変更しましたが、変わらずにこのエラーが出ました。

[root@localhost smarty-compile-check]# chmod 777 templates_c/ cache/ [root@localhost smarty-compile-check]# ls -la 合計 8 drwxr-xr-x. 6 root root 79 1月 6 04:02 . drwxr-xr-x. 4 root root 55 1月 6 03:31 .. drwxrwxrwx. 2 root root 6 1月 6 03:55 cache -rw-r--r--. 1 root root 114 1月 6 04:02 index.php drwxr-xr-x. 4 root root 4096 1月 6 02:32 libs drwxr-xr-x. 2 root root 22 1月 6 04:04 templates drwxrwxrwx. 2 root root 6 1月 6 03:55 templates_c

このエラーでindex.tplが表示されずに「HTTP ERROR 500」となっているので、templates_cにコンパイルしたファイルを書き込ませてindex.tplを表示させたいです。

###使用している環境
Virtualboxの仮想マシンを使用しています。OSはCentOS7です。

###現在の状況
実行している関連ファイルは以下のような構成になっています。

/var/ www/ html/ smarty-compile-check/ templates/ index.tpl templates_c/ cache/ index.php /usr/ local/ lib/ smarty-3.1.30/ libs/

###index.phpとindex.tplの中身
index.php

php

1<?php 2 define("SMARTY_DIR", "/usr/local/lib/smarty-3.1.30/libs/"); 3 require_once(SMARTY_DIR . "Smarty.class.php"); 4 $smarty = new Smarty(); 5 $smarty->display("index.tpl");

index.tpl

html

1<!DOCTYPE HTML> 2<html> 3 <head> 4 <title>Welcome Smarty !!!</title> 5 </head> 6 <body> 7 hogehoge smarty 8 </body> 9</html>

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

ベストアンサー

以下のようなコードを実行すると、インストールの状況をチェックできます。

testInstall()

testInstall() — Smarty のインストール状態を調べる

php

1<?php 2define("SMARTY_DIR", "/usr/local/lib/smarty-3.1.30/libs/"); 3require_once(SMARTY_DIR . "Smarty.class.php"); 4$smarty = new Smarty(); 5$smarty->testInstall();

投稿2017/01/07 08:36

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TeraTaka0614

2017/01/07 08:39

コメントありがとうございます。 こちら試したところ、以下のような出力になりました。 Smarty Installation test... Testing template directory... /var/www/html/smarty-compile-check/templates is OK. Testing compile directory... FAILED: /var/www/html/smarty-compile-check/templates_c is not writable. Testing plugins directory... /usr/local/lib/smarty-3.1.30/libs/plugins is OK. Testing cache directory... FAILED: /var/www/html/smarty-compile-check/cache is not writable. Testing configs directory... FAILED: /var/www/html/smarty-compile-check/configs/ is not a directory. Testing sysplugin files... ... OK Testing plugin files... ... OK Tests complete. やはり書き込みができないようです・・・。
退会済みユーザー

退会済みユーザー

2017/01/07 08:41 編集

chmod -R 777 /var/www/html/smarty-compile-check/templates_c 一発でいけるはずです。 もしそれでもおかしい場合、 rm -rf /var/www/html/smarty-compile-check/templates_c/*
TeraTaka0614

2017/01/07 08:50

>Kosuke_Shibuyaさん 再度やってみました。 [root@localhost smarty-compile-check]# chmod -R 777 /var/www/html/smarty-compile-check/templates_c [root@localhost smarty-compile-check]# ls -la 合計 4 drwxr-xr-x. 5 root root 68 1月 6 06:14 . drwxr-xr-x. 4 root root 55 1月 6 06:14 .. drwxrwxrwx. 2 apache apache 6 1月 6 05:22 cache -rw-r--r--. 1 root root 166 1月 6 06:05 index.php drwxr-xr-x. 2 root root 22 1月 6 05:59 templates drwxrwxrwx. 2 apache apache 6 1月 6 05:22 templates_c [root@localhost smarty-compile-check]# rm -rf /var/www/html/smarty-compile-check/templates_c/* chmodのあととrm -rfのあとにそれぞれ出力確認しましたが、変化ありませんでした。
退会済みユーザー

退会済みユーザー

2017/01/07 08:56

OPcacheが有効になっていたりします?
退会済みユーザー

退会済みユーザー

2017/01/07 08:58

まさかですが、$smarty = new Smarty(); のあとに、ディレクトリの設定していないとか?
TeraTaka0614

2017/01/07 08:59

OPcacheはたぶん有効になっていないかと。 OPcache自体初耳でしたので、有効かどうか調べてます。
TeraTaka0614

2017/01/07 09:11

>まさかですが、$smarty = new Smarty(); のあとに、ディレクトリの設定していないとか? こちら、以下のように再設定しましたが結果変わらずでした。setCompileDirとsetCacheDirがなくても結果は同じでしたね。 <?php define("SMARTY_DIR", "/usr/local/lib/smarty-3.1.30/libs/"); require_once(SMARTY_DIR . "Smarty.class.php"); $smarty = new Smarty(); $smarty->setCompileDir("/var/www/html/smarty-compile-check/templates_c/"); $smarty->setCacheDir("/var/www/html/smarty-compile-check/cache/"); $smarty->testInstall();
退会済みユーザー

退会済みユーザー

2017/01/07 09:20

もはや、違うサーバーでゴニュゴニョしているとしか思えません…
TeraTaka0614

2017/01/07 09:28

お手数おかけして申し訳ないです・・・。 いったんVMそのものを削除してゼロからやりなおしてみます。
退会済みユーザー

退会済みユーザー

2017/01/07 09:30

ちょっとまった。SELinux が有効になってませんか?
TeraTaka0614

2017/01/07 09:34

危なかった・・・削除する手前でした(--; SELinux有効になってますね・・・。
退会済みユーザー

退会済みユーザー

2017/01/07 09:35

無効にしましょう。
TeraTaka0614

2017/01/07 09:37

ありがとうございます。selinuxにしたことでOKになりました。 Smarty Installation test... Testing template directory... /var/www/html/smarty-compile-check/templates is OK. Testing compile directory... /var/www/html/smarty-compile-check/templates_c is OK. Testing plugins directory... /usr/local/lib/smarty-3.1.30/libs/plugins is OK. Testing cache directory... /var/www/html/smarty-compile-check/cache is OK. Testing configs directory... FAILED: /var/www/html/smarty-compile-check/configs/ is not a directory. Testing sysplugin files... ... OK Testing plugin files... ... OK Tests complete.
退会済みユーザー

退会済みユーザー

2017/01/07 09:41

グッジョブ!
guest

0

bash

1chmod 777 templates_c/ cache/ 2chmod -R a+rw templates_c/ cache/

だとどうでしょう?

(追記)
失礼しました。Permission Denied じゃないから権限不足じゃなさそうですね。
Document Root 配下に Smarty 本体があるのはちょっとおかしい気がします。

http://www.smarty.net/docs/ja/installing.smarty.basic.tpl

を読んで、もう一度設置環境を見直してみてください。

投稿2017/01/07 03:46

編集2017/01/07 07:04
hotta

総合スコア1613

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TeraTaka0614

2017/01/07 03:54

回答ありがとうございます。 試してみましたが、変化ありませんでした・・・。 ```bash [root@localhost smarty-compile-check]# chmod 777 templates_c/ cache/ [root@localhost smarty-compile-check]# chmod -R templates_c/ cache/ chmod: 無効なモード: `templates_c/' Try 'chmod --help' for more information. [root@localhost smarty-compile-check]# chmod -R a+rw templates_c/ cache/ [root@localhost smarty-compile-check]# ls -la 合計 8 drwxr-xr-x. 6 root root 79 1月 6 04:02 . drwxr-xr-x. 4 root root 55 1月 6 03:31 .. drwxrwxrwx. 2 root root 6 1月 6 03:55 cache -rw-r--r--. 1 root root 114 1月 6 04:02 index.php drwxr-xr-x. 4 root root 4096 1月 6 02:32 libs drwxr-xr-x. 2 root root 22 1月 6 04:04 templates drwxrwxrwx. 2 root root 6 1月 6 03:55 templates_c [root@localhost smarty-compile-check]# [root@localhost smarty-compile-check]# systemctl restart httpd.service ```
退会済みユーザー

退会済みユーザー

2017/01/07 07:25

回答通りのコマンドを実行していないから、失敗しているだけですよね。
TeraTaka0614

2017/01/07 07:46

>hottaさん 追記ありがとうございます。もう一度インストールから試してみます。 >kosuke_Shibuyaさん 「回答通りのコマンドを実行していない」とは「chmod -R templates_c/ cache/」のことでしょうか? それとも回答にない「systemctl restart httpd.service」を実行していることでしょうか?
退会済みユーザー

退会済みユーザー

2017/01/07 07:51 編集

chmod -R templates_c/ cache/ ですね そのあとで実行しているんですね。失礼しました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問