centos要安装imagick 首先安装ImageMagick

yum install -y ImageMagick ImageMagick-devel

然后安装imagick

wget http://pecl.php.net/get/imagick-3.4.3.tgz
tar zxvf imagick-3.4.3.tgz
cd imagick-3.4.3
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config
make
make install

安装成功后写入php.ini并重启

/usr/local/php/etc/php.ini
extension=imagick.so

/etc/init.d/php-fpm reload

php-imagick的安装

出现502 bad gateway错误的原因

1.php-fpm进程数不够用
2.Linux内核打开文件数量小
3.脚本执行时间超时
4.缓存设置比较小

网站间歇性出现502,第一反应不是程序的问题,而是nginx服务器的问题,因为这是代理服务器出现的问题,代理服务器并没有安装php 排除第一中情况。

于此想到的是可能是超时,所以我把超时修改了一些
一下是服务器原配置(重点配置)

http部分

server_names_hash_bucket_size 64;
client_header_buffer_size 128k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;

keepalive_timeout 60;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 60;
fastcgi_read_timeout 600;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 128k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;

gzip_buffers 4 128k;

server部分

upstream myweb {
server 10.10.10.1:80 max_fails=3 fail_timeout=30s;
server 10.10.10.2:80 max_fails=3 fail_timeout=30s;
ip_hash;
}

location / {
proxy_pass http://myweb;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_redirect off;
}

Read More →

添加bz2扩展,编译报错:
configure: error: Please reinstall the BZip2 distribution

解决方案:
yum install -y bzip2 bzip2-devel

cd /usr/local/src/php-5.6.31/ext/bz2
/srv/php-5.6.31/bin/phpize
./configure –with-php-config=/srv/php-5.6.31/bin/php-config –with-bz2
make
make install

PHP message: PHP Fatal error: require_once(): Failed opening required ‘/home/www/www.s.com/manage/app/../../app_module/classes/phpqrcode.php’

(include_path=’.:/usr/local/php/lib/php’) in /home/www/www.s.com/manage/index.php on line 11
方法1)在Nginx配置文件中加入

fastcgi_param PHP_VALUE “open_basedir=$document_root:/tmp/:/proc/”;

通常nginx的站点配置文件里用了include fastcgi.conf;,这样的,把这行加在fastcgi.conf里就OK了。
如果某个站点需要单独设置额外的目录,把上面的代码写在include fastcgi.conf;这行下面就OK了,会把fastcgi.conf中的设置覆盖掉。
这种方式的设置需要重启nginx后生效。

方法2)在php.ini中加入:

[HOST=www.s.com]
open_basedir=/home/www/www.s.com:/tmp/:/proc/
[PATH=/home/www/www.s.com]
open_basedir=/home/www/www.s.com:/tmp/:/proc/

这种方式的设置需要重启php-fpm后生效。

方法3)在网站根目录下创建.user.ini并写入:
open_basedir=/home/www/www.s.com:/tmp/:/proc/
这种方式不需要重启nginx或php-fpm服务。安全起见应当取消掉.user.ini文件的写权限。