래칫 휠 4에 Laavel 실행 환경 조성

라떼 파이 네 개로 라벨을 옮기고 싶어요.


기회가 되니까 메모로
모니터가 없는 SSH가 래스퍼리 PiOS Lite를 톱니바퀴 4에 설치하는 것부터 시작한다.
Nginx+PHP-fpm+MariaDB의 구성.

1. Raspberry Pi Imager를 사용하여 OS 설치


https://www.raspberrypi.com/software/에서 Raspberry Pi Imager를 다운로드하고 설치합니다.Mac 사용자이기 때문에 MacOS 버전을 넣습니다.
예전에는 Etcher가 했는데, 최근의 주류는 이쪽인가요?
부팅
Operationg System: Raspberry Pi OS (other) → Raspberry Pi OS Lite (64-bit)
Storage: SD 카드 선택(아, SD 카드 먼저 넣기)
오른쪽 아래에 있는 톱니바퀴 아이콘은 무엇입니까?(클릭)
→ "Would you like to prefill the wifi password from the system keychain?"질문을 받다.Mac의 Wifi 연결 설정입니다.부탁→YES
- 관리자의 사용자 이름과 암호를 입력할 수 있습니다.
→ Advanced options 설정 화면으로 이동합니다.미리 다양한 설정을 할 수 있네요.
이번에는 호스트 이름과 pi 사용자의 비밀번호를 미리 지정했습니다
  • Image customization options: "to always use"
  • Set hostname: XXX(지정된 이름).local
  • ✓ Enable SSH
  • ● Use password authentication
  • ✓ Set username and password
  • Username: pi (default)
  • Password: XXX(암호 지정)
  •  Configure wifi (이 내용은 아까 keychain에서 입력함)
  • Wifi country: JP(잘 모르겠습니다. 여기는 일본입니다)
  • ✓ Set locale settings
  • Timezone: Asia/Tokyo
  • Keyboard layout: jp
  • □ 스킵 퍼스트-run wizard

  • → 기타 품목은 그대로 "SAVE"
    → "WRITE"!!
    →(SD 카드 내용을 모두 삭제합니다. 괜찮으세요?)→ YES
    → 관리자 암호 입력(수정 예정)→ OK
    →(...쓰기 대기 중)
    → "Write Successful"
    →(SD 카드 제거)→CONTINUE

    2. 톱니바퀴 시동


    SD 카드를 톱니바퀴에 설치하여 전원을 켜세요.
    잠시만요, 터미널에서 SSH 연결을 시도해보세요
    ssh [email protected]
    # fingerprintご自由に
    [email protected]'s password: # 指定したパスワードを入力
    
    접속이 완료되었습니다.문제 없을 것 같습니다.

    3. 초기 설정


    송이경(신지현):어? 건너뛰진 않았을텐데,raspi-config 아무데나 올라간 거 아냐?몰라서 수동으로)
    sudo raspi-config
    
    →5 Localisation options 선택
    → L1 Locale 선택
    → ja_JP.UTF-8UTF-8 추가(스페이스바*)
    → 시스템 기본값은 enGB.UTF8 (명령만 사용하고 일본어 글씨체도 번거롭다).
    → Finish
    appt 업데이트 및 appt upgrade
    sudo apt update
    sudo apt upgrade
    

    4. Nginx 설치


    1. 설치


    apt list nginx
    # Listing... Done
    # nginx/stable,stable 1.18.0-6.1 all
    
    1.18이 기본적으로 설치됩니다.
    최신 스테이블이 1.20이라서 그거 넣고 싶어요.
    nginx.org의 Debian에서 패키지로 설치를 시도합니다.
    대명사죠?
    lsb_release -a
    # No LSB modules are available.
    # Distributor ID: Debian
    # Description: Debian GNU/Linux 11 (bullseye)
    # Release: 11
    # Codename: bullseye
    
    "bullseye"용 물건을 넣으면 됩니다.
    echo "deb http://nginx.org/packages/debian/ bullseye nginx" >nginx.list
    echo "deb-src http://nginx.org/packages/debian/ bullseye nginx" >> nginx.list
    sudo mv nginx.list /etc/apt/sources.list.d
    sudo apt update
    apt list nginx
    # :
    # nginx/stable 1.20.2-1~bullseye arm64
    
    좋아, 1.20은 들어갈 것 같아.
    sudo apt install nginx
    

    2. 버전 확인


    nginx -v
    # nginx version: nginx/1.20.2
    

    3. 시동


    sudo systemctl start nginx
    
    옆에 있는 Mac 브라우저로 접근http://XXX.local/.
    징크스의 웰컴 화면만 나오면 OK.

    5. PHP 설치


    그렇게 설치하면 7.4로 들어갑니다. 그런데, 8.x를 원합니다.

    1. 다음 순서에 따라 Sugy 창고 추가


    sudo apt -y install apt-transport-https lsb-release ca-certificates curl
    sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
    sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
    echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list
    sudo apt update
    
    이렇게 하면 8 시스템의 php를 설치할 수 있다.

    2. php와 관련된 각종 장치 설치


    sudo apt -y install php-fpm php-xml php-json php-intl php-curl php-mbstring php-mysql php-zip php-bcmath
    
    dpkg -l | grep php
    ii  php-bcmath                           2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          Bcmath module for PHP [default]
    ii  php-common                           2:92+0~20220117.43+debian11~1.gbpe0d14e     all          Common files for PHP packages
    ii  php-curl                             2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          CURL module for PHP [default]
    ii  php-fpm                              2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          server-side, HTML-embedded scripting language (FPM-CGI binary) (default)
    ii  php-intl                             2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          Internationalisation module for PHP [default]
    ii  php-json                             2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          JSON module for PHP [default]
    ii  php-mbstring                         2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          MBSTRING module for PHP [default]
    ii  php-mysql                            2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          MySQL module for PHP [default]
    ii  php-xml                              2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          DOM, SimpleXML, WDDX, XML, and XSL module for PHP [default]
    ii  php-zip                              2:8.1+92+0~20220117.43+debian11~1.gbpe0d14e all          Zip module for PHP [default]
    ii  php8.1-bcmath                        8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        Bcmath module for PHP
    ii  php8.1-cli                           8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        command-line interpreter for the PHP scripting language
    ii  php8.1-common                        8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        documentation, examples and common module for PHP
    ii  php8.1-curl                          8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        CURL module for PHP
    ii  php8.1-fpm                           8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        server-side, HTML-embedded scripting language (FPM-CGI binary)
    ii  php8.1-intl                          8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        Internationalisation module for PHP
    ii  php8.1-mbstring                      8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        MBSTRING module for PHP
    ii  php8.1-mysql                         8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        MySQL module for PHP
    ii  php8.1-opcache                       8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        Zend OpCache module for PHP
    ii  php8.1-readline                      8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        readline module for PHP
    ii  php8.1-xml                           8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        DOM, SimpleXML, XML, and XSL module for PHP
    ii  php8.1-zip                           8.1.3-1+0~20220223.13+debian11~1.gbp7757b9  arm64        Zip module for PHP
    
    8.1은 많은 것을 입력했다.

    6. MySQL(MarriadB) 설치


    Raspberry PiOS라면 MarriaDB를 추천합니다.

    1. 설치


    sudo apt -y install mariadb-server
    

    2. 초기 설정


    sudo mysql_secure_installation
    
    NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
        SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
    
    In order to log into MariaDB to secure it, we'll need the current
    password for the root user. If you've just installed MariaDB, and
    haven't set the root password yet, you should just press enter here.
    
    Enter current password for root (enter for none): 
    OK, successfully used password, moving on...
    
    Setting the root password or using the unix_socket ensures that nobody
    can log into the MariaDB root user without the proper authorisation.
    
    You already have your root account protected, so you can safely answer 'n'.
    
    Switch to unix_socket authentication [Y/n] n
    ... skipping.
    
    You already have your root account protected, so you can safely answer 'n'.
    
    Change the root password? [Y/n] n
    ... skipping.
    
    By default, a MariaDB installation has an anonymous user, allowing anyone
    to log into MariaDB without having to have a user account created for
    them.  This is intended only for testing, and to make the installation
    go a bit smoother.  You should remove them before moving into a
    production environment.
    
    Remove anonymous users? [Y/n] y
    ... Success!
    
    Normally, root should only be allowed to connect from 'localhost'.  This
    ensures that someone cannot guess at the root password from the network.
    
    Disallow root login remotely? [Y/n] y
    ... Success!
    
    By default, MariaDB comes with a database named 'test' that anyone can
    access.  This is also intended only for testing, and should be removed
    before moving into a production environment.
    
    Remove test database and access to it? [Y/n] y
    - Dropping test database...
    ... Success!
    - Removing privileges on test database...
    ... Success!
    
    Reloading the privilege tables will ensure that all changes made so far
    will take effect immediately.
    
    Reload privilege tables now? [Y/n] y
    ... Success!
    
    Cleaning up...
    
    All done!  If you've completed all of the above steps, your MariaDB
    installation should now be secure.
    
    Thanks for using MariaDB!
    

    3. Laavel용 데이터베이스 및 사용자 만들기


    sudo mysql -u root
    MariaDB [(none)]> CREATE DATABASE laravel CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
    MariaDB [(none)]> CREATE USER 'phper'@localhost IDENTIFIED BY 'secret';
    GRANT ALL PRIVILEGES ON laravel.* TO 'phper'@localhost;
    

    7.git/composier/nodejs 설치


    1. git


    좀 낡았지만 곤란할 정도는 아니에요.
    sudo apt -y install git
    
    git --version
    # git version 2.30.2
    

    2. composer


    공식적인 방법으로
    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
    php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"
    
    sudo mv composer.phar /usr/local/bin/composer
    
    composer -V
    # Composer version 2.2.7 2022-02-25 11:12:27
    

    3. nodejs


    nodesource/distributions부터 16까지.x를 가지고 오는 것이 매우 편리할 것 같다.
    curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
    sudo apt-get install -y nodejs
    
    node -v
    # v16.14.0
    npm -v
    # 8.3.1
    

    8. Laavel 설치


    1. GiitHub에서 기존 프로젝트 clone 시작


    sudo mkdir -p /var/www
    cd /var/www
    sudo git clone https://~.git
    Cloning into '<プロジェクト名>'...
    Username for 'https://github.com': blancpanda
    Password for 'https://[email protected]': (← Personal Access Token を入力)
    
    사유창고이기 때문에 권한이 있는 개인 방문 영패가 필요하다.
    아래의 지령은 15분 동안 기억할 수 있다.
    git config --global credential.helper cache
    
    store면~/명문 텍스트 파일로git-credentials에 저장합니다.유효기간이 없다.
    git config --global credential.helper store
    
    ※ 이후 제거 시
    git config --global --unset credential.helper
    

    2. Laavel 설정


    sudo chown -R pi:pi <プロジェクトフォルダ>
    cd <プロジェクトフォルダ>
    composer install
    cp .env.example .env
    php artisan key:generate
    php artisan storage:link
    chmod -R 777 storage bootstrap/cache
    npm install
    npm run dev
    nano .env # データベース接続確認(先程作成したデータベース/ユーザで接続する)
    php artisan migrate
    
    ※ 루트를 유지하기가 불편하므로 프로젝트 폴더의 소유권을 pi로 변경한 후 작업을 진행합니다.

    9.Nginx 및 PHP-fpm 설정


    상기 방법으로nginx1.20을 설치한 후,nginx 사용자가 실행하려고 시도하기 때문에/etc/nginx/nginx.conf로 시작하는 사용자를 www-data로 변경합니다.
    /etc/nginx/nginx.conf
    # user nginx;
    user www-data;
    
    nginx의 설정은 여러 가지 방법이 있지만 이번에는 conf.d 이하에서 <임의의 이름>입니다.conf를 만듭니다.
    참고Laavel 문서 설정 파일 제작.
    server_name, root, fastcgi_파스 근처를 변경하면 될 것 같아요.
    /etc/nginx/conf.d/<모든 이름>.conf
    server {
        listen 80;
        listen [::]:80;
        server_name XXX.local;
        root /<プロジェクトルート>/public;
    
        add_header X-Frame-Options "SAMEORIGIN";
        add_header X-Content-Type-Options "nosniff";
    
        index index.php;
    
        charset utf-8;
    
        location / {
            try_files $uri $uri/ /index.php?$query_string;
        }
    
        location = /favicon.ico { access_log off; log_not_found off; }
        location = /robots.txt  { access_log off; log_not_found off; }
    
        error_page 404 /index.php;
    
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
            fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
            include fastcgi_params;
        }
    
        location ~ /\.(?!well-known).* {
            deny all;
        }
    }
    
    재부팅
    옆에 있는 브라우저에서 XXX를 선택합니다.local에 액세스하여 Laavel을 보면 OK
    앱 설치로 모두 가능하면 수월하겠지만 버전이 너무 낡으면 경고가 번거롭다.결과적으로 새로운 물건을 넣는 것이 비교적 수월할지도 모른다.

    좋은 웹페이지 즐겨찾기