Laravel-AdminをEC2にインストールする手順 2022年版
パッケージのインストール
sudo amazon-linux-extras install -y php7.4
sudo yum install -y php-xml
sudo yum install -y php-mbstring
sudo amazon-linux-extras install -y mariadb10.5
sudo yum install httpd httpd-devel
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
自動起動設定
# mysql
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo systemctl is-enabled mariadb
sudo mysql_secure_installation
# httpd
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl is-enabled httpd
Laravelインストール
sudo su -
cd /var/www/
composer create-project "laravel/laravel=5.6.*" hoge-project
cd hoge-project
composer require encore/laravel-admin
Databaseの準備
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.5.10-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database hoge-project;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> ^DBye
Configの準備
/etc/httpd/conf/httpd.conf
# 以下を編集
DocumentRoot "/var/www/hoge-project/public"
<Directory "/var/www/hoge-project/public">
AllowOverride All
</Directory>
/var/www/hoge-project/config/database.php
// ログイン情報を記述
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'hoge-project'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'xxxxxxxxx'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
/var/www/hoge-profect/config/filesystems.php
// 以下を追記
'admin' => [
'driver' =>'local',
'root' => public_path('uploads'),
'visibility' =>'public',
'url' => env('APP_URL').'/uploads',
],
権限周り
/var/www/hoge-project は apache.apache に変更
設定の更新
php artisan admin:install
php artisan config:cache
php artisan vendor:publish --provider="Encore\Admin\AdminServiceProvider"
動作確認
ID: admin
Password: admin