手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Vagrant搭设Ubuntu的LNMP环境

[日期:2015-09-15] 来源:Linux社区  作者:Linux [字体:大 中 小]

安装Vagrant和Virtualbox. 这个不多说, 安装完成两个软件后, 在一个空闲的硬盘分区中

mkdir Ubuntu_lnmp
vagrant init ubuntu/trusty64

打开vagrantfile打开这两个配置

config.vm.network "private_network", ip: “192.168.10.10"

config.vm.provider "virtualbox" do |vb|
  # Display the VirtualBox GUI when booting the machine
  # vb.gui = true

  # Customize the amount of memory on the VM:
  vb.memory = "1024"
end

vagrant up等待安装 vagrant ssh的连接用户名和密码都是vagrant

vagrant环境搞定

sudo apt-get update

安装nginx

sudo apt-get install nginx

安装MySQL请设置密码, 在远程连接时候, 可以使用SSH方式连接, ssh的用户名和密码都是vagrant

sudo apt-get install mysql-server  mysql-client  libmysqlclient-dev

安装Git版本控制

sudo apt-get git

安装PHP以及相关模块

sudo apt-get install php5-fpm php5-mysql php5-cli php5-gd php5-memcache php5-memcached php5-json php5-mcrypt php5-curl php-pear build-essential php5-dev -y
sudo pecl install xdebug -y
sudo php5enmod json
sudo php5enmod mcrypt

删除/usr/share/nginx/html

sudo ln -s /vagrant /usr/share/nginx/html

注意: 这里的 /vagrant 目录其实就是你之前创建的 ubuntu_lnmp 目录, 你在本地修改 ubuntu_lnmp 虚拟机中 /vagrant 目录也会同步

修改/etc/php5/fpm/php.ini

cgi.fix_pathinfo = 0
display_errors = On
date.timezone = PRC

/etc/nginx/sites-available/default 修改

server {
    ...
    //找到index
    index index.php index.html index.htm

    ...
    location ~ \.php {
        #       fastcgi_split_path_info ^(.+\.php)(/.+)$;
        #       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
        #
        #       # With php5-cgi alone:
                fastcgi_pass 127.0.0.1:9000;
        #       # With php5-fpm:
        #       fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
                set $pathinfo "";
                set $real_script_name $fastcgi_script_name;
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                    set $real_script_name $1;
                    set $path_info $2;
                }
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param PATH_INFO $path_info;
    }
}

这样是为了支持PHP的PHPINFO. 其实不是很难理解, fastcgi_param 配置项名称会出现在$_SERVER[配置项名称]中

修改nginx的用户名称

sudo vi /etc/nginx/nginx.conf

找到user www-data; 改为 user vagrant;

修改配置php-fpm配置

sudo vi /etc/php5/fpm/pool.d/www.conf

找到以下配置项目修改

user = vagrant
group = vagrant

;listen = /var/run/php5-fpm.sock 注释掉 改为
listen = 127.0.0.1:9000

listen.owner = vagrant
listen.group = vagrant

我的pm.相关配置

pm.max_children = 1000
pm.start_servers = 25
pm.min_spare_servers = 25
pm.max_spare_servers = 50
pm.max_requests = 1000

为了防止cli和fpm的php.ini不相同, 可以讲cli的php.ini文件删除, 然后ln过去一个

sudo rm -rf /etc/php5/cli/php.ini
ln -s /etc/php5/fpm/php.ini /etc/php5/cli/php.ini

这样修改一个配置文件, 就可以达到两边同步了.

如何使用vagrant在虚拟机安装Hadoop集群 http://www.linuxidc.com/Linux/2013-04/82750.htm

Vagrant 中高效的 Puppet 模块管理 http://www.linuxidc.com/Linux/2014-05/101873.htm

使用 Vagrant 和 Fabric 用于集成测试 http://www.linuxidc.com/Linux/2014-07/104113.htm

使用 Vagrant 搭建开发环境 http://www.linuxidc.com/Linux/2014-07/104116.htm

Windows 下配置 Vagrant 环境 http://www.linuxidc.com/Linux/2014-07/104115.htm

使用 Vagrant 搭建开发环境 http://www.linuxidc.com/Linux/2014-07/104116.htm

通过 Vagrant 搭建虚拟机环境 http://www.linuxidc.com/Linux/2015-08/121985.htm

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-09/123056.htm

linux
相关资讯       LNMP 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款