トップ
サイト作成料金
お問い合わせ
自己紹介
ブログ
GAC blog.
カテゴリ
gacreate.com
Blog.
0
php
2023年06月05日02:13
ファイルアップローダー作って、一気に100個近いファイルをアップしたらエラーが出た
20個しかアップロード出来なかった
PHP Warning:  Maximum number of allowable file uploads has been exceeded in Unknown on line 0

「許可されているファイルアップロードの最大数を超えました」という事なのでphp.iniを確認
デフォルト20個なので100個に変更
# vi /etc/php.ini
max_file_uploads = 20
 ↓
max_file_uploads = 100


あと、アップした画像のサムネ生成処理に時間がかかり、タイムアウト(504 Gateway Timeout)も発生したので下記の設定も変更
1分から3分へ
default_socket_timeout = 60
 ↓
default_socket_timeout = 180


無事エラーが出なくなりました。

記事の内容で気づきや発見、助けられた場合にPayPalで送金(投げ銭)する事もできます。

頂いたお金はサイト運用費に当てさせて頂きます。

コメントを残して頂くだけでもモチベーションアップに繋がります(*^^*)

0
Python
2023年06月02日06:58
新しくVPS構築して移行させるので、python環境を整えてる。でもエラー対応に時間をとられる😢

CentOS Stream 8 ➔ RockyLinux 9.2

$ pip install mysqlclient
Defaulting to user installation because normal site-packages is not writeable
Collecting mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py egg_info did not run successfully.
  x exit code: 1
  mq> [16 lines of output]
      /bin/sh: line 1: mysql_config: command not found
      /bin/sh: line 1: mariadb_config: command not found
      /bin/sh: line 1: mysql_config: command not found
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-2rnsuumu/mysqlclient_d1de1a56619a4f72810d0a5562fcd405/setup.py", line 15, in <module>
          metadata, options = get_config()
        File "/tmp/pip-install-2rnsuumu/mysqlclient_d1de1a56619a4f72810d0a5562fcd405/setup_posix.py", line 70, in get_config
          libs = mysql_config("libs")
        File "/tmp/pip-install-2rnsuumu/mysqlclient_d1de1a56619a4f72810d0a5562fcd405/setup_posix.py", line 31, in mysql_config
          raise OSError("{} not found".format(_mysql_config_path))
      OSError: mysql_config not found
      mysql_config --version
      mariadb_config --version
      mysql_config --libs
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
mq> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

ググりながら色々試したけど解決せず

      /bin/sh: line 1: mysql_config: command not found
      /bin/sh: line 1: mariadb_config: command not found
      /bin/sh: line 1: mysql_config: command not found

コマンドが無いよ言われてるのでyumでそれっぽいlibやdevelが無いか探したけどもない。

1時間ぐらい格闘して、結論mysqlclientはyumで入れる事が分かった。

# yum -y install python-mysqlclient

$ pip list | grep mysql
mysqlclient         2.1.0

🤔CentOSの時はyumで入れたかな~?

記事の内容で気づきや発見、助けられた場合にPayPalで送金(投げ銭)する事もできます。

頂いたお金はサイト運用費に当てさせて頂きます。

コメントを残して頂くだけでもモチベーションアップに繋がります(*^^*)

0
Linux
2023年06月02日05:50
メモ

pythonも使うのでpipをインストール
# yum -y install python-pip

pipのアップグレード
# pip install --upgrade pip

python-devel
# yum -y install python-devel

gcc入ってないとシステムに怒られる事が多いのとりあえず
# yum -y install gcc

pythonでmariadbに接続したいのでmysqlclientインストール
# yum -y install python-mysqlclient
※なぜかpipからだとインストールできなかった
yumからだけどpipのlistに反映できてた
$ pip list | grep mysqlclient
mysqlclient            2.1.0

pythonでチャットサーバー運用してるの関連のモジュールインストール
$ pip install asyncio python-socketio

自動応答チャットボットも作ってるのでopenaiも入れとく
$ pip install openai

記事の内容で気づきや発見、助けられた場合にPayPalで送金(投げ銭)する事もできます。

頂いたお金はサイト運用費に当てさせて頂きます。

コメントを残して頂くだけでもモチベーションアップに繋がります(*^^*)

0
Linux
2023年06月01日06:09
前の記事
【備忘録】ConoHa VPSのサーバー構築 Part.1(初期設定編)


この記事では下記のソフトをインストールして設定する
httpd(apache)
php + ImageMagick
mariadb




remiリポジトリをインストール

※新しいphpのバージョンを使いたいのでremiを入れる
remiをインストール
# yum -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

念のためremi-safeが有効かだけ確認します
[remi-safe]の部分
# vi /etc/yum.repos.d/remi-safe.repo
enabled=1

リストを表示確認
# yum list
※何度かGPG鍵の確認があるので y で進めremiリポジトリのリストも表示されたらOK



httpd、php、mariadbのインストール

httpd
# yum -y install httpd httpd-devel

php8.2 + php-fpm + ImageMagick
ApacheモジュールではなくFastCGIで実行させる
# yum -y install php82 php82-php-gd php82-php-mysqlnd php82-php-fpm php82-php-pecl-imagick

mariadb
# yum -y install mariadb mariadb-server



自動起動設定

httpdの自動起動
# systemctl enable httpd

php-fpmの自動起動
# systemctl enable php82-php-fpm

MariaDBの自動起動
# systemctl enable mariadb

サーバーを再起動させます(僕のルーティーン)
# shutdown -r now

起動確認
🟢でactive(running)ならOK
# systemctl status httpd
# systemctl status php81-php-fpm
# systemctl status mariadb



phpの初期設定

phpコマンドが使えないので使えるように
# php
-bash: php: command not found

# alternatives --install /usr/bin/php php /usr/bin/php82 1
# php -v
PHP 8.2.6 (cli) (built: May  9 2023 06:25:31) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.6, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.6, Copyright (c), by Zend Technologies

設定ファイルが/etcじゃなく/etc/opt/remi/php82にあるのでシンボリックリンクを張る
# ln -s /etc/opt/remi/php82/php-fpm.conf /etc/php-fpm.conf
# ln -s /etc/opt/remi/php82/php-fpm.d /etc/php-fpm.d
# ln -s /etc/opt/remi/php82/php.ini /etc/php.ini
# ls -l /etc/php*
lrwxrwxrwx. 1 root root 32 Jun  1 09:27 /etc/php-fpm.conf -> /etc/opt/remi/php82/php-fpm.conf
lrwxrwxrwx. 1 root root 29 Jun  1 09:27 /etc/php-fpm.d -> /etc/opt/remi/php82/php-fpm.d
lrwxrwxrwx. 1 root root 27 Jun  1 09:27 /etc/php.ini -> /etc/opt/remi/php82/php.ini

ログファイルも/var/logに置シンボリックリンク
# ln -s /var/opt/remi/php82/log/php-fpm /var/log/php-fpm
# ls -l /var/log
lrwxrwxrwx. 1 root root 31 Jun  1 16:07 php-fpm -> /var/opt/remi/php82/log/php-fpm



ページを表示させる firewallの設定

ブラウザでサーバーのIPアドレスにアクセスします
http://xxx.xxx.xxx.xxx
アクセス出来ないので設定をします
httpを追加して設定を反映させます
# firewall-cmd --zone=public --add-service=http --permanent
# firewall-cmd --reload

ブラウザで再度サーバーのIPアドレスにアクセスしてWelcomeページが表示されたらOK




phpの動作確認

index.phpの作成
# vi /var/www/html/index.php
<?php
phpinfo();

ブラウザで再度サーバーのIPアドレスにアクセスしてphpのページが表示されたらOK
Apache + phpの連携は問題なし!




httpd.confの設定

# cd /etc/httpd/conf

変更箇所だけ記述 基本的にデフォルトのディレクトリ設定は使わない
# vi httpd.conf

コメントアウト(または消す)
#<Directory />
#    AllowOverride none
#    Require all denied
#</Directory>

コメントアウト(または消す)
#DocumentRoot "/var/www/html"

コメントアウト(または消す)
#<Directory "/var/www">
#    AllowOverride None
#    # Allow open access:
#    Require all granted
#</Directory>

コメントアウト(または消す)
#<Directory "/var/www/html">
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>

コメントアウト(または消す)
#ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

コメントアウト(または消す)
#<Directory "/var/www/cgi-bin">
#    AllowOverride None
#    Options None
#    Require all granted
#</Directory>

最後に追加
IncludeOptional conf.d/virtualhost/*.conf
ServerTokens ProductOnly



virtualhostの設定

# cd /etc/httpd/conf.d
# mkdir virtualhost
# cd virtualhost
# vi gacreate.com.conf
<Directory /www/gacreate.com/>
    Options +ExecCGI
    Options FollowSymLinks
    AllowOverride All
    DirectoryIndex index.php
    <FilesMatch \.(php)$>
        SetHandler "proxy:unix:/var/opt/remi/php82/run/php-fpm/www.sock|fcgi://localhost"
    </FilesMatch>
</Directory>

<VirtualHost *:80>
    ServerName gacreate.com
    DocumentRoot /www/gacreate.com/www
    ServerAdmin gacreate.com
</VirtualHost>

ディレクトリを作成
僕の場合は/wwwに複数のサイトを設置する構成
# mkdir -p /www/gacreate.com/www
ディレクトリをmiyakinの権限に変える
# chown -R miyakin:miyakin /www

index.phpを作成
# vi /www/gacreate.com/www/index.php
<?php
print("test");

httpdのconfファイルの構文チェック
# apachectl configtest
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ~~~~~~~~. Set the 'ServerName' directive globally to suppress this message
Syntax OK

httpd再起動
# systemctl restart httpd



php.confの設定

# vi /etc/httpd/conf.d/php82-php.conf
コメントアウト
#<IfModule !mod_php5.c>
#  <IfModule !mod_php7.c>
#    <IfModule !mod_php.c>
#      # Enable http authorization headers
#      SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
#
#      <FilesMatch \.(php|phar)$>
#          SetHandler "proxy:unix:/var/opt/remi/php82/run/php-fpm/www.sock|fcgi://localhost"
#      </FilesMatch>
#    </IfModule>
#  </IfModule>
#</IfModule>

httpdを再読み込み
# systemctl reload httpd



php-fpmの設定

# vi /etc/php-fpm.d/www.conf
[www]
user = apache
group = apache
listen = /var/opt/remi/php82/run/php-fpm/www.sock
listen.acl_users = apache
listen.allowed_clients = 127.0.0.1

pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35

slowlog = /var/opt/remi/php82/log/php-fpm/www-slow.log

security.limit_extensions = .php

php_admin_value[error_log] = /var/opt/remi/php82/log/php-fpm/www-error.log
php_admin_flag[log_errors] = on
php_value[session.save_handler] = files
php_value[session.save_path]    = /var/opt/remi/php82/lib/php/session
php_value[soap.wsdl_cache_dir]  = /var/opt/remi/php82/lib/php/wsdlcache

php-fpmを再起動
# systemctl restart php82-php-fpm



SELinuxコンテキスト

/wwwにhttpdで実行可能なラベル付けをする
# semanage fcontext -a -t httpd_sys_content_t "/www(/.*)?"

設定反映
# restorecon -Rv /www
Relabeled /www from unconfined_u:object_r:default_t:s0 to unconfined_u:object_r:httpd_sys_content_t:s0

確認
# semanage fcontext -l | grep /www
/www(/.*)?                                         all files          system_u:object_r:httpd_sys_content_t:s0

# ls -Z /
unconfined_u:object_r:httpd_sys_content_t:s0 www



php.iniの設定

デフォルト値から変更した項目を箇条書き
max_execution_time = 300
error_reporting = E_ALL
post_max_size = 1024M
upload_max_filesize = 1024M
date.timezone = "Asia/Tokyo"
mysqli.default_socket = /run/mariadb/mysqld.sock
session.name = GASESSID
session.auto_start = 1
mbstring.language = Japanese

httpdを再読み込み
# systemctl reload httpd

ブラウザでサーバーのIPアドレスにアクセスしてページが表示されたらOK



mariadbの設定

だいぶ昔から書き足しなので、そろそろしっかりチューニングをしたい。。
# vi /etc/my.cnf
[client]
user            = mysql
#password       = your_password
port            = 3306
socket          = /run/mariadb/mysqld.sock
default-character-set = utf8mb4

# Here follows entries for some specific programs

# The MariaDB server
[mysqld]
datadir=/var/lib/mysql
port            = 3306
socket          = /run/mariadb/mysqld.sock
character-set-server = utf8mb4
skip-character-set-client-handshake
max_connections = 512
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log-bin=mysql-bin
binlog_format=mixed
server-id       = 1
query_cache_size = 4M
query_cache_limit = 1M

[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
default-character-set = utf8mb4

mariadbを再起動
# systemctl restart mariadb



データベースのユーザー設定

mysqlにログイン
# mysql -u

ユーザーを追加
MariaDB> GRANT ALL PRIVILEGES ON *.* TO username@localhost IDENTIFIED BY 'password' WITH GRANT OPTION;
rootのパスワードを設定
MariaDB> SET PASSWORD FOR root@localhost=PASSWORD('password');



phpから接続確認

<?php
$cid = mysqli_connect("localhost", "username", "password");
mysqli_select_db($cid, "mysql");
$query_id = mysqli_query($cid, "SELECT User FROM user");
for($i = 0; $i < mysqli_num_rows($query_id); $i++) {
        $data[$i] = mysqli_fetch_array($query_id, MYSQLI_ASSOC);
}
print_r($data);


配列が表示出来たらLAMP環境の完成!


次は
【備忘録】ConoHa VPSのサーバー構築 Part.3(ただのメモ編)

記事の内容で気づきや発見、助けられた場合にPayPalで送金(投げ銭)する事もできます。

頂いたお金はサイト運用費に当てさせて頂きます。

コメントを残して頂くだけでもモチベーションアップに繋がります(*^^*)

0
Linux
2023年06月01日05:08
CentOS Stream 8のサポート終了が2024年5月末
サポート終了前に新しいVPSを用意しておく。

一世風靡したCentOSもオワコン感が出てきてしまったので、今回は自鯖でも利用してるRockyLinux。

契約したプランは1GBプラン, CPU 2Core, SSD 100GB
確か512MBプランだと後々プランを変更出来なかったと思うので1GBプランで環境構築する

記事を書いてる現在、RockyLinux9.2がリリースされているが、ConoHaのイメージには9.2がないので9.1を選択



サーバーを追加して数分で新しいVPSが用意されたのでSSHで接続してサーバーの環境構築開始!!

SELinuxを有効にして、LAMP環境を整えるまで行います。
(SELinuxが嫌いな人は、その設定を無視してね)

これは備忘録ですが少しでも参考になれば幸いです



気分的に最初にやること

パッケージやカーネル(とOS)を最新にする
# yum update

~~~~
パッケージやカーネルも更新される
~~~~

再起動する
# shutdown -r now


再起動されたらOSのバージョンを確認
※9.1から9.2にアップグレードされた
# cat /etc/redhat-release
Rocky Linux release 9.2 (Blue Onyx)


コンソールのIP表示が嫌なので変更
[root@IPアドレス ~]# vi /etc/hostname
gac

systemd-hostnamedを再起動させて反映
# systemctl restart systemd-hostnamed

ターミナルを終了させて
# exit

再度接続するとhostnameが変わってる
[root@gac ~]#



ユーザーを作成する

miyakinというユーザーを作る
# useradd miyakin
# passwd miyakin
(パスワードを入力)

ターミナルを立ち上げて接続出来るか確認
[miyakin@gac ~]$



SSHの設定 rootでSSHログインさせない

# vi /etc/ssh/sshd_config.d/01-permitrootlogin.conf
PermitRootLogin no

sshdの再起動
# systemctl restart sshd

ターミナルを立ち上げてrootで接続出来ないか確認
追加したユーザーで接続出来るか確認



SELinuxを有効化

※SELinuxを有効化するとLinuxが嫌いになる事もあるので注意してね
SELinuxのステータスを確認
disabledは無効状態
# sestatus
SELinux status:                 disabled

有効化する
# vi /etc/selinux/config
SELINUX=enforcing

※設定の反映にはOSを再起動する必要があるので今は保留



SSHの設定 ポート番号を変える

22番ポートは攻撃を受けやすいので別ポートに変更
仮に1234番に変更 ※ポート番号にはルールがあるので知らなかったら調べてね
# vi /etc/ssh/sshd_config
Port 1234

firewallで1234ポートのアクセスを許可
# firewall-cmd --add-port=1234/tcp --zone=public --permanent
ssh(22番)のアクセスを許可を削除
# firewall-cmd --remove-service=ssh --zone=public --permanent
firewallで設定反映
# firewall-cmd --reload
firewallの設定確認
# firewall-cmd --list-all --zone=public
「ports: 1234/tcp」がある事を確認
「services:」から「ssh」がない事を確認

SELinuxで許可するポートを追加
# semanage port --add --type ssh_port_t --proto tcp 1234
確認
# semanage port --list | grep ssh
ssh_port_t                     tcp      1234, 22

ターミナルを立ち上げてから22ポートで入れないか確認
ターミナルを立ち上げてから1234ポートで入れるか確認



OSを再起動させてSELinuxを有効化

再起動
# shutdown -r now

ターミナルを立ち上げて接続出来るか確認
※接続出来なければConoHaの管理画面のコンソールから操作して設定を見直すか、SELinuxを無効にして再起動

確認
# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   enforcing
Mode from config file:          enforcing
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Memory protection checking:     actual (secure)
Max kernel policy version:      33


これで初期設定は完了!

次は
【備忘録】ConoHa VPSのサーバー構築 Part.2(LAMP編)

記事の内容で気づきや発見、助けられた場合にPayPalで送金(投げ銭)する事もできます。

頂いたお金はサイト運用費に当てさせて頂きます。

コメントを残して頂くだけでもモチベーションアップに繋がります(*^^*)