Nginx 和 PHP的安装配置
1.安裝PHP(注意系統默認安裝了php,要安裝高版本之前最好卸載舊版本,因為這個原因糾結了四個小時)
./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目錄下面生成了兩個目錄php和fastphp,使用service php-fpm啟動的時候有些配置文件報錯,拷貝相應的文件到目錄即可
[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,然后訪問10.160.65.44/index.php,在/web/htdocs下面顯示phpinfo。
?============================================================================================
memcache對于php7的支持不太好,上述安裝完以后php的驗證代碼一直無法運行,可能是php7的源碼修改比較大?而且memadmin也無法使用,因而我重新安裝了php-5.6.28.tar。安裝過程相同,安裝完成之后編譯安裝memcache-2.2.4。
安裝完成之后memadmin-master.zip,解壓后將其放置在/web/htdocs/目錄修改為mmaster目錄。通過http://10.160.65.44/mmaster/index.php可以訪問管理主頁面。
? 測試php頁面:
<?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."; ?>訪問http://10.160.65.44/test.php,得到下面的結果,表明php已經可以使用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的會話保存在memcache中。
測試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(); ?>
?
轉載于:https://www.cnblogs.com/python-study/p/6054750.html
總結
以上是生活随笔為你收集整理的Nginx 和 PHP的安装配置的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 架构评审方法和思路总结
- 下一篇: 安全与隐私没有允许任何来源选项