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-zip
2.安装完成之后在/usr/local目录下面生成了两个目录php和fastphp,使用service php-fpm启动的时候有些配置文件报错,拷贝相应的文件到目录即可
[root@nginx fastphp]# tree . |-- etc | |-- pear.conf | `-- php-fpm.conf `-- var `-- log `-- php-fpm.log 3 directories, 3 files
3.安装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/> "; $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/> "; $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(); ?>