Nginx 和 PHP的安装配置
1.安裝PHP(注意系統(tǒng)默認(rèn)安裝了php,要安裝高版本之前最好卸載舊版本,因?yàn)檫@個(gè)原因糾結(jié)了四個(gè)小時(shí))
./configure \ --prefix=/usr/local/php \ --exec-prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \--with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --with-zlib-dir \ --with-mhash \ --with-openssl-dir \ --with-jpeg-dir \ --enable-gd-jis-conv \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip2.安裝完成之后在/usr/local目錄下面生成了兩個(gè)目錄php和fastphp,使用service php-fpm啟動(dòng)的時(shí)候有些配置文件報(bào)錯(cuò),拷貝相應(yīng)的文件到目錄即可
[root@nginx fastphp]# tree . |-- etc | |-- pear.conf | `-- php-fpm.conf `-- var`-- log`-- php-fpm.log3 directories, 3 files3.安裝nginx,不贅述。
4.配置nginx
location / {root /web/htdocs/;index index.php index.html index.htm;}location ~ \.php$ {root /web/htdocs/;index index.php;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}重啟nginx,然后訪問(wèn)10.160.65.44/index.php,在/web/htdocs下面顯示phpinfo。
?============================================================================================
memcache對(duì)于php7的支持不太好,上述安裝完以后php的驗(yàn)證代碼一直無(wú)法運(yùn)行,可能是php7的源碼修改比較大?而且memadmin也無(wú)法使用,因而我重新安裝了php-5.6.28.tar。安裝過(guò)程相同,安裝完成之后編譯安裝memcache-2.2.4。
安裝完成之后memadmin-master.zip,解壓后將其放置在/web/htdocs/目錄修改為mmaster目錄。通過(guò)http://10.160.65.44/mmaster/index.php可以訪問(wèn)管理主頁(yè)面。
? 測(cè)試php頁(yè)面:
<?php $mem = new Memcache; $mem->connect("127.0.0.1",11211) or die("Could not connect"); $version = $mem->getVersion(); echo "Server's version: ".$version."<br/>\n"; $mem->set('testkey','HelloWorld',0,600) or die("Failed to save data at the memcached server"); echo "Store data in the cache (data will expire in 600 seconds)<br/>\n"; $get_result = $mem->get('testkey'); echo "get_result is from memcached server."; ?>訪問(wèn)http://10.160.65.44/test.php,得到下面的結(jié)果,表明php已經(jīng)可以使用memcache了。
Server's version: 1.4.33 Store data in the cache (data will expire in 600 seconds) get_result is from memcached server.配置php的會(huì)話保存在memcache中。
測(cè)試php代碼如下
setsess.php
<?php session_start(); if (!isset($_SESSION['www.MageEdu.com'])){$_SESSION['www.MageEdu.com'] = time(); } print $_SESSION['www.MageEdu.com']; print "<br><br>"; print "Session ID: " . session_id(); ?>showsess.php
<?php session_start(); $memcache_obj = new Memcache; $memcache_obj->connect('192.168.144.44',11211); $mysess=session_id(); var_dump($memcache_obj->get($mysess)); $memcache_obj->close(); ?>
?
轉(zhuǎn)載于:https://www.cnblogs.com/python-study/p/6054750.html
總結(jié)
以上是生活随笔為你收集整理的Nginx 和 PHP的安装配置的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 架构评审方法和思路总结
- 下一篇: 动态规划算法php,php算法学习之动态