Press "Enter" to skip to content

标签: php-x64

Centos7安装php7.4.9+redis扩展

本文只讲php的编译及Redis扩展的安装,其他nginx的安装什么都相同方式无非就是配置需要修改一下。

php7.4.9安装包下载:https://www.php.net/downloads.php#v7.4.9

我下载了:https://www.php.net/distributions/php-7.4.9.tar.bz2

解压 tar jzvf php-7.4.9.tar.bz2,并打开php-7.4.9目录,需要安装的扩展自行增减,然后进行编译:

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-fpm-user=www --with-fpm-group=www --with-curl --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --with-xmlrpc --with-xsl --with-zlib --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-zip --disable-fileinfo
进行make时会提示错误:
collect2: error: ld returned 1 exit status
make: *** [sapi/cli/php] Error 1

需要:make ZEND_EXTRA_LIBS=’-liconv’ 进行编译操作

等编译后make install安装完成!

把php-fpm做成系统启动,先复制 php-7.4.9目录下./sapi/fpm/init.d.php-fpm至/etc/init.d/目录下

cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

复制完,执行service php-fpm start 会提示错误:env: /etc/init.d/php-fpm: Permission denied,因为 init.d目录下需要给相应的权限才可执行:

chmod a+x /etc/init.d/php-fpm

执行service php-fpm start 提示:Starting php-fpm done 说明启动成功!

然后第二步安装Redis扩展,下载地址:https://pecl.php.net/package/redis 选择自己适合的扩展,我选择了最新的Redis5.3.1版本

wget https://pecl.php.net/get/redis-5.3.1.tgz
tar zxvf redis-5.3.1.tgz
cd redis-5.3.1
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install

–with-php-config=/usr/local/php/bin/php-config 根据自己安装的位置找到php-config

编辑php.ini文件

vim /usr/local/php/etc/php.ini

找到extension区域,增加:extension=redis.so,然后保存退出

重启php进程 service php-fpm restart

查看php是否已经安装了redis模块:

[root@localhost php-7.4.9]# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
filter
gettext
hash
iconv
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zlib

[Zend Modules]

这里特别注意:–with-config-file-path=/usr/local/php/etc编译PHP是指定目录 php.ini文件,如果非此目录的php.ini文件增加扩展,重启是不会加载扩展。新手要特别注意!!!

写一个php文件:phpinfo.php

<?php
  phpinfo();
?>

找到此配置信息项:

Configuration File (php.ini) Path/usr/local/php/etc
Loaded Configuration File/usr/local/php/etc/php.ini

转载请注明出处!

Leave a Comment

Linux X64下Nginx1.0.4无缝升级到新版本1.3.0版本操作方法[原创]

服务器近一年没有更新Nginx版本了,为了提高性能和稳定,采用了最新的Nginx版本。可以到http://nginx.org/en/download.html 进行下载。升级仅花了几分钟时间就搞定了。
注:以下代码是真实环境直接配置复制进来,可以根据代码从上至下进行操作配置。

[root@kiccleaf leaf]# wget http://nginx.org/download/nginx-1.3.0.tar.gz
[root@kiccleaf leaf]# tar -zxvf nginx-1.3.0.tar.gz
[root@kiccleaf leaf]# cd nginx-1.3.0
#如果需要服务器个性化名称可以修改
[root@kiccleaf nginx-1.3.0]# vi src/core/nginx.h
/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) Nginx, Inc.
 */


#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_


#define nginx_version      1003000
#define NGINX_VERSION      "1.3.0"  #可修改成自己需要的版本
#define NGINX_VER          "Nginx/" NGINX_VERSION #可修改成自己需要服务的名称

#define NGINX_VAR          "NGINX"  #可修改成自己需要服务的名称
#define NGX_OLDPID_EXT     ".oldbin"


#endif /* _NGINX_H_INCLUDED_ */

#进行配置操作,根据自己的实际配置来,以下是我简单的配置

[root@kiccleaf nginx-1.3.0]# ./configure --user=www --group=www --add-module=../ngx_cache_purge-1.3 --prefix=/usr/local/nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
checking for OS
 + Linux 2.6.18-274.12.1.el5 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.1.2 20080704 (Red Hat 4.1.2-51)
…………………………编译代码省略………………
  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
[root@kiccleaf nginx-1.3.0]# make  #看清咯,只make,而不是make install,这里升级不需要install操作
make -f objs/Makefile
make[1]: Entering directory `/home/leaf/nginx-1.3.0'
…………………………编译代码省略………………
make[1]: Leaving directory `/home/leaf/nginx-1.3.0'
make -f objs/Makefile manpage
make[1]: Entering directory `/home/leaf/nginx-1.3.0'
sed -e "s|%%PREFIX%%|/usr/local/nginx|" \
		-e "s|%%PID_PATH%%|/usr/local/nginx/logs/nginx.pid|" \
		-e "s|%%CONF_PATH%%|/usr/local/nginx/conf/nginx.conf|" \
		-e "s|%%ERROR_LOG_PATH%%|/usr/local/nginx/logs/error.log|" \
		< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/leaf/nginx-1.3.0'

检查配置是否正确,这里出现了警告,因为从低版本升级至高版本产生了配置的问题

[root@kiccleaf nginx-1.3.0]# ./objs/nginx -t
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/conf.d/www.kiccleaf.com.conf:22
nginx: [warn] the "log_format" directive may be used only on "http" level in /usr/local/nginx/conf/conf.d/www.qimutian.com.conf:22
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#升级后出现配置文件conf有错误,如果有其的虚拟主机开启了日志,也按要求移出server段放在server段的前面即可。
[root@kiccleaf nginx-1.3.0]# vi /usr/local/nginx/conf/conf.d/www.kiccleaf.com.conf
#把server里面的log_format代码拿到上面来,保存退出
    log_format  www_kiccleaf_com  '$remote_addr - $remote_user [$time_local] "$request" '
             '$status $body_bytes_sent "$http_referer" '
              '"$http_user_agent" $http_x_forwarded_for';
server
{
    listen       80;
    server_name  www.kiccleaf.com;
    index index.html index.htm index.php;
    root  /data/kiccleaf;
    #limit_conn   crawler  20;    
                            
    location ~ .*\.(php|php5)?$
    {      
      fastcgi_pass  127.0.0.1:9000;
      fastcgi_index index.php;
      include fcgi.conf;
    }

#以下代码的问题,升级后需要把以下代码拿到server上面去。这里先注释掉
#    log_format  www_kiccleaf_com  '$remote_addr - $remote_user [$time_local] "$request" '
#             '$status $body_bytes_sent "$http_referer" '
#              '"$http_user_agent" $http_x_forwarded_for';
    access_log  /data/logs/www_kiccleaf_com.log www_kiccleaf_com;

}
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -t  #再检查,没有warn警告信息了
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

操作升级,出错误不管它

[root@kiccleaf nginx-1.3.0]# make upgrade #出现错误,就先不管它
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
cat: /usr/local/nginx/logs/nginx.pid: No such file or directory
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
make: *** [upgrade] Error 1

备份老的Nginx程序,复制新的过去

[root@kiccleaf nginx-1.3.0]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
mv: overwrite `/usr/local/nginx/sbin/nginx.old'? y
[root@kiccleaf nginx-1.3.0]# cp objs/nginx /usr/local/nginx/sbin/nginx
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -t #查看复制过去配置是否正确
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@kiccleaf nginx-1.3.0]# /usr/local/nginx/sbin/nginx -v  #再查看一下新版本,老的是1.0.4版本
nginx version: Nginx/1.3.0  #已经是新版本

无缝升级到新版本

[root@kiccleaf nginx-1.3.0]# kill -USR2 `cat /usr/local/nginx/nginx.pid` #
[root@kiccleaf nginx-1.3.0]# ps aux| grep nginx #查看一下进程
root      2169  0.0  0.0 248708  1788 ?        Ss    2011   0:00 nginx: master process /usr/local/nginx/sbin/nginx  #老的进程都是2011年开启的,嘿嘿
www       6891  0.0  0.3 274308 27796 ?        S    Apr20   0:13 nginx: worker process               
www       6892  0.0  0.3 274308 27616 ?        S    Apr20   0:13 nginx: worker process               
www       6893  0.0  0.3 274308 27596 ?        S    Apr20   0:13 nginx: worker process               
www       6894  0.0  0.3 274308 27612 ?        S    Apr20   0:13 nginx: worker process               
www       6895  0.0  0.3 274308 27608 ?        S    Apr20   0:15 nginx: worker process               
www       6896  0.0  0.3 274308 27796 ?        S    Apr20   0:15 nginx: worker process               
www       6897  0.0  0.3 274308 27700 ?        S    Apr20   0:15 nginx: worker process               
www       6898  0.0  0.3 274308 27600 ?        S    Apr20   0:12 nginx: worker process               
www       6899  0.0  0.3 274308 27592 ?        S    Apr20   0:13 nginx: worker process               
www       6900  0.0  0.3 274308 27620 ?        S    Apr20   0:13 nginx: worker process               
www       6901  0.0  0.3 274308 27616 ?        S    Apr20   0:14 nginx: worker process               
www       6902  0.0  0.3 274308 27652 ?        S    Apr20   0:11 nginx: worker process               
www       6903  0.0  0.3 274308 27856 ?        S    Apr20   0:13 nginx: worker process               
www       6904  0.0  0.3 274308 27608 ?        S    Apr20   0:15 nginx: worker process               
www       6905  0.0  0.3 274308 27644 ?        S    Apr20   0:12 nginx: worker process               
www       6906  0.0  0.3 274308 27612 ?        S    Apr20   0:16 nginx: worker process               
www       6907  0.0  0.0 248708  1500 ?        S    Apr20   0:00 nginx: cache manager process        
root     30293  0.0  0.0 248008  3764 ?        S    22:17   0:00 nginx: master process /usr/local/nginx/sbin/nginx
www      30294  0.0  0.3 273968 27524 ?        S    22:17   0:00 nginx: worker process               
www      30295  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30296  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30297  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30298  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30299  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30300  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30301  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30302  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30303  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30304  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30305  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30306  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30307  0.0  0.3 273936 27392 ?        S    22:17   0:00 nginx: worker process               
www      30308  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30309  0.0  0.3 273608 26784 ?        S    22:17   0:00 nginx: worker process               
www      30310  0.0  0.0 248188  1396 ?        S    22:17   0:00 nginx: cache manager process        
root     30316  0.0  0.0  61172   800 pts/1    S+   22:36   0:00 grep nginx

原来存放nginx.pid的目录下自动出现了nginx.pid.oldbin。现在新的和旧的一起在提供服务,我们执行一下命令把老的进程给Kill掉就可以了。

[root@kiccleaf nginx-1.3.0]# kill -QUIT `cat /usr/local/nginx/nginx.pid.oldbin` 
[root@kiccleaf nginx-1.3.0]# ps aux| grep nginx #现在查看进程只有新的了
root     30293  0.0  0.0 248720  3924 ?        S    22:17   0:00 nginx: master process /usr/local/nginx/sbin/nginx
www      30332  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30333  0.1  0.3 274320 27552 ?        S    22:43   0:00 nginx: worker process               
www      30334  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30335  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30336  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30337  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30338  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30339  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30340  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30341  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30342  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30343  0.1  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30344  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30345  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30346  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30347  0.0  0.3 274320 26944 ?        S    22:43   0:00 nginx: worker process               
www      30348  0.0  0.0 248720  1400 ?        S    22:43   0:00 nginx: cache manager process        
root     30418  0.0  0.0  61172   796 pts/1    S+   22:45   0:00 grep nginx

好了进行访问网站,是不是正常不间断切换至最新的Nginx版本了!

Leave a Comment

Win2008 R2 X64系统中IIS7.5配置PHP及PHP x64位环境[原创]

本文介绍在Win2008 R2 x64下配置PHP环境,网络上找了较多参考,都不是非常详细,有些配置无法成功,特此写下较详细的配置与大家分享。
条件与环境:
系统:Windows Server 2008 R2 Enterprise Edition X64
IIS版本:IIS7.0 / IIS7.5 测试通过
PHP版本:
php-5.2.8-x64.zip(已经测试成功)
php-5.3.8-nts-Win32-VC9-x86.zip(已经测试成功)
官方PHP下载地址:http://windows.php.net/download/

本人已经配置好的php.ini 打包供大家下载
php-5.2.8-x64.zip(已经测试成功后打包)
php-5.3.8-nts-Win32-VC9-x86.zip(已经测试成功后打包)

说明一下:php-x64位的目前本人没找到从官方下载地址,所以安装32位。

前期准备工作:
查看IIS是否已经安装CGI扩展,本人的环境之前安装时未安装CGI扩展,接下去是安装步骤:
1.安装CGI扩展
2.解压PHP包至C盘(也可选择其他盘),分配目录权限
3.配置IIS支持PHP,此文采用IIS7.5配置
4.测试PHP程序

第一步:打开“开始”–“控制面板”–“程序和功能”–“打开或关闭Winodw功能”

查看CGI扩展未安装,选择“添加角色服务”

勾选“CGI”扩展,点下一步进行安装【记得要用到系统安装盘,或是源文件】

查看“CGI”扩展已经安装成功!

第二步,解压下载的PHP压缩包
解压下载好的PHP包,并修改php.ini-recommended为php.ini
打开php.ini,修改

cgi.force_redirect = 0
cgi.fix_pathinfo=1
fastcgi.impersonate = 1;
extension_dir = "C:\php\ext\"
session.save_path = "C:\php\sessiontmp"

#扩展可根据自己需求选择,一般常用的如:
extension=php_curl.dll
extension=php_gd2.dll
extension=php_gettext.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_openssl.dll
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_sockets.dll
extension=php_xmlrpc.dll

配置C盘PHP目录权限 Everyone可读,可执行
配置C盘PHP目录下的C:\php\sessiontmp 目录全部权限

配置好PHP目录后,对PHP进行测试是否php.ini文件配置正确
“开始”–“运行”–输入“cmd”–“cd /php/”转到c盘php下下。输入“php -v”查看配置情况
php-5.2.8-x64配置测试

php-5.3.8-nts-Win32-VC9-x86配置测试

不管哪个php版本以下对IIS配置都一样。

第三步:配置IIS7.5支持PHP
选择主域下“处理程序映射”

添加PHP配置如图所示:

配置完成后,打开“FastCgi设置”

配置PHP“环境变量” PHP_FCGI_MAX_REQUESTS,取值设置为10000

注意:采用x64php可以不用配置程序池,但采用32位的php一定要对相应的站点程序池进行配置
“应用程序池”–找到站点名称相同的程序池如“kiccleaf.com”–“高级设置”如图所示:

全配置完成后,重启IIS。

第四步测试php,命名为test.php

<?php
echo phpinfo();
?>

测试结果如图所示:

Leave a Comment