PHPでDBを使えるようにする
まず、CentOS7 MariaDB(MySQL)インストール手順 - Qiita を参考に、MariaDBをインストールする。
# yum install mariadb mariadb-server
# vi /etc/my.cnf
character-set-server=utf8 を追加。
# systemctl enable mariadb.service
# systemctl start mariadb.service
# mysql_secure_installation
基本的にデフォルトを選択。
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 5.5.64-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 db_3;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]>
できたみたい。
PHP: Installation - Manual にたどり着いて、なんとか成功。
# yum install php-mysqlnd
# systemctl restart httpd.service
以下のスクリプトで試してみる。
$mysqli = new mysqli("localhost", "root", "password", "database");
$data = $mysqli->query("SELECT user,host FROM mysql.user");
foreach ($data as $row) {
print_r($row);
}
結果。
Array ( [user] => root [host] => 127.0.0.1 ) Array ( [user] => root [host] => ::1 ) Array ( [user] => root [host] => localhost )
やったー!
♨サイトを作る
♨がJavaScriptでゲームを作りたいそうなので、どうせならiPhoneで遊べるようにWebサイトを作ってあげる。
まずアカウントを作る。
# useradd xxx
# passwd xxx
https://qiita.com/uhooi/items/137de4578534c8e7e7f2を参考に、SSH(公開鍵認証)でアクセスできるようにする。
https://www.hiroom2.com/2016/06/03/centos-7-httpd%E3%81%AEuserdir%E3%83%A2%E3%82%B8%E3%83%A5%E3%83%BC%E3%83%AB%E3%81%A7%EF%BD%90ublic-html%E3%82%92%E5%85%AC%E9%96%8B%E3%81%99%E3%82%8B/を参考に、public_htmlを有効にする。
# vi /etc/httpd/conf.d/userdir.conf
17c17
< #UserDir disabled
---
> UserDir disabled
24c24
< UserDir public_html
---
> #UserDir public_html# systemctl restart httpd
# setsebool -P httpd_enable_homedirs on
$ chmod 711 ~
$ mkdir public_html
$ chmod 711 public_html
自宅サーバOS更新
自宅サーバのOSを更新した。
# yum update
で
$ uname -a
Linux localhost.localdomain 3.10.0-862.14.4.el7.x86_64 #1 SMP Wed Sep 26 15:12:11 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
が
$ uname -a
Linux localhost.localdomain 3.10.0-957.1.3.el7.x86_64 #1 SMP Thu Nov 29 14:49:43 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
になった。
ついでに、自宅サーバをSSLに対応した。
まず、443/tcpを開ける。
# firewall-cmd --permanent --add-service=https
# firewall-cmd --reload
試してみる。
だろうね。
そこで、Let's Encrypt!
# yum install epel-release
# yum install certbot python-certbot-apache
# certbot
他に、VirtualHostを設定したり、ルータの443/tcpを開けたりした。
できたみたい。