はじめに
下記記事で説明した手順に従って構築したVirtualBox上の仮想環境(CentOS 7)を基に、この記事ではLAMP環境の構築とWordPressの導入・動作確認までの具体的なステップを詳細に解説します。
尚、今回は勉強用のためSELinuxやファイアウォールを切って操作を行います。

Windows11+VirtualBox+CentOS7+SSH接続の環境構築手順書
はじめに最新版のVirtualBox7.0.8とCentOS7の組み合わせがうまくインストールできない問題が発生しました。VirtualBoxのバージョンを変更してインストールを試み、問題が解決できたため、本記事では、その動作確認に至る具体...
今回インストールと動作確認するサービス
- Apache Ver.2.4.6
- PHP Ver.7.4.33
- MariaDB Ver.5.5.68
- phpMyAdmin Ver.4.4.15.10
- vsftp Ver.3.0.2
- Samba Ver.4.10.16
前提
この記事の仮想環境が準備できており、Tera TermでSSH接続できている事です。

Windows11+VirtualBox+CentOS7+SSH接続の環境構築手順書
はじめに最新版のVirtualBox7.0.8とCentOS7の組み合わせがうまくインストールできない問題が発生しました。VirtualBoxのバージョンを変更してインストールを試み、問題が解決できたため、本記事では、その動作確認に至る具体...
事前準備
システムを最新の状態に更新
sudo yum update -y
vimのインストール
sudo yum install vim -y
SELinuxの無効化
sudo vim /etc/selinux/config
設定を下記の通り変更してください。
SELINUX=enforcing ↓ SELINUX=disabled
SELinux無効化の確認
下記コマンドで「disabled」と表示されたら無効化されています。
sestatus
ファイアウォールの無効化
sudo systemctl stop firewalld sudo systemctl disable firewalld
Apacheのインストールと設定
インストール
sudo yum install httpd -y
ドキュメンルートの変更準備(必要な人だけ)
ドキュメンルートを /var/www/httml → /home/jet-blog/html に変更する場合
sudo mkdir -p /home/jet-blog/html sudo chown -R jet-blog:jet-blog /home/jet-blog/html sudo chmod +x /home/jet-blog sudo usermod -a -G apache jet-blog
ドキュメンルートの設定書き換え(必要な人だけ)
sudo vim /etc/httpd/conf/httpd.conf
※119行目付近 : DocumentRoot
※131行目付近 : <Directory>
/var/www/httml → /home/jet-blog/html に変更する場合
変更前
# DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/var/www/html" # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/var/www/html"> # # Possible values for the Options directive are "None", "All",
変更後
# DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/home/jet-blog/html" # # Relax access to content within /var/www. # <Directory "/var/www"> AllowOverride None # Allow open access: Require all granted </Directory> # Further relax access to the default document root: <Directory "/home/jet-blog/html"> # # Possible values for the Options directive are "None", "All",
Apache起動
sudo systemctl start httpd sudo systemctl enable httpd
PHPのインストール
sudo yum install epel-release yum-utils -y sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y sudo yum-config-manager --enable remi-php74 sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt php-mbstring php-curl php-xml php-pear php-bcmath php-json -y
インストールの確認
php -v
Apache再起動
sudo systemctl restart httpd
MariaDBのインストール
sudo yum install mariadb-server mariadb -y sudo systemctl start mariadb sudo systemctl enable mariadb
初期設定スクリプト実行
sudo mysql_secure_installation
質問形式でMariaDBの初期設定を行ってくれます。
- Enter current password for root (enter for none):
- MariaDBの現在のrootパスワードを入力してください。
- 初期はパスワード無し(none)なので、そのままEnter
- MariaDBの現在のrootパスワードを入力してください。
- Set root password? [Y/n]
- Rootのパスワード設定をしますか?
- お好みで設定してください
- Rootのパスワード設定をしますか?
- Remove anonymous users? [Y/n]
- 匿名ユーザーを削除しますか?
- お好みで設定してください。
- 匿名ユーザーを削除しますか?
- Disallow root login remotely? [Y/n]
- リモートからのrootログインを無効にしますか?
- お好みで設定してください。
- リモートからのrootログインを無効にしますか?
- Remove test database and access to it? [Y/n]
- testデータベースとアクセス権限を削除しますか?
- お好みで設定してください。
- testデータベースとアクセス権限を削除しますか?
- Reload privilege tables now? [Y/n]
- 特権テーブルを今すぐ再読み込みしますか?
- 「Y」で反映させましょう。
- 特権テーブルを今すぐ再読み込みしますか?
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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? [Y/n] 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? [Y/n] n ... skipping. By default, MariaDB 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? [Y/n] 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? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
jet-blogユーザーの追加と特権設定
sudo mysql -u root -p CREATE USER 'jet-blog'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON *.* TO 'jet-blog'@'localhost' WITH GRANT OPTION; FLUSH PRIVILEGES; exit;
phpMyAdminのインストール
sudo yum install epel-release -y sudo yum install phpmyadmin -y sudo systemctl restart httpd
phpMyAdminを外部のPCからアクセスさせる設定
sudo vim /etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 <IfModule mod_authz_core.c> # Apache 2.4 <RequireAny> Require all granted # Require ip 127.0.0.1 # Require ip ::1 </RequireAny> </IfModule> <IfModule !mod_authz_core.c> # Apache 2.2 Order Allow,Deny Allow from all # Allow from 127.0.0.1 # Allow from ::1 </IfModule> </Directory>
sudo systemctl restart httpd
vsftpdのインストール
sudo yum install vsftpd -y sudo systemctl start vsftpd sudo systemctl enable vsftpd
sambaのインストール
sudo yum install samba samba-client samba-common -y
sambaで共有するディレクトリの追加
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak sudo vim /etc/samba/smb.conf
下記を追記
[samba] path = /home/jet-blog/html writable = yes valid users = jet-blog
sambaで共有できるユーザーの追加
sudo smbpasswd -a jet-blog
sambaの起動と自動起動設定
sudo systemctl start smb sudo systemctl start nmb sudo systemctl enable smb sudo systemctl enable nmb