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?

More than 1 year has passed since last update.

aws lightsail (nginx , php8.1 , composer をインストール)

Last updated at Posted at 2022-04-14

最新にして、時刻を日本にする


yum update -y
timedatectl status
sudo timedatectl set-timezone Asia/Tokyo
localectl status
sudo localectl set-locale LANG=ja_JP.UTF-8
sudo localectl set-keymap jp106

古いphp消す

これやっとかんと、あとでphp5が動いたりするからやっておく。

sudo yum remove php-*

php8.1をインスコ


sudo amazon-linux-extras install epel
sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
sudo yum remove php-common
sudo yum install php81-php-mbstring php81-php-pdo php81-php-gd php81-php-mysqlnd php81-php-xml php81-php-opcache php81-php-fpm

sudo alternatives --install /usr/bin/php php /usr/bin/php81 1
php -v

nginx をインスコ

sudo amazon-linux-extras install nginx1
nginx -v

www.confを変更

www.conf の場所が以下になるので要注意
また、

/var/run/php-fpm/php-fpm.sock
とか php-fpm.sockを中に入れるとうまくフォルダが生成されないので、
run 直下に php-fpm.sockを作るようにする。

/etc/opt/remi/php81/php-fpm.d/www.conf

###変更###
;listen = 127.0.0.1:9000
listen = /var/run/php-fpm.sock

### 24行目あたり ###
# 変更前
user = apache
# 変更後
user = nginx

### 26行目あたり ###
# 変更前
group = apache
# 変更後
group = nginx

### 48行目あたり ###
# 変更前
;listen.owner = nobody
# 変更後
listen.owner = nginx

### 49行目あたり ###
# 変更前
;listen.group = nobody
# 変更後
listen.group = nginx

### 50行目あたり ###
# 変更前
;listen.mode = 0666
# 変更後
listen.mode = 0666

mkdir -p /var/www/html/yamada/
vim /var/www/html/yamada/index.php
/var/www/html/yamada/index.php
<?php
phpinfo();
?>

default.confを変更

server {
    listen 80;
    server_name yourdomain.net;
    root   /var/www/html/yamada/;
    index index.php index.html index.htm;


         location ~ \.php$ {

       fastcgi_pass   unix:/var/run/php-fpm.sock;

       fastcgi_index  index.php;

       fastcgi_param  SCRIPT_FILENAME /var/www/html/yamada$fastcgi_script_name;
        include        fastcgi_params;

 }

}
~                                                                                                                                                  


php fpm , nginx を動かす

sudo systemctl start php81-php-fpm
sudo systemctl enable php81-php-fpm
sudo systemctl start nginx
sudo systemctl enable nginx

これで静的IPにアクセスしてphpinfo();が表示されれば成功。

firewallはlightsailの管理画面よりオープン

firewalld は使わない

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');"

ってのをコピーしていく。
最新の情報をコピペしないとバグるので必ずリンク先からやること。

composer (/usr/local/bin)にパスを通す

vim ~/.bashrc
//最終行に追記
export PATH=$PATH:/usr/local/bin

//再読み込み
source ~/.bashrc

//composerのバージョン確認
composer -V
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?