LoginSignup
3
3

More than 5 years have passed since last update.

PHPでのLINUXコマンド実行 (あれ?ファイルのコピーができない・・・)

Last updated at Posted at 2015-12-02

かなり長時間躓いた為メモ。
PHPの処理でexec関数によりLINUXコマンドを実行する際のこと。

<?php
$page_code = 'copy_test';
exec('cp -r ../test ../' . $page_code);
?>

この処理は「test」というディレクトリとその配下をコピーし、
「copy_test」というディレクトリを作成するという処理ですが、
何度実行してもコピーされませんでした。
こういう時にもっとも陥りやすいのがアクセス権限の問題です。

exec関数でアクセスしようとしているディレクトリのパーミッションを変更しなくてはなりません。
例えば「/home/greenwich/html/testtemp/ ・・・・」の場合、
copy_testを作成するディレクトリ「html」のパーミッションを書込み可に変更すれば実行できるようになります。

毎回パーミッションの件で時間を費やしている気がする…

3
3
5

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