Mac OSX+VirtualBox +Vagrant +Centos环境配置

### 参考资料

https://webtatic.com/packages/php56/

https://app.vagrantup.com/boxes/search

https://github.com/puphpet/bento

### 版本信息

MacOS Sierra10.12.6

Vagrant 1.9.5

VirtualBox Version: 5.1.22

#### 缘由

之前用的是32位的centos6.4搭建的公司的本地测试环境,但是调试thrift接口过程中有发现PHP的int处理会报内存耗尽,所以觉得使用64位系统重新搭建。

### 新建box

cd ~/vagrant-box/ubox64

vagrant init puphpet/centos65-x64

vagrant up //下载box镜像过程中,可能会断开,多试几次就能下载好了

经过漫长的等待,大概2-3小时,启动完毕

vagrant ssh

### 配置centos6.5

安装 Nginx、Mysql、PHP5.6.31

sudo yum install nginx

sudo chkconfig nginx on

sudo service nginx start

sudo yum install mysql

sudo yum install mysql-server

sudo /etc/init.d/mysqld start

sudo chkconfig mysqld on

sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

sudo rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

sudo yum install php56w php56w-fpm php56w-opcache php56w-gd php56w-mysql php56w-mcrypt 

sudo chkconfig php-fpm on

sudo /etc/rc.d/init.d/php-fpm start

配置Nginx虚拟主机使用php-fpm解析php文件

location ~ \.php$ {

#fastcgi_intercept_errors on;

fastcgi_pass  127.0.0.1:9000;

fastcgi_index index.php;

include fastcgi_params;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

}

### 问题,访问页面时提示500错误

vagrant up 之后 nginx没有开机启动

google之后在stackoverflow有说:

Apparently the problem was due to the vagrant folder not being mounted when Apache tries to start. Although I still don't understand why no error is thrown.

I solved it by creating an Upstart script (on the folder/etc/init) to start the service after vagrant mounts its folder (it emits an event calledvagrant-mounted)

This is the script I used (with the filenamehttpd.confbut I don't think that's necessary).

sudo vi /etc/init/nginx-start.conf 写入

# start apache on vagrant mounted

start on vagrant-mounted

exec sudo service nginx start


查看php-fpm进程发现用户是apache

ps aux | grep php-fpm

root34770.01.0 4123485104 ?Ss07:050:00 php-fpm: master process (/etc/php-fpm.conf)

apache34780.00.9 4123484948 ?S07:050:00 php-fpm: pool www

apache34790.00.9 4123484948 ?S07:050:00 php-fpm: pool www

修改php-fpm的用户名和组名

sudo vi /etc/php-fpm.d/www.conf

sudo /etc/rc.d/init.d/php-fpm restart

### 安装memcached

sudo yum search memcached // 查找包名

sudo yum install memcached

php-fpm -m | grep memcache

安装php的memcache扩展

sudo yum install php56w-pecl-memcache
sudo /etc/rc.d/init.d/php-fpm restart

### 修改主机名

sudo vi /etc/sysconfig/network

sudo vi /etc/hosts

hostname

你可能感兴趣的:(Mac OSX+VirtualBox +Vagrant +Centos环境配置)