ローカルサーバー

クライアントPCのhosts

C:\Windows\System32\drivers\etc\hosts

192.168.〇〇〇.〇〇〇	wordpress.local
192.168.〇〇〇.〇〇〇	gitea.local

〇〇〇は構築する環境に合わせて、設定する。

Hyper-Vにインストールします。

Rocky Linux

Nginx

nginxリポジトリ

# nano /etc/yum.repos.d/nginx.repo

[nginx]
name=nginx
repobaseurl=https://nginx.org/packages/mainline/centos/8/$basearch/
gpgcheck=0
enabled=0

インストール

# dnf -y install nginx
# mkdir -p /usr/share/nginx
# chown nginx:nginx /usr/share/nginx
# firewall-cmd --permanent --add-service=http
# firewall-cmd --reload
# nano /etc/nginx/conf.d/wordpress.conf
 
server {
   listen 80;
   server_name wordpress.local;
   root /usr/share/nginx/wordpress;
   index index.php;
  
   charset utf-8;
   location / {
       proxy_pass http://localhost:3000;
   }
}
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
# systemctl start nginx
# systemctl enable nginx

nginxディレクトリ アクセス権設定

# usermod -aG nginx rockylinux # ユーザー名「rockylinux」は適宜変更
# chown -R nginx:nginx /usr/share/nginx
# chmod -R 775 /usr/share/nginx

PHP8.0

インストール

## 先にutilsをインストールします
# dnf -y install dnf-utils
 
## 8.1をインストールします。
# dnf module install -y php:remi-8.1
# dnf -y install php-xmlrpc php-gd php-pdo php-mysqlnd php-opcache
# dnf -y install php-pecl-zip php-pecl-apcu

# php -v
PHP 8.1.12 (cli) (built: Oct 25 2022 17:30:00) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.12, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.12, Copyright (c), by Zend Technologies

PHP 設定

# nano /etc/php.ini

(↓PHPでアップロードできるファイルの上限サイズ)
post_max_size = 64M
upload_max_filesize = 64M

(↓mbstringで使用されるデフォルト言語を日本語にする。)
mbstring.language = Japanese

(↓デフォルトの文字コードを指定する)
mbstring.internal_encoding = UTF-8

(↓HTTP通信時のインプットとアウトプットの文字コード自動変換禁止)
mbstring.http_input = pass
mbstring.http_output = pass

(↓文字エンコーディング検出や内部文字エンコーディングへの変換を行う文字エンコーディングフィルタを無効にします。)
mbstring.encoding_translation = Off

(↓文字コードの自動検出時の優先順位を指定)
mbstring.detect_order = UTF-8,EUC-JP,SJIS,JIS,ASCII 

(↓変換に失敗した場合や無効な文字の代わりに表示する文字を指定)
mbstring.substitute_character = none

php-fpm 設定

# nano /etc/php-fpm.d/www.conf
(↓実行ユーザ・グループをnginxに変更します。)
user = apache -> user = nginx に変更
group = apache -> group = nginx に変更

php高速化

OPCache、APC設定

# nano /etc/php.d/10-opcache.ini

zend_extension=opcache
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.blacklist_filename=/etc/php.d/opcache*.blacklist

起動

# systemctl start php-fpm
# systemctl enable php-fpm
Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service.
# systemctl restart nginx

MariaDB

インストール

# dnf -y install mariadb mariadb-server

起動

# systemctl start mariadb
# systemctl enable mariadb
Created symlink /etc/systemd/system/mysql.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/mysqld.service → /usr/lib/systemd/system/mariadb.service.
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.

設定

# mysql_secure_installation
設定項目設定内容
Enter current password for root (enter for none):「Enter」
Switch to unix_socket authentication「Enter」
Change the root password?「Enter」
パスワードを設定する
Remove anonymous users? [Y/n]「Enter」
Disallow root login remotely? [Y/n]「Enter」
Remove test database and access to it? [Y/n]「Enter」
Reload privilege tables now? [Y/n]「Enter」

文字コード

# nano /etc/my.cnf.d/mariadb-server.cnf
[mysqld]
character-set-server=utf8
innodb_buffer_pool_size=512M
query_cache_size=64M

再起動

# systemctl restart mariadb

外部アクセス許可

# firewall-cmd --zone=public --add-port=3306/tcp --permanent
# firewall-cmd --reload

ログイン

# mysql -u root -p

Enter password:
MariaDB [(none)]> CREATE DATABASE mariadb;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> CREATE DATABASE wordpress;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> CREATE DATABASE gitea;
Query OK, 1 row affected (0.000 sec)

「*****」はユーザ「mariadb」のパスワード。
MariaDB [(none)]> GRANT ALL PRIVILEGES ON mariadb.* TO "mariadb"@"192.168.1.%" IDENTIFIED BY "*****";
Query OK, 0 rows affected (0.000 sec)

「*****」はユーザ「wordpress」のパスワード。
MariaDB [(none)]> GRANT ALL PRIVILEGES ON wordpress.* TO "wordpress"@"localhost" IDENTIFIED BY "*****";
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON gitea.* TO "gitea"@"localhost" IDENTIFIED BY "gitea";
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

OpenSSL(プライベート認証局)

WordPress

# systemctl stop nginx

ダウンロード、インストール

# cd /usr/share/nginx
# curl -O https://ja.wordpress.org/latest-ja.tar.gz
# tar xzfv latest-ja.tar.gz
# chown -R nginx:nginx wordpress

nginx 設定

# nano /etc/nginx/conf.d/wordpress.conf

server {
  listen 80;
  server_name wordpress.local;
  root /usr/share/nginx/wordpress;
  index index.php;
 
  charset utf-8;
 
# wordpress パーマネントリンク設定
  try_files $uri $uri/ /index.php?q=$uri&$args;
 
# wp-config.phpへのアクセス拒否設定
  location ~* /wp-config.php {
    deny all;
  }
 
# php-fpm用設定
  location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    include fastcgi_params;
  }
}

server {
  listen 443 ssl http2;
  server_name wordpress.local;
  root /usr/share/nginx/wordpress;
  index index.php;

  charset utf-8;

# SSL設定
ssl_certificate /etc/pki/tls/certs/server.crt;
ssl_certificate_key /etc/pki/tls/private/server.key;

# wordpress パーマネントリンク設定
  try_files $uri $uri/ /index.php?q=$uri&$args;

# wp-config.phpへのアクセス拒否設定
  location ~* /wp-config.php {
    deny all;
  }

# php-fpm 設定
  location ~ \.php$ {
    fastcgi_pass unix:/run/php-fpm/www.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_script_name;
    include fastcgi_params;
  }
}

php-frmの設定の関する注意点

/etc/nginx/conf.d/wordpress.confに記述してある

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

の、unix: 以降は

/etc/nginx/conf.d/php-fpm.confに記述してある

PHP-FPM FastCGI server
network or unix domain socket configuration

upstream php-fpm {
  server unix:/run/php-fpm/www.sock;
}

の、unix: 以降に合わせる必要があります。

# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

wp-config設定

# cd /usr/share/nginx/wordpress/
# cp -p wp-config-sample.php wp-config.php
# nano wp-config.php

// 「リダイレクトが繰り返し行われました。」対策【追加】
define('WP_HOME','https://wordpress.local');
define('WP_SITEURL','https://wordpress.local');

define( 'DB_NAME', 'wordpress' );
define( 'DB_USER', 'wordpress' );
define( 'DB_PASSWORD', '*****' );
# systemctl restart nginx

 https://wordpress.local

Gitea

# nano /etc/nginx/conf.d/gitea.conf
 
server {
    listen 80;
    server_name gitea.local;
    root /usr/share/nginx/gitea;
    index index.php;
 
    charset utf-8;
    location / {
        proxy_pass http://localhost:3000;
    }
}

server {
    listen 443 ssl http2;
    server_name gitea.local;
    root /usr/share/nginx/gitea;
    index index.php;

    charset utf-8;

# SSL設定
ssl_certificate /etc/pki/tls/certs/server.crt;
ssl_certificate_key /etc/pki/tls/private/server.key;

    location / {
        proxy_pass http://localhost:3000;
    }
}
# nginx -t
# systemctl restart nginx

初期設定

 https://gitea.local

オプションは設定しない。

エラー502が出ても気にしない。

動作確認!

 http://gitea.local

まずは「登録」をクリックしてユーザ登録。

公開鍵の登録

秘密鍵の登録

クライアントとなるPCの
「ホームディレクトリ/.ssh」フォルダにコピー。

動作確認!

https://wordpress.local/
https://gitea.local/

Git操作

init

$ git init

commit

$ git commit -m "first commit"

remote

$ git remote add origin git@<url:リポジトリ名>

push

$ git push -u origin <ブランチ名>
タイトルとURLをコピーしました