阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Vagrant搭设Ubuntu的LNMP环境

106次阅读
没有评论

共计 2690 个字符,预计需要花费 7 分钟才能阅读完成。

安装 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

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2690字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中