はじめに
この記事ではVirtualBoxを使用して、LAMP環境(Linux,Apache,PHP,MySql)を構築します。
VirtualBoxを使用した、CentOSの環境構築については以下の記事を参考にしてください。
VirtualBox(Windows10)にCentOS7環境を構築し、TeraTermでssh接続をする
環境
- VirtualBox:6.0
- ホストOS:Windows10
- ゲストOS:CentOS 7.9
- Apache:2.4.6
- PHP:8.1.17
- Mysql:8.0.27
1.初期設定
全パッケージのバージョンを最新のものに更新する。
# yum -y update
SELinuxを無効にし、設定を反映させるために再起動する。
# vi /etc/selinux/config
SELINUX=disabled
# reboot
2.Apacheのインストール
Apacheをインストールする。
# yum -y install httpd
Apacheを起動、自動起動の設定をする。
# systemctl start httpd
# systemctl enable httpd
サービスの起動状態を確認。
# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2022-01-23 12:23:49 JST; 4min 26s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 986 (httpd)
http接続できるように80番ポートを許可する。
# firewall-cmd --add-service=http --zone=public --permanent
success
設定を反映させるために再読みする。
# firewall-cmd --reload
success
3.PHPのインストール
PHPに関するパッケージがない事を確認
# yum list installed | grep php
もしあれば以下のコマンドで削除
# yum remove php*
Remiレポジトリの追加
# yum -y install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
インストールできるphp81系パッケージの確認
# yum list | grep php81
phpインストール
# yum -y install −−enablerepo=remi-php81 php81 php81-php php81-php-xml php81-php-xmlrpc php81-php-pecl-mcrypt php81-php-fpm php81-php-pecl-apcu php81-php-mbstring php81-php-gd php81-php-json php81-php-pecl-json-post php81-php-pdo php81-php-mysqlnd php81-php-pecl-mysql php81-php-opcache php81-php-pear php81-php-soap php81-php-intl php81-php-pear
インストールできたか確認
# php81 -v
PHP 8.1.17 (cli) (built: Mar 14 2023 19:50:20) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.17, Copyright (c) Zend Technologies
with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies
phpコマンドでphp81を実行できるようにシンボリックリンクを張る。
まずはphp81の確認
# which php81
/usr/bin/php81
シンボリックリンクを張る
# ln -sf /usr/bin/php81 /usr/bin/php
phpコマンドでバージョン確認
# php -v
PHP 8.1.17 (cli) (built: Mar 14 2023 19:50:20) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.1.17, Copyright (c) Zend Technologies
with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies
php/iniの設定。まずは場所の確認。
# php -i | grep php.ini
Configuration File (php.ini) Path => /etc/opt/remi/php81
Loaded Configuration File => /etc/opt/remi/php81/php.ini
php.iniを編集
# vi /etc/opt/remi/php81/php.ini
date.timezone = "Asia/Tokyo"
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = pass
mbstring.http_output = pass
mbstring.encoding_translation = Off
mbstring.detect_order = auto
mbstring.substitute_character = none;
mbstring.strict_detection = Off
post_max_size = 20M
upload_max_filesize = 20M
3.Mysqlのインストール
MariaDB関連のライブラリの削除
# yum remove mariadb-libs
# rm -rf /var/lib/mysql/
Remiレポジトリの追加
# rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm
インストールできるリポジトリの確認
# yum repolist all | grep mysql
GPGキーのインストール
# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
mysqlのインストール
# yum -y install mysql-community-server
バージョン確認
# mysql --version
mysql Ver 8.0.27 for Linux on x86_64 (MySQL Community Server - GPL)
mysqlを起動、自動起動の設定をする。
# systemctl start mysqld
# systemctl enable mysqld
サービスの起動状態を確認。
# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 日 2022-01-23 12:24:00 JST; 21min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 1057 (mysqld)
パスワードの確認。
# grep password /var/log/mysqld.log
2021-11-06T05:50:17.606050Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 現在のパスワード
mysql_secure_installationの実行。
ウィザードが立ち上がるので、それに従いパスワード等を設定。
# mysql_secure_installation
Press y|Y for Yes, any other key for No: Y
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
New password:
Re-enter new password:
Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
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
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) : N
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
All done!
接続を確認する
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 8.0.27 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
以上!