「PHP 7.2.0」が2017年11月30日に公開されたので最新版のPHP7.2を含むLAMP環境のインストールをしてみます。
PHP7.2では暗号化ライブラリlibsodiumがコアに加わるなどの変更が行われています。
インストールは標準のVagrant(centos/7)から実施しています。
まずは必要そうなrpmのインストールを行います。
1 2 3 4 5 |
$ sudo yum -y update $ sudo yum -y install wget vim git ftp gcc make perl zlib-devel git gcc-c++ readline-devel svn perl-devel perl-CPAN openssl-devel nkf mailx $ sudo yum -y groupinstall development |
次にちょっとシステム設定を変更しておきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$ sudo hostname sample-web01 $ sudo vi /etc/hostname -----------------------------変更 localhost.localdomain ↓ sample-web01 ----------------------------- $ sudo vi /etc/hosts -----------------------------削除 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 ----------------------------- |
だいたい定番になってしまいますがSELinuxを無効化します。
1 2 3 4 5 6 7 8 9 |
$ sudo setenforce 0 $ sudo vi /etc/selinux/config -----------------------------変更 SELINUX=disabled ----------------------------- $ sudo shutdown -r now |
最後に再起動したところで事前準備完了です。
まずはREMIのリポジトリ追加を行います。
1 2 3 4 5 6 |
$ cd /etc/yum.repos.d $ sudo yum -y install epel-release $ sudo rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm $ sudo vi /etc/yum.repos.d/remi.repo |
次にApacheのインストールをREMIのリポジトリから行います。
1 2 3 4 5 |
$ sudo yum -y install --enablerepo=remi httpd httpd-devel mod_ssl cronolog $ sudo systemctl enable httpd.service Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. |
httpd関連の設定をちょこっとしておきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ cd /etc/httpd/conf $ sudo cp -p httpd.conf httpd.conf.org $ sudo vi httpd.conf $ diff httpd.conf httpd.conf.org 144c144 < Options FollowSymLinks --- > Options Indexes FollowSymLinks 316c316 < #AddDefaultCharset UTF-8 --- > AddDefaultCharset UTF-8 $ sudo systemctl start httpd.service |
さて、ようやくPHP7.2のインストールです。
REMIのリポジトリを追加した段階でPHP7.2用のインストールファイルも入っているので、「remi-php72」を参照します。
1 2 3 |
$ sudo yum install -y --enablerepo=remi,remi-php72 php php-devel php-mbstring php-pdo php-gd php72-php-mcrypt php72-php-pecl-imagick php72-php-pecl-imagick-devel php72-php-pecl-zip php72-php-xmlrpc php72-php-xml php72-php-pecl-http php72-php-pecl-http-devel php72-php-opcache php72-php-mysqlnd php72-php-bcmath php-xml |
初期段階としてphp.iniのファイルを変更しておき、サービスのリスタートなどを行います。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
$ cd /etc $ sudo cp -p php.ini php.ini.org $ sudo vi php.ini ----------------------------- enable_dl = Off upload_max_filesize = 2M ;date.timezone = ;mbstring.language = Japanese ;mbstring.internal_encoding = EUC-JP ;mbstring.http_input = auto ;mbstring.http_output = SJIS ;mbstring.encoding_translation = Off ----------------------------- ↓ -----------------------------変更 enable_dl = On upload_max_filesize = 100M date.timezone = Asia/Tokyo mbstring.language = Japanese mbstring.internal_encoding = UTF-8 mbstring.http_input = auto mbstring.http_output = pass mbstring.encoding_translation = Off ----------------------------- $ cd /tmp $ sudo curl -sS https://getcomposer.org/installer | php $ sudo mv composer.phar /usr/local/bin/composer $ sudo systemctl restart httpd.service |
次にmariadbのインストールですが公式サイトからリポジトリを選択して「/etc/yum.repos.d/mariadb.repo」に保存します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$ sudo vi /etc/yum.repos.d/mariadb.repo ------------------------------------------------------------- # MariaDB 10.2 CentOS repository list - created 2017-12-10 11:52 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.2/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 ------------------------------------------------------------- $ sudo yum -y install MariaDB-server MariaDB-client MariaDB-devel |
初期設定もちょこっとしておきます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
$ sudo cp -p /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.org $ sudo vi /etc/my.cnf.d/server.cnf $ diff /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.org 13,16d12 < character-set-server=utf8 < plugin-load = handlersocket.so < log-bin=mysql-bin < expire_logs_days = 30 $ sudo systemctl start mariadb.service $ sudo systemctl enable mariadb.service $ sudo mysql_secure_installation 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] Y ... Success! 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! |
最後に「php-mysqlnd」を入れて完了です。
1 2 3 |
$ sudo yum -y install --enablerepo=remi,remi-php72 php-mysqlnd |
なんだかんだでLAMP環境は定期的に使うので、ローカルのVagrant環境でもささっと作れる状態にしておくと検証が便利です。
このブログは株式会社CoLabMixによる技術ブログです。
GCP、AWSなどでのインフラ構築・運用や、クローリング・分析・検索などを主体とした開発を行なっています。
Ruby on RailsやDjango、Pythonなどの開発依頼などお気軽にお声がけください。
開発パートナーを増やしたいという企業と積極的に繋がっていきたいです。
お問い合わせやご依頼・ご相談など