Centos 7 PHP7环境配置 LNMP

<p>首先更新系统软件</p><p>$ yum update</p><p>安装nginx</p><p>1.安装nginx源</p><pre class="brush:bash;toolbar:false">1. $yumlocalinstallhttp://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm</pre><p>2.安装nginx</p><pre class="brush:bash;toolbar:false">1. $yuminstallnginx</pre><p>3.启动nginx</p><pre class="brush:bash;toolbar:false">1. $servicenginxstart Redirectingto/bin/systemctlstartnginx.service</pre><p>4.访问http://你的ip/</p><p>如果成功安装会出来nginx默认的欢迎界面</p><p>安装MySQL5.7.*</p><p>1.安装mysql源</p><pre class="brush:bash;toolbar:false">1. $yumlocalinstallhttp://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm</pre><p>2.安装mysql</p><pre class="brush:bash;toolbar:false">1. $yuminstallmysql-community-server</pre><p>确认一下mysql的版本,有时可能会提示mysql5.6</p><p>3.安装mysql的开发包,以后会有用</p><pre class="brush:bash;toolbar:false">1. $yuminstallmysql-community-devel</pre><p>4.启动mysql</p><pre class="brush:bash;toolbar:false">1. $servicemysqldstart Redirectingto/bin/systemctlstartmysqld.service</pre><p>5.查看mysql启动状态</p><pre class="brush:bash;toolbar:false">1. $servicemysqldstatus 出现pid</pre><p>证明启动成功</p><p>6.获取mysql默认生成的密码</p><pre class="brush:bash;toolbar:false">1. $grep&#39;temporarypassword&#39;/var/log/mysqld.log 2015-12-05T05:41:09.104758Z1[Note]Atemporarypasswordisgeneratedforroot@localhost:%G1Rgns!dD!v&lt;/str&gt;&lt;/str&gt;</pre><p>加粗的就是生成的密码</p><p>7.换成自己的密码</p><pre class="brush:bash;toolbar:false">1. $mysql-uroot-p Enterpassword:输入上面的密码</pre><p>成功输入后进入一下步,这里你估计会输入 好几次才进去</p><p>8. 更换密码</p><pre class="brush:bash;toolbar:false">1. mysql&gt;ALTERUSER&#39;root&#39;@&#39;localhost&#39;IDENTIFIEDBY&#39;MyNewPass4!&#39;;</pre><p>这个密码一定要足够复杂,不然会不让你改,提示密码不合法;</p><p>9.退出mysql;</p><pre class="brush:bash;toolbar:false">1. mysql&gt;quit;</pre><p>10.用新密码再登录,试一下新密码</p><pre class="brush:bash;toolbar:false">1. $mysql-uroot-p</pre><p>Enter password:输入你的新密码</p><p>11.确认密码正确后,退出mysql;</p><pre class="brush:bash;toolbar:false">1. mysql&gt;quit;</pre><p>编译安装php7.0.0</p><p>1.下载php7源码包</p><pre class="brush:bash;toolbar:false">1. $cd/root&amp;wget-Ophp7.tar.gzhttp://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror</pre><p>2.解压源码包</p><pre class="brush:bash;toolbar:false">1. $tar-xvfphp7.tar.gz 3. 1. $cdphp-7.0.1</pre><p>4.安装php依赖包</p><pre class="brush:bash;toolbar:false">1. $yuminstalllibxml2libxml2-developensslopenssl-develbzip2bzip2-devellibcurllibcurl-devellibjpeglibjpeg-devellibpnglibpng-develfreetypefreetype-develgmpgmp-devellibmcryptlibmcrypt-develreadlinereadline-devellibxsltlibxslt-devel</pre><p>5.编译配置,这一步我们会遇到很多configure error,我们一一解决,基本都是相关软件开发包没有安装导致</p><pre class="brush:bash;toolbar:false">$./configure\ --prefix=/usr/local/php\ --with-config-file-path=/etc\ --enable-fpm\ --with-fpm-user=nginx\ --with-fpm-group=nginx\ --enable-inline-optimization\ --disable-debug\ --disable-rpath\ --enable-shared\ --enable-soap\ --with-libxml-dir\ --with-xmlrpc\ --with-openssl\ --with-mcrypt\ --with-mhash\ --with-pcre-regex\ --with-sqlite3\ --with-zlib\ --enable-bcmath\ --with-iconv\ --with-bz2\ --enable-calendar\ --with-curl\ --with-cdb\ --enable-dom\ --enable-exif\ --enable-fileinfo\ --enable-filter\ --with-pcre-dir\ --enable-ftp\ --with-gd\ --with-openssl-dir\ --with-jpeg-dir\ --with-png-dir\ --with-zlib-dir\ --with-freetype-dir\ --enable-gd-native-ttf\ --enable-gd-jis-conv\ --with-gettext\ --with-gmp\ --with-mhash\ --enable-json\ --enable-mbstring\ --enable-mbregex\ --enable-mbregex-backtrack\ --with-libmbfl\ --with-onig\ --enable-pdo\ --with-mysqli=mysqlnd\ --with-pdo-mysql=mysqlnd\ --with-zlib-dir\ --with-pdo-sqlite\ --with-readline\ --enable-session\ --enable-shmop\ --enable-simplexml\ --enable-sockets\ --enable-sysvmsg\ --enable-sysvsem\ --enable-sysvshm\ --enable-wddx\ --with-libxml-dir\ --with-xsl\ --enable-zip\ --enable-mysqlnd-compression-support\ --with-pear\ --enable-opcache configureerror: 1.configure:error:xml2-confignotfound.Pleasecheckyourlibxml2installation.</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstalllibxml2libxml2-devel 2.configure:error:CannotfindOpenSSL&#39;s&lt;evp.h&gt;</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstallopensslopenssl-devel 3.configure:error:PleasereinstalltheBZip2distribution</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstallbzip2bzip2-devel 4.configure:error:Pleasereinstallthelibcurldistribution-easy.hshouldbein&lt;curl-dir&gt;/include/curl/</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstalllibcurllibcurl-devel 5.Ifconfigurefailstry--with-webp-dir=&lt;DIR&gt;configure:error:jpeglib.hnotfound.</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstalllibjpeglibjpeg-devel 6.Ifconfigurefailstry--with-webp-dir=&lt;DIR&gt; checkingforjpeg_read_headerin-ljpeg...yes configure:error:png.hnotfound.</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstalllibpnglibpng-devel</pre><p>7.If configure fails try --with-webp-dir=&lt;DIR&gt;</p><pre class="brush:bash;toolbar:false">checkingforjpeg_read_headerin-ljpeg...yes checkingforpng_write_imagein-lpng...yes Ifconfigurefailstry--with-xpm-dir=&lt;DIR&gt; configure:error:freetype-confignotfound.</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstallfreetypefreetype-devel 8.configure:error:Unabletolocategmp.h</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstallgmpgmp-devel 9.configure:error:mcrypt.hnotfound.Pleasereinstalllibmcrypt.</pre><p>解决:</p><pre class="brush:bash;toolbar:false">$yuminstalllibmcryptlibmcrypt-devel 10.configure:error:Pleasereinstallreadline-Icannotfindreadline.h</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstallreadlinereadline-devel 11.configure:error:xslt-confignotfound.Pleasereinstallthelibxslt&gt;=1.1.0distribution</pre><p>解决:</p><pre class="brush:bash;toolbar:false">1. $yuminstalllibxsltlibxslt-devel</pre><p>6.编译与安装</p><pre class="brush:bash;toolbar:false">1. $make&amp;&amp;makeinstall</pre><p>这里要make好久,要耐心一下</p><p>7.添加 PHP 命令到环境变量</p><pre class="brush:bash;toolbar:false">1. $vim/etc/profile</pre><p>在末尾加入</p><pre class="brush:bash;toolbar:false">PATH=$PATH:/usr/local/php/bin exportPATH</pre><p>要使改动立即生效执行</p><pre class="brush:bash;toolbar:false">1. $./etc/profile</pre><p>或</p><pre class="brush:bash;toolbar:false">1. $source/etc/profile</pre><p>查看环境变量</p><pre class="brush:bash;toolbar:false">1. $echo$PATH</pre><p>查看php版本</p><pre class="brush:bash;toolbar:false">1. $php-v</pre><p>8.配置php-fpm</p><pre class="brush:bash;toolbar:false">1. $cpphp.ini-production/etc/php.ini 1.2.3. $cp/usr/local/php/etc/php-fpm.conf.default/usr/local/php/etc/php-fpm.conf $cp/usr/local/php/etc/php-fpm.d/www.conf.default/usr/local/php/etc/php-fpm.d/www.conf 1. $cpsapi/fpm/init.d.php-fpm/etc/init.d/php-fpm 1. $chmod+x/etc/init.d/php-fpm</pre><p>9.启动php-fpm</p><pre class="brush:bash;toolbar:false">$/etc/init.d/php-fpmstart</pre><p>配置nginx虚拟机,绑定域名</p><pre class="brush:bash;toolbar:false">$vim/etc/nginx/conf.d/php7.thinkcmf.com.conf</pre><p>这里可以把php7.thinkcmf.com.conf改成自己的域名</p><p>把下面的内容复制到php7.thinkcmf.com.conf里</p><pre class="brush:bash;toolbar:false">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.47.48.49.50.51. server{ listen80; server_namephp7.thinkcmf.com; root/var/www/html/php7.thinkcmf.com;#该项要修改为你准备存放相关网页的路径 location/{ indexindex.phpindex.htmlindex.htm; #如果请求既不是一个文件,也不是一个目录,则执行一下重写规则 if(!-e$request_filename) { #地址作为将参数rewrite到index.php上。 rewrite^/(.*)$/index.php/$1; #若是子目录则使用下面这句,将subdir改成目录名称即可。 #rewrite^/subdir/(.*)$/subdir/index.php/$1; } } #proxythephpscriptstophp-fpm location~\.php{ includefastcgi_params; ##pathinfo支持start #定义变量$path_info,用于存放pathinfo信息 set$path_info&quot;&quot;; #定义变量$real_script_name,用于存放真实地址 set$real_script_name$fastcgi_script_name; #如果地址与引号内的正则表达式匹配 if($fastcgi_script_name~&quot;^(.+?\.php)(/.+)$&quot;){ #将文件地址赋值给变量$real_script_name set$real_script_name$1; #将文件地址后的参数赋值给变量$path_info set$path_info$2; } #配置fastcgi的一些参数 fastcgi_paramSCRIPT_FILENAME$document_root$real_script_name; fastcgi_paramSCRIPT_NAME$real_script_name; fastcgi_paramPATH_INFO$path_info; ###pathinfo支持end fastcgi_intercept_errorson; fastcgi_pass127.0.0.1:9000; } location^~/data/runtime{ return404; } location^~/application{ return404; } location^~/simplewind{ return404; } }</pre><p>2.重启nginx</p><pre class="brush:bash;toolbar:false">1. $servicenginxreload 3. 1. $vim/var/www/html/php7.thinkcmf.com/index.php</pre><p>把下面的代码复制到这个文件 里</p><pre class="brush:php;toolbar:false">&lt;?php phpinfo();</pre>
返回顶部 留言