長らく使用していなかったデスクトップPCの開発環境を整える(win7, vagrant, LAMP)
引っ越しから3か月 作業机がやっと導入された~~( ;∀;)
ダイニングテーブルに出すわけにもいかず埃をかぶっていたデスクトップPCを とりあえず使えるようにします。
OSはwin7です
本当は10にしたかったのに無料期間終わってたので諦めました
いつまでも あると思うな 無償版
win7なんてほんと今更なんだけど、せっかくなので書きます。
ざっくり手順
- ターミナルをインストールする(teraterm)
- VirtualBoxとVagrantを使って仮想マシンを起動
- LAMP環境を整える
ちな今回最終的に入れるのはこちら
- L: Linux(CentOS6.8)
- A: apache2.2
- M: Mysql5.6
- P: PHP7.1
それじゃあ行ってみよう☺
ターミナルをインストールする
窓の社からダウンロード
「Tera Term」定番のターミナルエミュレーター - 窓の杜ライブラリ
エディタをインストールする
この記事に全部書いてあるから特筆することない。
VirtualBoxとvagrantを入れる
本当ならdocker使いたいところなんだけど、hyper-vが使えないので(win7)いつも通りvirtualboxとvagrantで建てます
ここからvirtualboxをダウンロード
Windows hostsをクリック
今度はここからvagrantをダウンロード
※64bit版と32bit版があるけどコンパネからシステムとセキュリティ>システムで「システムの種類」を参照して一致する方を選択
windows power shell起動
仮想マシン起動準備
1.仮想マシン用のディレクトリを作る
複数の仮想マシンを作ることを想定して、それらをまとめておくディレクトリ(MyVagrant)を作成し、その中に仮想マシンを作るディレクトリを作る(MyCentOS)1
PS C:\Users\osato>mkdir MyVagrant PS C:\Users\osato\MyVagrant>cd MyVagrant PS C:\Users\osato\MyVagrant>mkdir MyCentOS PS C:\Users\osato\MyVagrant\MyCentOS>cd MyCentOS
2.仮想マシン設定用のVagrantfileを作る
ここで使いたい仮想マシンのもととなるVagrantBoxを探す
Discover Vagrant Boxes - Vagrant Cloud
今回は私の都合でcentos6.8を入れる
PS C:\Users\osato\MyVagrant\MyCentOS> vagrant init bento/centos-6.8 A `Vagrantfile` has been placed in this directory. You are now ready to `vagrant up` your first virtual environment! Please read the comments in the Vagrantfile as well as documentation on `vagrantup.com` for more information on using Vagrant.
終わったらカレントディレクトリの中身を確認
PS C:\Users\osato\MyVagrant\MyCentOS> dir ディレクトリ: C:\Users\osato\MyVagrant\MyCentOS Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 2018/01/20 18:14 3093 Vagrantfile
Vagrantfileが作成されている。
3.Vagrantfileの編集
Vagrantfileを開いて
config.vm.network "private_network", ip: "192.168.33.10"
のコメントアウトを外す
4.仮想マシン起動
Vagrantfileを作成したディレクトリ内でvagrant up
を実行
トラブル発生・・・
のどちらかを試す必要があるようだ。
とりあえず1の手順を試すとしよう。 まずはpowershellのバージョンを確認。 私のマシンに入っているpowershellはVersion : 2.0 最新は5.1・・・・・? とりあえずアップデートしよう。 .Net Frameworkのバージョン確認方法はこちらの記事を参考に
ITmediaで配布されているzipをダウンロードして展開したら まれにcheckvdnfw_cmdのみしか表示されない場合がある。これは登録されている拡張子を非表示にする設定になっているためなので で拡張子を表示する設定に変更。 ここまでできたらpowershell上から展開したディレクトリまで移動し、 4までしか入っていないことが判明。 .Net Frameworkの4.5.2以上をインストールして、それからpowershellをインストールするとしよう。 ダウンロード出来たら再度バージョンを確認 4.6入った(^_^) それじゃあpowershell5.1を・・・・とおもったら、 zipファイルを解凍してpowershellを管理者権限で起動 なのこっちゃ🤔??? とりあえずググると次の記事がヒット WindowsでPowerShellスクリプトの実行セキュリティポリシーを変更する:Tech TIPS - @IT 要はセキュリティ上の問題で「.ps1」の拡張子を持つファイルが実行できないようになっているから 実行ポリシーを変更するため以下のコマンドを実行 再度
実行しますか?と聞かれるのでRを入力し、enterキーを押下 さあ、バージョンはどうなったかというと、、 お!5.1が入ってる!!! やったーーーー🎉🎉🎉🎊🎊🎊!!ドンドンパフパフ 無事バージョンも上がったので、先ほど変更した実行ポリシーは元に戻しましょう。 ふう・・・・・ひと段落ついたところで、いったい何をやっていたのだったかな・・・・・・・? そうだ、vagrant upから先に進まない問題
ググるとこちらの記事がヒット
記事によると、
PS C:\Users\osato\MyVagrant\MyCentOS> Get-Host
Name : ConsoleHost
Version : 2.0
InstanceId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : ja-JP
CurrentUICulture : ja-JP
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
古!!!wwwwwwww
すでに非推奨になってた2
とはいったもののpowershellの最新をそのまま取ってきてインストールすればいいというものではないらしい。
どうやらpowershell5.1を動かすには.Net Frameworkの4.5.2以上が必要なようだ。
checkvdnfw_cmd.txt
を checkvdnfw.cmd
にリネーム。
.\checkvdnfw.cmd
を実行----- ローカル・コンピュータ(Lion-PC) -----
.NET Framework 2.0 Service Pack 2 がインストール済みです
日本語Language Pack(Service Pack 2)がインストール済みです
.NET Framework 3.0 Service Pack 2 がインストール済みです
日本語Language Pack(Service Pack 2)がインストール済みです
.NET Framework 3.5 Service Pack 1 がインストール済みです
日本語Language Pack(Service Pack 1)がインストール済みです
.NET Framework 4(フル版) がインストール済みです
日本語Language Pack(フル版) がインストール済みです
※すでに4.5.2以上が入っている場合は飛ばしておk
こちら.aspx)から最新版をダウンロード(現時点では4.6.2)
詳細: .NET Framework Developer Pack または再頒布可能パッケージをインストールするには | Microsoft DocsPS C:\Users\Lion\Downloads\checkvdnfw-20151009> .\checkvdnfw.cmd
----- ローカル・コンピュータ(Lion-PC) -----
.NET Framework 2.0 Service Pack 2 がインストール済みです
日本語Language Pack(Service Pack 2)がインストール済みです
.NET Framework 3.0 Service Pack 2 がインストール済みです
日本語Language Pack(Service Pack 2)がインストール済みです
.NET Framework 3.5 Service Pack 1 がインストール済みです
日本語Language Pack(Service Pack 1)がインストール済みです
.NET Framework 4.6 がインストール済みです
日本語Language Packがインストール済みです
PS C:\Users\Lion\Downloads\checkvdnfw-20151009>
powershellというのはWMF(Windows Management Framework)に含まれるツールの一つらしい。
WMFをインストールすると一緒に新しいpowershellが入るとのこと。
展開したフォルダにcdコマンドで移動.\Install-WMF5.1.ps1
を実行すると今度は下記エラーが・・・スクリプトの実行がシステムで無効になっているため、ファイル C:\Users\osato\Downloads\インストーラ\Win7AndW2K8R2-KB31915
66-x64\Install-WMF5.1.ps1 を読み込めません。詳細については、「get-help about_signing」と入力してヘルプを参照してくださ
い。
実行できるようにしなければならないということらしい。Set-ExecutionPolicy RemoteSigned
.\Install-WMF5.1.ps1
インストーラが起動するのでライセンスに同意して再起動PS C:\Windows\system32> Get-Host
Name : ConsoleHost
Version : 5.1.14409.1005
InstanceId : XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
UI : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture : ja-JP
CurrentUICulture : ja-JP
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : False
Runspace : System.Management.Automation.Runspaces.LocalRunspace
Set-ExecutionPolicy RemoteSigned
vagrant up
が失敗したのでした。
```
だいぶ脱線してしまったけど 気を取り直してvagrant up
PS C:\Users\osato\MyVagrant\MyCentOS> vagrant status Current machine states: default running (virtualbox) The VM is running. To stop this VM, you can run `vagrant halt` to shut it down forcefully, or you can run `vagrant suspend` to simply suspend the virtual machine. In either case, to restart it again, simply run `vagrant up`.
はい勝利😂
teratermからログインしてみる
teraterm起動して、
ホストに 192.168.33.10
を入力
OKボタン押下
vagrant初期状態なら
ユーザ名もパスも vagrant
※後で変える
apacheインストール(LAMPのA)
root権限で
yum -y update
したら
apacheインストール
[root@localhost ~]#yum -y install httpd [root@localhost ~]# httpd -v Server version: Apache/2.2.15 (Unix) Server built: Oct 19 2017 16:43:38
apache 起動
[root@localhost ~]# service httpd start Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName [ OK ]
設定ファイル内でサーバ名指定していないからか警告がでているが、いったん置いといてあとで設定。
今すぐ修正するならこちらの記事をご参考に↓↓
Apache を再起動すると、「httpd: Could not reliably determine the server’s fully qualified domain name, using XXXXXXXXXXXXX for ServerName」と出力される – KUJIRA note
mysqlのインストール(LAMPのM)
とりあえず比較的新しいものを使ってみたいところではあるが、5.7は5.6までとかなり違うとの前情報があるため いったん5.6をインストールして様子見てバージョンあげようかな・・・・
まずは、既存のmysqlがあれば削除
[root@localhost ~]# yum list installed | grep mysql mysql-libs.x86_64 5.1.73-8.el6_8 @base [root@localhost ~]# yum erase mysql-libs ... Complete!
yumでMySQL5.6をインストールする話 | Skyarch Broadcasting
rpm -ivh http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
yum
コマンドでmysql5.6をインストール
[root@localhost ~]# yum install mysql mysql-server mysql-devel mysql-utilities
確認
[root@localhost ~]# rpm -qa | grep mysql mysql-community-release-el6-5.noarch mysql-community-common-5.6.39-2.el6.x86_64 mysql-community-client-5.6.39-2.el6.x86_64 mysql-connector-python-2.1.7-1.el6.x86_64 mysql-community-devel-5.6.39-2.el6.x86_64 mysql-community-libs-5.6.39-2.el6.x86_64 mysql-community-server-5.6.39-2.el6.x86_64 mysql-utilities-1.6.5-1.el6.noarch [root@localhost ~]# mysql --version mysql Ver 14.14 Distrib 5.6.39, for Linux (x86_64) using EditLine wrapper
5.6入りました
mysql起動
[root@localhost ~]# service mysqld start Initializing MySQL database: 2018-01-20 22:04:05 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details). ・<br> ・<br> ・<br> ・<br> PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems at http://bugs.mysql.com/ The latest information about MySQL is available on the web at http://www.mysql.com Support MySQL by buying support/licenses at http://shop.mysql.com Note: new default config file not created. Please make sure your config file is current WARNING: Default config file /etc/my.cnf exists on the system This file will be read by default by the MySQL server If you do not want to use this, either remove it, or use the --defaults-file argument to mysqld_safe when starting the server [ OK ] Starting mysqld: [ OK ]
この状態だとサーバー停止する度にいちいち立ち上げなおさなきゃいけなくなるので
自動起動設定する
現在は
[root@localhost ~]# chkconfig --list mysqld mysqld 0:off 1:off 2:off 3:on 4:on 5:on 6:off
自動起動設定
[root@localhost ~]# chkconfig mysqld on [root@localhost ~]# chkconfig --list mysqld mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
mysql_secure_installation
を実行してセキュリティ要件を設定する
こいつは最低限のセキュリティ設定をしてくれるありがたいコマンドらしい
[root@localhost bin]# /usr/bin/mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, 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 MySQL 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 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? [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, 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? [Y/n] y - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - 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! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
[root@localhost bin]# mysql -u root -p Enter password: mysql> SHOW VARIABLES LIKE 'char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.01 sec)
文字コードが一部latin1になってしまっているのでutf_8に変更する
一度バックアップ
cp -rp /etc/my.cnf /etc/my.cnf.bak
以下の項目を[mysqld]、[mysql]、[client]の下に追加。なければ項目ごと追加。
#vim /etc/my.cnf [mysqld] default-storage-engine=InnoDB innodb_file_per_table character-set-server = utf8 collation-server = utf8_general_ci [mysql] default-character-set=utf8 [client] default-character-set = utf8
再起動して反映
# /etc/init.d mysql restart
変更確認
mysql> SHOW VARIABLES LIKE 'char%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
MySQLインストールの後、初期設定をする手順 | 田舎に住みたいエンジニアの日記
PHPをインストールする(LAMPのP)
remiリポジトリのパッケージをとってくる
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm # yum install yum-utilsyum-config-manager --enable remi-php70 # yum install php # php -v 5.3.3
7.1いれたいんだけど・・・・なんかうまく入らなかったぞ よく見るとこれcentos7用のパッケージでは。 一旦けす
rpm -qa | grep php yum remove php-*
centOS6系のパッケージいれる
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm yum install yum-utilsyum-config-manager --enable remi-php70
再度インストール
[root@localhost bin]#yum install --enablerepo=remi,remi-php71 php php-devel php-mbstring php-pdo php-gd php-xml php-mcrypt [root@localhost bin]# php -v PHP 7.1.14 (cli) (built: Jan 31 2018 08:50:37) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
無事一通り入ったようなのでブラウザからhttp://192.168.33.10/
にアクセス
→apacheでたやで!!!!!!!
とりあえずここまでできれば素のPHPは動く。