VagrantでPHPのプロファイル環境[CentOS6(32bit)+XDebug+Webgrind]

注釈

XDebug のプロファイル出力を Webgrind で参照する
XDebug のプロファイルの出力ディレクトリーは /tmp 配下
64bit版が使用できる場合は、 VagrantでPHPのプロファイル環境[CentOS7(64bit)+XDebug+XHProf] を参照
有効になるURL
URL パス 概要
http://192.168.33.10/ /var/www/vagrant/ ドキュメントルート
http://192.168.33.10/webgrind/ /var/www/vagrant/webgrind/ Webgrind
http://192.168.33.10/phpinfo.php /var/www/vagrant/phpinfo.php phpinfo();

CentOS6(32bit)+Apache22+PHP56

Vagrantfile

1
2
3
4
5
6
7
8
Vagrant.configure(2) do |config|
  config.vm.box = "bento/centos-6.7-i386"
  config.vm.network "private_network", ip: "192.168.33.10"
  config.vm.synced_folder "../www", "/var/www/vagrant", create: true, owner: "vagrant", group: "vagrant", mount_options: ['dmode=777','fmode=755']
  config.vm.provider "virtualbox"
  config.vm.provision :shell, :path => "provision.sh"
  config.ssh.insert_key = false
end

provision.sh

 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
#!/bin/sh

### Les RPM de Remi
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
### basic lib
yum -y install --enablerepo=remi vim git
### Apahe
mkdir -p /var/www/vagrant && chown vagrant: /var/www/vagrant
yum -y install --enablerepo=remi httpd
sed -i -e "s/^User apache$/User vagrant/g" /etc/httpd/conf/httpd.conf
sed -i -e "s/^Group apache$/Group vagrant/g" /etc/httpd/conf/httpd.conf
touch /etc/httpd/conf.d/vhosts.conf && chown vagrant: /etc/httpd/conf.d/vhosts.conf
echo 'NameVirtualHost *:80' >> /etc/httpd/conf.d/vhosts.conf
echo '<VirtualHost *:80>' >> /etc/httpd/conf.d/vhosts.conf
echo '  DocumentRoot /var/www/vagrant' >> /etc/httpd/conf.d/vhosts.conf
echo '  <Directory /var/www/vagrant>' >> /etc/httpd/conf.d/vhosts.conf
echo '      Options FollowSymLinks' >> /etc/httpd/conf.d/vhosts.conf
echo '      AllowOverride All' >> /etc/httpd/conf.d/vhosts.conf
echo '      #Order deny,allow' >> /etc/httpd/conf.d/vhosts.conf
echo '      #Deny from all' >> /etc/httpd/conf.d/vhosts.conf
echo '  </Directory>' >> /etc/httpd/conf.d/vhosts.conf
echo '</VirtualHost>' >> /etc/httpd/conf.d/vhosts.conf
### PHP
yum -y install --enablerepo=remi,remi-php56 php php-cli php-common php-devel php-gd php-intl php-mbstring php-openssl \
php-pear php-xml php-mcrypt php-pdo php-mysqlnd \
php-pecl-xdebug php-pecl-xhprof php-phpunit-PHPUnit
echo 'date.timezone = Asia/Tokyo' >> /etc/php.ini
echo '[xdebug]' >> /etc/php.ini
echo 'xdebug.default_enable = 1' >> /etc/php.ini
echo 'xdebug.remote_autostart = 0' >> /etc/php.ini
echo 'xdebug.remote_connect_back = 1' >> /etc/php.ini
echo 'xdebug.remote_enable = 1' >> /etc/php.ini
echo 'xdebug.remote_handler = dbgp' >> /etc/php.ini
echo 'xdebug.remote_port = 9000' >> /etc/php.ini
#echo 'xdebug.profiler_enable=1' >> /etc/php.ini
echo 'xdebug.profiler_enable_trigger=1' >> /etc/php.ini
echo 'xdebug.profiler_output_dir= /tmp' >> /etc/php.ini
### PHP:Webgrind
#wget https://github.com/jokkedk/webgrind/archive/master.zip && unzip master && mv webgrind-master -T /var/www/vagrant/webgrind
wget https://github.com/jokkedk/webgrind/archive/master.tar.gz && tar xpvf master.tar.gz && mv webgrind-master -T /var/www/vagrant/webgrind

echo '<?php phpinfo(); ?>' > /var/www/vagrant/phpinfo.php
chkconfig httpd on
service httpd start

注釈

mysql をインストールする場合、以下を追加

wget https://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm
rpm -Uvh mysql-community-release-el6*.noarch.rpm
yum -y install mysql-community-server
chkconfig mysqld on
service mysqld start
#mysql_secure_installation