本文参照 具体步骤按照本人实际操作。
本文环境:
Centos 7 + php-fpm + nginx + mcrypt
首先确保Nginx和php-fpm已经安装并且配置好
Nginx配置如下
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
| /etc/nginx/conf.d/default.conf
server {
# 监听端口,默认就是8000
listen 8000;
# 网站域名
server_name www.wecenter.com;
# 网站根目录(我是改成了/home/wwwroot)
root /home/wwwroot;
#root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php; #开启伪静态
}
# 错误页配置
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# php-fpm配置,即对于php后缀的,都是用php-fpm处理
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
#fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
|
PHP配置如下
1
2
| /etc/php.ini
cgi.fix_pathinfo=0
|
php-fpm配置如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| /etc/php-fpm.d/www.conf
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific address on
; a specific port;
; 'port' - to listen on a TCP socket to all addresses on a
; specific port;
; '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
;listen = 127.0.0.1:9000
listen=/var/run/php-fpm/php-fpm.sock
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
; RPM: apache Choosed to be able to access some dir as httpd
;user = apache
user = nginx
; RPM: Keep a group allowed to write in log dir.
;group = apache
group = nginx
|
新建测试文件info.php到目录/home/wwwroot
重启nginx和php-fpm
1
2
3
| sudo systemctl restart php-fpm
sudo systemctl restart nginx.service
sudo systemctl reload nginx.service
|
打开浏览器测试
1
| http://[Your_IP_Address]:8000/info.php
|
然后你就可以看到目前你的PHP相关的所有配置,如果页面没有出来,或者不成功,请对照以上步骤,仔细查阅,看看哪里写的不对。
安装mcrypt库
1
2
| #确认系统是否已经安装了mcrypt
yum list installed|grep mcrypt
|
如果没有安装,请安装。
1
2
| #安装命令
yum install libmcrypt libmcrypt-devel mcrypt mhash
|
安装php的mcrypt扩展(动态加载编译)
下载php下的mcrypt扩展或者直接下载php的完整安装包
http://cn.php.net/releases/ 网页下找到自己服务器的php版本,下载后tar解压(本人的是php5.4.16)
进入ext/mcrypt文件夹
1
2
| tar -xzvf php-5.4.16.tar.gz
[wwwroot@localhost ~]# cd php-5.4.16/ext/mcrypt/
|
执行phpize命令(phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块,如果没有?yum install php53-devel里包含了,或者其他方法)
1
2
3
4
5
6
7
| [wwwroot@localhost mcrypt]# whereis phpize //为了确定phpize存在
phpize: /usr/bin/phpize /usr/share/man/man1/phpize.1.gz
[wwwroot@localhost mcrypt]# phpize
Configuring for:
PHP Api Version: 20090626
Zend Module Api No: 20090626
Zend Extension Api No: 220090626
|
执行完后,会发现当前目录下多了一些configure文件,最后执行php-config命令就基本完成了
执行以下命令,确保你的/usr/bin/php-config是存在的
1
2
3
| [wwwroot@localhost mcrypt]# whereis php-config
php-config: /usr/bin/php-config /usr/share/man/man1/php-config.1.gz
[wwwroot@localhost mcrypt]# ./configure --with-php-config=/usr/bin/php-config
|
如果遇到以下错误(configure: error: no acceptable C compiler found in $PATH),请先安装gcc,
直到不报错,出现:config.status: creating config.h,执行以下命令
1
| [wwwroot@localhost mcrypt]# make && make install
|
最后的最后,会提示你如下,说明你大功告成了
1
| Installing shared extensions: /usr/lib64/php/modules/
|
顺便检查下/usr/lib64/php/modules/里的mrcypt.so扩展是否已经创建成功
然后的事就简单了,给你的php.ini添加一条extension=mcrypt.so
1
2
3
4
5
6
7
8
9
10
11
| extension_dir=/usr/lib64/php/modules
extension=mcrypt.so
service php-fpm restart 重启php
[wwwroot@localhost mcrypt]# cd /etc/php.d
创建一个mrcypt.ini文件就行,里面写extension=mcrypt.so
[wwwroot@localhost php.d]# vim mcrypt.ini
;Enable mcrypt extension module
extension=mcrypt.so
|
检测Mcrypt是否安装成功
1
2
3
4
| http://192.168.10.64:8000/info.php
页面上应该显示
mcrypt support:enabled
mcrypt_filter support:enabled
|