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?

はじめに

 私自身の行った作業をまとめたものになります。
 サーバ構築について経験が浅いため、至らない点が多々ある記事かと思いますが、コメントにてそれらご教示いただけますと幸いです。
 本記事では、AlmaLinuxを使用して、開発・検証用のOpenPNEサーバを構築する方法について記載いたします。サーバ構築がゴールなので、OpenPNE自体の操作方法に関してはあまり触れません。ご了承ください。

環境

AlmaLinux 9.5 ※投稿主はVirtual Boxを用いた仮想環境上で検証を行っております。
Apache 2.4.62
MySQL 8.0.41
PHP 7.4.33 ※記事公開時点ではPHP8以上のバージョンにOpenPNEが対応していません。
OpenPNE 3.10.19
推奨環境や各バージョンについては、OpenPNE公式が公開している情報も参考にしてください。(本記事最後の参考文献にリンクを掲載しています)

LAMP環境の構築

コマンド実行時は適宜rootユーザーで操作を行う、もしくは sudo も同時に用いるなどしてください。

Apacheのインストール

 標準リポジトリからApacheをインストールします。

shell
[username@localhost ~]# sudo dnf install httpd

 http.confファイルの設定を下記の通り変更します。

httpd.conf
(省略)

<IfModule dir_module>
    DirectoryIndex index.php index.html     <-- index.phpという文言を追加
</IfModule>

(省略)

<Directory "/var/www">
	AllowOverride All <--Noneから「All」に変更
	(省略)
</Directory>

# Further relax access to the default document root:
<Directory "/var/www/html">
    
    #Options Indexes FollowSymLinks  <-- コメントアウト
    Options FollowSymLinks  <-- 「Indexes」を削除

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    #AllowOverride None  <-- コメントアウト
    AllowOverride ALL   <-- 「ALL」に変更

    Require all granted
</Directory>

(省略)

 Rewriteモジュールの状態を確認します。下記のコマンドを入力して、結果が同様であれば問題ありません。

shell
[username@localhost ~]# httpd -M | grep rewrite
 rewrite_module (shared)

PHPのインストール

 PHP 7.4は、標準リポジトリでは提供されていないためEPELリポジトリ、Remiリポジトリを使用して、PHP 7.4のインストールを行います。

 EPELリポジトリとRemiリポジトリは、Red Hat社にサポートされていないリポジトリです。そのため自己責任の元で利用する必要がある点に注意してください。

 各リポジトリを追加します。

shell
[username@localhost ~]# sudo dnf -y install epel-release
[username@localhost ~]# sudo dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm

 dnfのメタデータキャッシュを作成します。

shell
[username@localhost ~]# sudo dnf clean all && dnf -y makecache

 現在のPHPがある場合、削除します。まずは現在のiniファイルをバックアップして、phpの各パッケージを削除します。(この作業は現在のPHPがない場合は必要ありません。)

shell
[username@localhost ~]# sudo cp /etc/php.ini /etc/php.ini.bk
[username@localhost ~]# sudo dnf remove php-*

 インストールするPHPのバージョンを指定します。

shell
[username@localhost ~]# sudo dnf module -y reset php 
[username@localhost ~]# sudo dnf module -y enable php:remi-7.4

 PHPおよび各モジュールをインストールします。

shell
[username@localhost ~]# sudo dnf -y install php php-cli php-fpm php-devel php-pear php-curl php-mysqlnd php-gd php-opcache php-zip php-intl php-common php-bcmath php-imagick php-xmlrpc php-json php-readline php-memcached php-redis php-mbstring php-apcu php-xml php-dom php-redis php-memcached php-memcache php-process

 「/etc/php.ini」ファイルを以下のとおり変更します。(必要があればバックアップしたiniファイルの内容に戻してください。)

php.ini

[mbstring]
; language for internal character representation.
; This affects mb_send_mail() and mbstring.detect_order.
; https://php.net/mbstring.language
mbstring.language = Japanese  <-- Japaneseに設定

; Maximum amount of memory a script may consume
; https://php.net/memory-limit
memory_limit = 128M  <-- 128MBに設定

; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
;post_max_size = 8M
post_max_size = 40M  <-- 40MBに設定

; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize
;upload_max_filesize = 2M
upload_max_filesize = 30M  <-- 30MBに設定

MySQLのインストール

 MySQLをインストールします。

shell
[username@localhost ~]# sudo dnf install mysql-server mysql

 MySQLサーバを起動します。

shell
[username@localhost ~]# sudo systemctl start mysqld

 MySQLサーバの初期設定を行います。下記の通りコマンドを実行します。

shell
[username@localhost ~]# mysql_secure_installation
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No:  <-- [Enter]を押下
Please set the password for root here.

New password:  <-- MySQLのrootのパスワードを入力

Re-enter new password:   <-- MySQLのrootパスワードを再入力
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y  <-- 「y」を入力
Success.

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y <-- 「y」を入力
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y <-- 「y」を入力
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y <-- 「y」を入力
Success.

All done!

OpenPNEのインストール

 公式がGitHubで公開しているOpenPNEのリポジトリをgit cloneコマンドでローカルに複製します。
 gitをインストールしていない場合は、まずgitをインストールします。

shell
[username@localhost ~]# sudo dnf install git

 git cloneコマンドを実行します。

OpenPNE公式の案内では、git clone実行時のURLがgit://github.com/...となっていますが、https://github.com/...でないとコマンドに失敗しました。

shell
[username@localhost ~]# sudo clone https://github.com/openpne/OpenPNE3.git
[username@localhost ~]# sudo cd OpenPNE3
[username@localhost ~]# sudo git checkout OpenPNE-3.10.19

 ダウンロードしたOpenPNEのファイルをアップロードします。

shell
[username@localhost ~]# sudo mkdir /var/www/sns
[username@localhost ~]# sudo mv OpenPNE3 /var/www/sns

 アップロードしたOpenPNEのファイルに権限を付与します。また、ディレクトリのパーミッションも設定します。

shell
[username@localhost ~]# sudo chown -R apache:apache /var/www/sns/
[username@localhost ~]# sudo find /var/www/sns -type d -exec chmod 755 {} \;
[username@localhost ~]# sudo find /var/www/sns -type f -exec chmod 644 {} \;

 OpenPNE用のデータベースおよびユーザーを作成します。

shell
[username@localhost ~]# mysql -u root -p
Enter password:          <-- 先ほど設定したパスワードを入力
MySQL
CREATE DATABASE pnedb;
CREATE USER 'pneuser'@'localhost' IDENTIFIED BY 'database_password';
GRANT ALL PRIVILEGES ON pnedb.* TO 'pneuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
quit

 ここからOpenPNEのディレクトリで作業を行います。

shell
[username@localhost ~]# sudo cd /var/www/sns/OpenPNE3
[username@localhost OpenPNE3]# sudo cp config/ProjectConfiguration.class.php.sample config/ProjectConfiguration.class.php
[username@localhost OpenPNE3]# sudo cp config/OpenPNE.yml.sample config/OpenPNE.yml

 必要に応じて、OpnePNE.ymlの設定を変更します。特にbase_url と mail_domain はメール投稿、メール配信の際に利用されるので、各自の環境に合わせて変更を行ってください。

shell
[username@localhost OpenPNE3]# sudo vim config/OpenPNE.yml
OpenPNE.yml
(省略)
base_url: "各自の環境"
mail_domain: "各自の環境"
(省略)

 インストール作業を開始します。下記の./symfonyを実行後、データベースに関する設定を行います。

shell
[username@localhost OpenPNE3]# ./symfony openpne:install --internet

DBMS:                 mysql
Database Username:    pneuser
Database Password:    (任意で設定、必要なければ入力しないままEnterキーを押す)
Database Hostname:    localhost
Database Port Number: (任意で設定、必要なければ入力しないままEnterキーを押す)
Database Name:        pnedb
Database Socket:      (任意で設定、必要なければ入力しないままEnterキーを押す)

 インストールが完了したら、ApacheのRewriteBaseの編集を行います。

shell
[username@localhost ~]# sudo vim /var/www/sns/OpenPNE3/web/.htaccess
.htaccess
Options +FollowSymLinks +ExecCGI

<IfMocule mod_rewrite.c>
 RewriteEngine On

 # uncomment (省略)
 # getting (省略)
 RewriteBase / ← 先頭の"#"を削除
 
(省略)

 最後にApacheを起動しておきます。(すでに起動している場合は再起動を行ってください。)

shell
[username@localhost ~]# sudo systemctl start httpd
[username@localhost ~]# sudo systemctl restart httpd #再起動の場合はこちら

OpenPNEにログインする

 ブラウザでhttp://IPアドレス/にアクセスすると、OpenPNEの一般ユーザーのログイン画面が表示されるはずです。ログインフォームに sns@example.com / password と入力し、ログインできるかどうか確認してください。

管理者画面にログインする

 サーバーのPCでhttp://IPアドレス/pc_backend.phpにアクセスすると、管理者用のログイン画面が表示されるはずです。ログインフォームに admin / password と入力し、ログインできるかどうか確認してください。

作業時のエラーについて

 私が作業中に起きたエラーを共有します。

PHPのバージョンによるエラー

 以下のエラーは、PHPのバージョンが8以上の状態で作業を進めた際、./symfonyを実行するときに発生しました。バージョンが異なると配列や関数の定義や呼び出し方が変更されており、それが原因でエラーとなるようです。

shell
[username@localhost OpenPNE3]# ./symfony openpne:install --internet
PHP Fatal error: Array and string offset access syntax with curly braces is no longer supported in /var/www/sns/Open3/lib/vendor/symfony/lib/util/sfFinder.class.php on line 583

ブラウザでログイン画面のURLを入力すると「現在サーバが混みあっているか、メンテナンス中です」と表示される

 この表示が出た場合、解決方法はその時々によって異なるようです。原因を探るには、http://IPアドレス/pc_frontend_dev.phpにアクセスして、ページ下部のエラー表記を見るのが有効です。
 私が作業していた時は、SQLクエリで作成したデータベースの名前と、.symfony実行時に指定したデータベースの名前が異なっていたためにエラーが発生していました。そのため、データベースを改めて作成して、Apacheを再起動することで解決できました。

参考文献

下記のOpenPNEサーバ構築に関するサイトを参考にさせていただきました。
openPNEを構築してみた話 - DENET技術ブログ
(最終閲覧日:2025年7月12日)
また、下記のOpenPNE公式サイトも参考にしました。より詳細な手順は下記リンク先の「セットアップ手順はこちら」もご覧ください。
ダウンロード/OpenPNE3 - OpenPNE
(最終閲覧日:2025年7月12日)
PHPのバージョン指定に関しては、下記の記事を参考にしました。
AlmaLinux8のPHPを7.3/7.4/8.0/8.1/8.2系にバージョンアップする - Qiita/heimaru1231
(最終閲覧日:2025年7月12日)

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?