使用Vagrant搭建LAMP环境
LAMP环境
-
- MacBook Pro
-
- Linux(CentOS 6.6)
-
- Apache 2.2
-
- MySQL 5.6
- PHP 5.4.x
安装 CentOS 6.6
添加一个vagrant box
复制所需安装版本的URL。这次我们使用6.6版本。
http://www.vagrantbox.es/
$ vagrant box add centos66 https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'centos66' (v0) for provider:
box: Downloading: https://github.com/tommy-muehle/puppet-vagrant-boxes/releases/download/1.0.0/centos-6.6-x86_64.box
==> box: Successfully added box 'centos66' (v0) for 'virtualbox'!
我已经通过以上方式成功添加了一个BOX。
- vagrantの初期化
$ vagrant init centos66
在文件夹中创建一个Vagrantfile文件。
- Vagrantfileの変更
29 # config.vm.network "private_network", ip: "192.168.33.10"
40 # config.vm.synced_folder "../data", "/vagrant_data"
46 # config.vm.provider "virtualbox" do |vb|
47 # # Display the VirtualBox GUI when booting the machine
48 # vb.gui = true
49 #
50 # # Customize the amount of memory on the VM:
51 # vb.memory = "1024"
52 # end
解除上述的注释。
将第40行更改为任意共享文件夹。
通过mount_options可以更改共享文件夹的权限(如果不这样做,chmod将无效)。
config.vm.synced_folder “.”, “/var/www/html”, :mount_options => [‘dmode=777’, ‘fmode=777’]可以实现这一功能。
- vagrant起動
$ vagrant up
- vagrant環境にログインする
$ vagrant ssh
只要成功登录就可以了!
在CentOS6.6上进行环境配置。
$ vagrant ssh
$ su -
登录后切换至超级用户, 默认密码为 ‘vagrant’,先进行系统更新。
yum update
Apache的安装
确认httpd版本
yum info httpd
确认版本为2.2,因此需要安装最新版。
yum -y install httpd
httpd -v
Server version: Apache/2.2.15 (Unix)
可以在 httpd.conf 文件中进行配置更改。
/etc/httpd/conf/httpd.conf
#httpd起動
/etc/rc.d/init.d/httpd start
#httpd自動起動設定
chkconfig httpd on
MySQL的安装
#mysql確認
rpm -qa | grep mysql
#競合するため削除
yum remove mysql*
将rpm仓库添加到yum中
yum -y install http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
确认要安装的版本。
vi /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
开启=1将被安装。
#インストール実行
yum install mysql-client mysql-server
#mysql起動
/etc/init.d/mysqld start
#バージョン確認
mysql --version
mysql Ver 14.14 Distrib 5.6.37, for Linux (x86_64) using EditLine wrapper
#mysql自動起動設定
chkconfig mysqld on
#自動に起動するか確認
chkconfig | grep mysql
登入MySQL
mysql -u root
安装PHP
#phpバージョン確認
rpm -qa | grep php
#古いバージョンがあれば一応削除
yum remove php-*
#epelレポジトリ
rpm -Uvh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
#remiレポジトリ
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
#5.4のインストール
yum install --enablerepo=remi,remi-php54 php php-pear php-devel php-mbstring php-pdo php-gd
#install結果確認
rpm -qa | grep php
#バージョン確認
php -v
编辑设置文件
vi /etc/php.ini
#以下を変更
error_logs = /var/log/php_errors.log
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = auto
mbstring.detect_order = auto
expose_php = off
date.timezone = Asia/Tokyo
#apache再起動
service httpd restart
安装phpMyAdmin
yum -y install --enablerepo=remi-php54 phpMyAdmin