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

Mac から Laravel 本番サーバーへ画像ファイルをアップロードする手順

Last updated at Posted at 2025-07-25

⭐️ 目的:

開発環境の画像(例:storage/app/public/images/logo.png)を、本番サーバーへアップロードし、Web上で正しく表示できるようにする。

⭐️ 手順

✅ 1:本番に画像用ディレクトリがあるか確認

SSHでサーバーにログイン:

ssh root@<本番サーバーのIP>

Laravelプロジェクトへ移動:

# 例:conohaVPSの場合
cd /var/www/アプリ名

画像格納用のディレクトリが存在するか確認:
開発で使っていたフォルダを確認する。

# 例:imagesフォルダ
ls storage/app/public/images

なければ作成:

sudo mkdir -p storage/app/public/images
sudo chmod -R 775 storage/app/public/images
# このディレクトリとその中のすべてのファイル・フォルダの所有者が apache ユーザーになる。
sudo chown -R apache:apache storage/app/public/images

✅ 2:Mac 側のターミナルでファイルをアップロード

開発環境:画像の位置
本番環境:画像を入れたいフォルダの位置

pwd
# 開発環境の例: /Applications/MAMP/htdocs/Laravel/プロジェクト名/storage/app/public/images/画像.png
# 開発環境の例: root@xxx.xx.xxx.xxx:/var/www/プロジェクト名/storage/app/public/images/

開発環境のプロジェクト位置でコマンドを実行

# 「開発環境 \ 本番環境」で記載
scp /Applications/MAMP/htdocs/Laravel/プロジェクト名/storage/app/public/images/画像.png \
root@xxx.xx.xxx.xxx:/var/www/プロジェクト名/storage/app/public/images/

※ パスやファイル名は適宜修正してください。

🔹 補足:ディレクトリごとアップロードしたい場合

scp -r /Applications/MAMP/htdocs/Laravel/プロジェクト名/storage/app/public/images/ \
root@xxx.xx.xxx.xxx:/var/www/プロジェクト名/storage/app/public/

✅ 3:本番サーバーで所有者を Apache に変更

sudo chown apache:apache /var/www/プロジェクト名/storage/app/public/images/画像.png

✅ 4:本番サーバーで所有者を Apache に変更

以下のシンボリックリンクが存在すること:

ls -l /var/www/プロジェクト名/public/storage

なければ作成:

cd /var/www/プロジェクト名
sudo -u apache php artisan storage:link

✅ 5:本番サーバーで所有者を Apache に変更

Webブラウザで以下のURLにアクセス:

https://ドメイン/storage/images/画像.png
1
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
1
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?