今回も完全自分用メモ。
Amazon LightsailにLaravelを入れて運用。
OSはubuntuでやりました。
Laravelはローカルで開発したモノをGit経由でUPという想定。
広告
目次
Amazon Lightsail に Laravel を入れるまで
今回、せっかくなのでPHP8でインストしてみる事にしました。
apache2 と mariadb と php8.0
どなたかを参考にしたんですが、リンク忘れてスイマセン。
# apt-get update # apt-get upgrade # apt-get dist-upgrade # reboot
アプデ関係やって。
# apt install -y lynx # apt install -y apache2 mariadb-server # add-apt-repository ppa:ondrej/php # apt install -y php8.0 php8.0-intl php8.0-mysql php8.0-gd php8.0-dom php8.0-curl php8.0-mbstring php8.0-xml php8.0-zip
これでPHP8でイケます。
Composerのインストール
# apt install -y curl php-cli php-mbstring git unzip
# php -r "copy ( 'https://getcomposer.org/installer', 'composer-setup.php' ) ;";
# php composer-setup.php --install-dir=/usr/local/bin --filename=composer;
# composer -v
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.1.9 2021-10-05 09:47:38
デデーン!! とComposer。
Sqlの設定
# systemctl start mysql # mysql -uroot -p MariaDB [(none)]> CREATE USER 'username'@'localhost' IDENTIFIED BY 'password'; MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS laravel CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci; MariaDB [(none)]> GRANT ALL PRIVILEGES ON laravel.* TO 'username'@'localhost'; MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> quit;
Git
# cd /var/www # mkdir laravel /*laravelのプロジェクト*/ # cd /var/www/laravel # git clone https://github.com/ユーザ名/プロジェクト.git
VirtualHostの設定
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName mydomai.com /*ドメイン*/
    DocumentRoot /var/www/laravel/public  /*Laraveのディレクトリ*/
    <Directory "/var/www/laravel/public">
            Options FollowSymLinks
            ReWriteEngine On
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# service apache2 restart
VirtualHostの設定を変更する事に。
多分以下のが正しい設定??
# nano /etc/apache2/sites-available/laravel.conf
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName mydomai.com /*ドメイン*/
    DocumentRoot /var/www/laravel/public  /*Laraveのディレクトリ*/
    <Directory "/var/www/laravel">
            AllowOverride All
    </Directory>
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# a2ensite laravel.conf
# a2enmod rewrite
# service apache2 restart
その他細かい事
重要な追記。
タイムゾーンの設定やらないと mariadb の時間ズレてしまいました。
defaultはOSの設定を使うようなのでタイムゾーンの設定やります。
# timedatectl set-timezone Asia/Tokyo 
# timedatectl
               Local time: Mon 2021-10-20 19:48:26 JST
           Universal time: Mon 2021-10-20 10:48:26 UTC
                 RTC time: Mon 2021-10-20 10:48:27
                Time zone: Asia/Tokyo (JST, +0900)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no
//SQLが立ち上がってたら再起動
systemctl restart mysql
これでSQL側のタイムスタンプが正常になりました。
laravel側とかPHP側は設定済で。
chown -hR www-data:www-data /var/www/laravel
で www-data に変更。
# apt install certbot python3-certbot-apache # certbot --apache //アドレスを設定 Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): youraddress@address.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must agree in order to register with the ACME server at https://acme-v02.api.letsencrypt.org/directory - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (A)gree/(C)ancel: A - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Would you be willing to share your email address with the Electronic Frontier Foundation, a founding partner of the Let's Encrypt project and the non-profit organization that develops Certbot? We'd like to send you email about our work encrypting the web, EFF news, campaigns, and ways to support digital freedom. - - - - - - - - - (Y)es/(N)o: N
SSL化して
//チェック
# systemctl status certbot.timer
 
~~~~
     Active: active (waiting) since Tue 2021-06-22 10:58:55 UTC; 9min ago
    Trigger: Tue 2021-06-22 17:47:42 UTC; 6h left
   Triggers: ● certbot.service
~~~~~
自動化のチェック。
あとはenvファイルとか入れてなかったら設置するとか細かいので終了。
Laravel使って、通販サイトの在庫自動同期システムを組んでおりました。
AmazonのSP-APIに相当苦戦しました。
機会があればメモがてらUPするかもですが、複雑で結構メンドイですね。
ではでは。
おすすめのコンテンツ
                
広告
	
