LoginSignup
0
0

More than 3 years have passed since last update.

AWS EC2 Amazon Linux2 にPhalcon3.4+MariaDB環境をセットアップ

Last updated at Posted at 2020-03-31

AWS EC2 までは起動できているとします。

Amazon Linux2は、インストール済み

Nginx + PHP + PHP-FPM + MariaDBをインストール

amazon-linux-extras list

sudo su -
amazon-linux-extras install nginx1

systemctl enable nginx

# パッケージ更新
# yum update -y

# タイムゾーン設定・確認
# timedatectl status
# timedatectl set-timezone Asia/Tokyo

# timedatectl status

# ロケール、キーボードレイアウト設定・確認
# localectl status
# localectl set-locale LANG=ja_JP.UTF-8
# localectl set-keymap jp106
# localectl status


mariadb

# インストール CentOSなど # Amazon Linuxはスクリプトに対応してない

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | bash


amazon linux2 の場合は、リポジトリのインストールができないのでリポジトリを定義する。

下記サイトに手順があるのでそのとおりに行うこと。
AmazonLinux2 は、centos7ベースなのでそれを選択。 Amazon Linux2でも、arm選択したらNGですよ。x64じゃないとmariadbパッケージインストールは無理です。ソースからコンパイル・インストールしか方法はないです。今の時代、ソースからインストールってアップデートも面倒なんでやんないですよねー

# vi /etc/yum.repos.d/mariadb.repo
# MariaDB 10.4 CentOS repository list - created 2020-03-31 10:03 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

-----------
# yum install MariaDB-server MariaDB-client
$ 

## 起動
# systemctl start mariadb

# 有効化
# systemctl enable mariadb
# systemctl is-enabled mariadb

## セキュリティ設定 rootのパスワード等を設定します。全部Yでもいいかなと思っています。
# mysql_secure_installation

Enter current password for root (enter for none):  # 空Enter(パスワードは初期設定はされてないので)

Switch to unix_socket authentication [Y/n] # n を入力(なぜYではなく、nなのか。ほとんどの人は、id/pwでDBにログインしてると思う。それはsocketではないから。unix_socket接続ってことはunixローカルユーザで接続するということを理解しておくこと

Set root password? [Y/n] # Y 
Remove anonymous users? [Y/n] # Y
Disallow root login remotely? [Y/n] # Y
Remove test database and access to it? [Y/n]  # Y
Reload privilege tables now? [Y/n] # Y
 ...
Thanks for using MariaDB!

接続テスト

mysql -u root -p
Enter password : 

/etc/my.cnf.d/server.cnf
[mariadb]
character-set-server=utf8mb4

PHP とphalconの関連を確認

phalcon3を使いたい。phalcon3のPHPバージョンを確認



リポジトリのインストール
# yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm


確認するコマンド
# yum --enablerepo=remi-php73 list | grep phalcon


php73-php-phalcon3.x86_64

これを確認ってことは、php7.4ではだめ。php7.3である必要があるとわかる。

php 7.3と phalconをインストール

phpコマンドを[php]で実行したい場合は、php-xxxxという名前のyum install をする必要がある。

amazon-linux-extras install php7.3

yum --enablerepo=remi-php73 install php-phalcon3

php7.4 はこっちだけど、phalconがphp7.3までなので要注意

amazon-linux-extras install php7.4

mbstringは必須なので以下も。phpをインストールしているとそのバージョンのmbstringがインストールされるので、-yをつけずに確認してからインストールすること。

yum install php-mbstring php-xml

以下の場合は、phpではなく、php73をインストールした場合のだめな場合のメモ

phpを複数バージョン入れる場合はphp73とバージョン番号付きでインストール可能だが、本番サーバーでは1つでいいので。

php73-php-mbstring
php73-php-xml

yum --enablerepo=remi-php73 install php73-php-mbstring php73-php-xml php73-php-phalcon3

php-fpm

# systemctl enable php-fpm
# systemctl start php-fpm

phalconは以下にインストールされる
ztsは、zend Thread Safeといってマルチスレッドで動くバージョン。phpはシングルスレッドなのでztsは使わない。

/usr/lib64/php/modules/phalcon.so
/usr/lib64/php-zts/modules/phalcon.so

/etc/php.ini 追加するのではなく、
/etc/php.d/50-phalcon.ini たぶん、ある。これが。なければ作る。

extension=/usr/lib64/php/modules/phalcon.so

--- jsonライブラリのあとでなければならないため。50-phalcon.iniの50は若い順に読み込まれるので

php−fpmの実行ユーザがapacheになっているので、nginxに変更

/etc/php-fpm.d/www.conf 

user nginx
group nginx

nginx
php-fpm
をリスタート

systemctl restart nginx
systemctl restart php-fpm

phpのセッションは以下のディレクトリ似て管理しているので、オーナーを変更しておく

chown -R nginx /var/lib/php/session

composer は、以下サイトにいくとトップに書いてあるコマンドを実行
https://getcomposer.org/download/

ついでにどこでもcomposerが使えるように、
/usr/local/bin/にいれておきたい。じつは、3行目にあるコマンドでdir指定ができる。
さらに、ファイル名も、composer.pharじゃなくて、composerコマンドにしたいので.pharを除去したファイル名にしたい場合は以下。

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

できなかったら自分でやればよい。

mv composer.phar /usr/local/bin/.
cd /usr/local/bin
ln -s ./composer.phar composer

nginx config test syntax check

nginx -t

php-fpm ソケット接続設定 設定を確認だけ

/etc/php-fpm.d/www.conf

listen = /run/php-fpm/www.sock

とりあえず、php-cliだけどphalconの確認を行う

php -i | grep phalcon

phalcon => enabled

enabledを確認できればOK

おまけ

wordpressのnginx設定

/etc/nginx/conf.d/【あなたのサーバのホスト名】.conf

server {
        listen 80;
        server_name 【あなたのサーバのホスト名】;
        index index.php ;
        root /var/www/wordpress ;
        location ~* /wp-config.php {
             deny all;
        }
        location ~ \.php$ {

             # ソケット接続にする。 /etc/php-fpm.d/www.confを確認
             fastcgi_pass   unix:/run/php-fpm/www.sock;
             fastcgi_index  index.php;
             fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
             include        fastcgi_params;
        }
    }


        # for PHP
        location ~ \.php$ {
                fastcgi_pass  unix:/run/php-fpm/www.sock;
                fastcgi_index /index.php;

                include fastcgi_params;
                fastcgi_split_path_info       ^(.+\.php)(/.+)$;
                fastcgi_param PATH_INFO       $fastcgi_path_info;
                fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                sendfile on;
                client_max_body_size 512M;
                fastcgi_buffering off;
                fastcgi_read_timeout 600;
        }
        location / {
                try_files $uri $uri/ /index.php?_url=$uri&$args;
                # Basic認証するときは以下を
                #        auth_basic "Restricted";
                #        auth_basic_user_file /var/www/html/.htpasswd;
        }

0
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
0
0