Vagrant搭建LNMP环境
Vagrant搭建LNMP环境
安装Vagrant和Virtualbox. 这个不多说, 安装完成两个软件后, 在一个空闲的硬盘分区中
<span class="pln">mkdir Ubuntu_lnmp</span>
<span class="pln">vagrant init ubuntu</span><span class="pun">/</span><span class="pln">trusty64</span>
打开vagrantfile打开这两个配置
<span class="pln">config</span><span class="pun">.</span><span class="pln">vm</span><span class="pun">.</span><span class="pln">network </span><span class="str">"private_network"</span><span class="pun">,</span><span class="pln"> ip</span><span class="pun">:</span><span class="pun">“</span><span class="lit">192.168</span><span class="pun">.</span><span class="lit">10.10</span><span class="str">"</span>
<span class="str">config.vm.provider "</span><span class="pln">virtualbox</span><span class="str">" do |vb|</span>
<span class="str"># Display the VirtualBox GUI when booting the machine</span>
<span class="str"># vb.gui = true</span>
<span class="str"># Customize the amount of memory on the VM:</span>
<span class="str">vb.memory = "</span><span class="lit">1024</span><span class="str">"</span>
<span class="str">end</span>
vagrant up等待安装 vagrant ssh的连接用户名和密码都是vagrant
vagrant环境搞定
<span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> update</span>
安装nginx
<span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install nginx</span>
安装Mysql请设置密码, 在远程连接时候, 可以使用SSH方式连接, ssh的用户名和密码都是vagrant
<span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install mysql</span><span class="pun">-</span><span class="pln">server mysql</span><span class="pun">-</span><span class="pln">client libmysqlclient</span><span class="pun">-</span><span class="pln">dev</span>
安装Git版本控制
<span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> git</span>
安装PHP以及相关模块
<span class="pln">sudo apt</span><span class="pun">-</span><span class="kwd">get</span><span class="pln"> install php5</span><span class="pun">-</span><span class="pln">fpm php5</span><span class="pun">-</span><span class="pln">mysql php5</span><span class="pun">-</span><span class="pln">cli php5</span><span class="pun">-</span><span class="pln">gd php5</span><span class="pun">-</span><span class="pln">memcache php5</span><span class="pun">-</span><span class="pln">memcached php5</span><span class="pun">-</span><span class="pln">json php5</span><span class="pun">-</span><span class="pln">mcrypt php5</span><span class="pun">-</span><span class="pln">curl php</span><span class="pun">-</span><span class="pln">pear build</span><span class="pun">-</span><span class="pln">essential php5</span><span class="pun">-</span><span class="pln">dev </span><span class="pun">-</span><span class="pln">y</span>
<span class="pln">sudo pecl install xdebug </span><span class="pun">-</span><span class="pln">y</span>
<span class="pln">sudo php5enmod json</span>
<span class="pln">sudo php5enmod mcrypt</span>
删除/usr/share/nginx/html
<span class="pln">sudo ln </span><span class="pun">-</span><span class="pln">s </span><span class="pun">/</span><span class="pln">vagrant </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">share</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">html</span>
注意: 这里的 /vagrant 目录其实就是你之前创建的 ubuntu_lnmp 目录, 你在本地修改 ubuntu_lnmp 虚拟机中 /vagrant 目录也会同步
修改/etc/php5/fpm/php.ini
<span class="pln">cgi</span><span class="pun">.</span><span class="pln">fix_pathinfo </span><span class="pun">=</span><span class="lit">1</span>
<span class="pln">display_errors </span><span class="pun">=</span><span class="typ">On</span>
<span class="pln">date</span><span class="pun">.</span><span class="pln">timezone </span><span class="pun">=</span><span class="pln"> PRC</span>
<span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">sites</span><span class="pun">-</span><span class="pln">available</span><span class="pun">/</span><span class="kwd">default</span>
修改
<span class="pln">server </span><span class="pun">{</span>
<span class="pun">...</span>
<span class="com">//找到index</span>
<span class="pln">index index</span><span class="pun">.</span><span class="pln">php index</span><span class="pun">.</span><span class="pln">html index</span><span class="pun">.</span><span class="pln">htm</span>
<span class="pun">...</span>
<span class="pln">location </span><span class="pun">~</span><span class="pln"> \.php </span><span class="pun">{</span>
<span class="com"># fastcgi_split_path_info ^(.+\.php)(/.+)$;</span>
<span class="com"># # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini</span>
<span class="com">#</span>
<span class="com"># # With php5-cgi alone:</span>
<span class="pln">fastcgi_pass </span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">:</span><span class="lit">9000</span><span class="pun">;</span>
<span class="com"># # With php5-fpm:</span>
<span class="com"># fastcgi_pass unix:/var/run/php5-fpm.sock;</span>
<span class="pln">fastcgi_index index</span><span class="pun">.</span><span class="pln">php</span><span class="pun">;</span>
<span class="pln">include fastcgi_params</span><span class="pun">;</span>
<span class="kwd">set</span><span class="pln"> $path_info </span><span class="str">""</span><span class="pun">;</span>
<span class="kwd">set</span><span class="pln"> $real_script_name $fastcgi_script_name</span><span class="pun">;</span>
<span class="kwd">if</span><span class="pun">(</span><span class="pln">$fastcgi_script_name </span><span class="pun">~</span><span class="str">"^(.+?\.php)(/.+)$"</span><span class="pun">)</span><span class="pun">{</span>
<span class="kwd">set</span><span class="pln"> $real_script_name $1</span><span class="pun">;</span>
<span class="kwd">set</span><span class="pln"> $path_info $2</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pln">fastcgi_param SCRIPT_FILENAME $document_root$real_script_name</span><span class="pun">;</span>
<span class="pln">fastcgi_param SCRIPT_NAME $real_script_name</span><span class="pun">;</span>
<span class="pln">fastcgi_param PATH_INFO $path_info</span><span class="pun">;</span>
<span class="pun">}</span>
<span class="pun">}</span>
这样是为了支持PHP的PHPINFO. 其实不是很难理解, fastcgi_param 配置项名称会出现在$_SERVER[配置项名称]中
修改nginx的用户名称
<span class="pln">sudo vi </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">/</span><span class="pln">nginx</span><span class="pun">.</span><span class="pln">conf</span>
找到user www-data; 改为 user vagrant;
修改配置php-fpm配置
<span class="pln">sudo vi </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php5</span><span class="pun">/</span><span class="pln">fpm</span><span class="pun">/</span><span class="pln">pool</span><span class="pun">.</span><span class="pln">d</span><span class="pun">/</span><span class="pln">www</span><span class="pun">.</span><span class="pln">conf</span>
找到以下配置项目修改
<span class="pln">user </span><span class="pun">=</span><span class="pln"> vagrant</span>
<span class="kwd">group</span><span class="pun">=</span><span class="pln"> vagrant</span>
<span class="pun">;</span><span class="pln">listen </span><span class="pun">=</span><span class="str">/var/</span><span class="pln">run</span><span class="pun">/</span><span class="pln">php5</span><span class="pun">-</span><span class="pln">fpm</span><span class="pun">.</span><span class="pln">sock </span><span class="pun">注释掉</span><span class="pun">改为</span>
<span class="pln">listen </span><span class="pun">=</span><span class="lit">127.0</span><span class="pun">.</span><span class="lit">0.1</span><span class="pun">:</span><span class="lit">9000</span>
<span class="pln">listen</span><span class="pun">.</span><span class="pln">owner </span><span class="pun">=</span><span class="pln"> vagrant</span>
<span class="pln">listen</span><span class="pun">.</span><span class="kwd">group</span><span class="pun">=</span><span class="pln"> vagrant</span>
我的pm.相关配置
<span class="pln">pm</span><span class="pun">.</span><span class="pln">max_children </span><span class="pun">=</span><span class="lit">1000</span>
<span class="pln">pm</span><span class="pun">.</span><span class="pln">start_servers </span><span class="pun">=</span><span class="lit">25</span>
<span class="pln">pm</span><span class="pun">.</span><span class="pln">min_spare_servers </span><span class="pun">=</span><span class="lit">25</span>
<span class="pln">pm</span><span class="pun">.</span><span class="pln">max_spare_servers </span><span class="pun">=</span><span class="lit">50</span>
<span class="pln">pm</span><span class="pun">.</span><span class="pln">max_requests </span><span class="pun">=</span><span class="lit">1000</span>
为了防止cli和fpm的php.ini不相同, 可以讲cli的php.ini文件删除, 然后ln过去一个
<span class="pln">sudo cp </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php5</span><span class="pun">/</span><span class="pln">fpm</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">php5</span><span class="pun">/</span><span class="pln">cli</span><span class="pun">/</span><span class="pln">php</span><span class="pun">.</span><span class="pln">ini</span>
这样修改一个配置文件, 就可以达到两边同步了。
下面关于LNMP(Linux+Nginx+MySQL+PHP)的文章您也可能喜欢,不妨看看:
相关推荐
Normalizer 2020-06-16
Wyt00 2020-05-30
kingpin 2020-05-16
Normalizer 2020-05-14
独行者0 2020-05-10
xsgnzb 2020-05-05
wxtyixiao 2020-05-05
CCoder 2020-04-10
xsgnzb 2020-03-09
wxtyixiao 2020-01-24
Normalizer 2020-01-14
RLanffy 2020-01-14
xsgnzb 2020-01-01
LiHansiyuan 2020-01-03
空之轨迹约修亚 2019-12-25
yuxeaotao 2019-11-17
ScaredParadise 2019-11-09
ScaredParadise 2019-11-08