Laravelのプロジェクトをサーバにデプロイ

Table of Contents

ローカルで作成したLaravelのプロジェクトをサーバにデプロイ

プロジェクトを取得(git)

# cd /opt/apache
# git clone ssh://hoge@ns.chinaz.org/var/lib/git/(プロジェクト名).git  /opt/apache/(プロジェクト名)
# chown apache.apache (プロジェクト名)/ -R

環境ファイルの設定(DB,Mail等)

# cd /opt/apache/(プロジェクト名)
# cp .env.example .env

Composer で必要なファイルをインストールする

# sudo -u apache php /usr/local/bin/composer install

.envの「APP_KEY=」アプリケーションキーを生成する。

# php artisan key:generate

JNode.jsのnpmコマンドをインストール

# npm install

npm installでエラー

[root@hp diary]# npm install
npm ERR! code ECONNREFUSED
npm ERR! syscall connect
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz failed, reason: connect ECONNREFUSED 2606:4700::6810:1723:443
npm ERR!     at ClientRequest.<anonymous> (/usr/lib/node_modules/npm/node_modules/minipass-fetch/lib/index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:502:9)
npm ERR!     at TLSSocket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
npm ERR!  FetchError: request to https://registry.npmjs.org/yaml/-/yaml-2.2.2.tgz failed, reason: connect ECONNREFUSED 2606:4700::6810:1723:443
npm ERR!     at ClientRequest.<anonymous> (/usr/lib/node_modules/npm/node_modules/minipass-fetch/lib/index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:513:28)
npm ERR!     at TLSSocket.socketErrorListener (node:_http_client:502:9)
npm ERR!     at TLSSocket.emit (node:events:525:35)
npm ERR!     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR!     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   syscall: 'connect',
npm ERR!   address: '2606:4700::6810:1723',
npm ERR!   port: 443,
npm ERR!   type: 'system'
npm ERR! }
npm ERR!
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-05-13T08_59_50_956Z-debug-0.log

registry.npmjs.orgのIPv6での名前解決でエラーになっていることが原因であったので、hostsに下記を追加してIpv4の名前解決で、回避

# vi /etc/hosts
-------------------------------------
104.16.20.35 registry.npmjs.org
-------------------------------------

JSファイルやCSSファイルをマージ

# npm run build

データベースマイグレーションを生成データベースマイグレーションを生成

# php artisan migrate

apacheの設定

#vi /etc/httpd/conf.d/laravel.conf
-------------------------------------
Alias /diary "/opt/apache/(プロジェクト名)/public"

<Directory "/opt/apache/(プロジェクト名)/public">
  Require all granted
  Options FollowSymlinks MultiViews Indexes
  AllowOverride All
</Directory>
-------------------------------------
# vi /opt/apache/(プロジェクト名)/public/.htaccess
-------------------------------------
 RewriteEngine On の下に下記を追加
 RewriteBase /(プロジェクト名)/
-------------------------------------

Apacheの再起動

# systemctl restart httpd

参考URL

ローカルで動かしたLaravelをCentOSにデプロイする方法 – 今日の役に立たない一言 - Today’s Trifle! -
viteを使ってみようと思ったら最初から詰まった – Qiita
npm で ECONNREFUSEDとか言われた – Qiita

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です