やりたいこと
centOS7でLAMP環境を構築する。
(PHPのみ、7を指定。)
バージョン
centOS7
Apache2.4.6
PHP7.0.18
MySQL5.6.36
前提条件
centOS7のインストール・初期設定が完了していること
Apacheインストール
インストール実行
# yum -y install httpd
起動状態の確認
# systemctl status httpd
サービスの起動
# systemctl start httpd.service
自動起動をONにする
# systemctl enable httpd.service
ブラウザからアクセスして初期画面が表示されればOK。
PHP7インストール
EPELリポジトリ追加
# yum install epel-release
Remiリポジトリ追加
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
インストール実行
# yum install --enablerepo=remi,remi-php70 php php-mbstring php-devel php-pdo php-gd php-mysqlnd
php.iniの編集
※こちらのサイトを参考にさせていただきました
# vi /etc/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.func_overload = 0
mbstring.strict_detection = Off
mbstring.http_output_conv_mimetype=
Apache再起動
# systemctl restart httpd
テストファイルを作成
# vi /var/www/html/index.php
infoを表示するコード↓を記述して保存
<?php phpinfo(); ?>
ブラウザからアクセスして、infoが表示されていればOK。
MySQLインストール
リポジトリファイルをインストール
# yum -y install http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
MySQLインストール
# yum -y install mysql mysql-devel mysql-server mysql-utilities
my.cnfの編集
# vi /etc/my.cnf
[mysqld]の欄に以下を追記
character-set-server = utf8
MySQL起動
# systemctl start mysqld
MySQLにログイン(パスワード無し)
# mysql -u root -p
rootのパスワードをthisIsPasswordに変更
>update mysql.user set password=password('thisIsPassword') where user = 'root';
変更を反映する
>flush privileges;
ログアウト
>exit;
rootのthisIsPasswordでログインできればOK。
MySQL再起動
# systemctl restart mysqld
自動起動の設定
httpd自動起動ON
# systemctl enable httpd.service
mysql自動起動ON
# systemctl enable mysqld.service
httpd自動起動確認
# systemctl is-enabled httpd.service
mysql自動起動確認
# systemctl is-enabled mysqld.service
「enabled」になっていれば、自動起動がONになっている。
終了!