Press "Enter" to skip to content

标签: php

FreeBSD12安装Nginx1.18+PHP7.4+MariaDB10.4的网站环境

个人很喜欢FreeBSD系统,简单,占用资源少,在网站大并发处理方面性能比Linux要好很多,稳定运行三五年都不用重启,因为之前做广告投放系统,每天大并发300多万,Linux并发一上来压力就大系统就慢下来,搞不好就挂机了,然而FreeBSD安然无恙,所以还有什么理由不选择这么优秀的系统来做大并发服务呢?(当然这里还涉及到很多系统安全及优化操作,等空了再分享给大家,先记录一下基本环境的搭建)

常用的工具
pkg install vim wget screen
编译扩展时用到的
pkg install autoconf

这里需要的扩展就自己选择增加吧,不知道的可以用才下工具查出你想要的扩展吧

pkg search php74

开始NGINX+PHP7.4.9+MARIADB的安装:

pkg install php74 php74-zlib php74-exif php74-gd php74-mbstring php74-xml php74-pdo php74-pdo_mysql php74-pdo_pgsql php74-mysqli php74-curl php74-opcache php74-intl php74-sockets php74-zip php74-openssl php74-bz2 php74-pecl-redis php74-session php74-json php74-dom php74-fileinfo php74-simplexml php74-simplexml php74-pdo_sqlite php74-iconv php74-pecl-imagick-im7 php74-filter php74-phar php74-calendar php74-ctype php74-exif php74-bcmath php74-dba php74-tokenizer php74-extensions php73-zip nginx-full mariadb104-server-10.4.13_4 mariadb104-client-10.4.13_4

开机启动项/etc/rc.conf增加:

php_fpm_enable="yes"
nginx_enable="yes"
mysql_enable="yes"
mysql_pidfile="/var/db/mysql/mysql.pid"
mysql_optfile="/usr/local/etc/my.cnf"

PHP配置/usr/local/etc/php-fpm.d/www.conf

[www]
user = www
group = www

;listen = 127.0.0.1:9000
 (注释掉或删除,添加以下这一行/tmp/php-cgi.sock)
listen = /tmp/php-cgi.sock

开启以下三行
listen.owner = www
listen.group = www
listen.mode = 0660

为什么要用unix:/tmp/php-cgi.sock替代127.0.0.1:9000呢?最主要的就是unix socket比tcp快,所以对大并发的网站优化过后性能提升不少,这一点你GET到了吗?启动php-fpm自动生成/tmp/php-cgi.sock。

对php.ini文件的修改,增加重要的函数进行屏蔽

disable_functions = passthru,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
根据服务器内存大小调整
memory_limit = 128M
上传文件最大5M
upload_max_filesize = 5M

根据需要开启opcache缓存,能提升性能
[opcache]
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=10000
opcache.max_wasted_percentage=5
opcache.validate_timestamps=1
opcache.revalidate_freq=10

validate_timestamps配置项用于验证是否要重新生成缓存脚本, 如果设置为 0(性能最佳),需要手动在每次 PHP 代码更改后手动清除 opcache。除了重启php-fpm的进程可以清理opcache缓存外, 通过PHP函数可以手动清除:

<?php opcache_reset();?>

网络上其他朋友说,当PHP以PHP-FPM的方式运行的时候,opcache的缓存是无法通过php命令进行清除的,只能通过http或cgi到php-fpm进程的方式来清除缓存(此说法本人未验证过)。我配置的生产环境一般都会通过重启php-fpm进程来清除缓存,所以一般一直缓存着高效。

validate_timestamps配置项如果值为 0,那么 revalidate_freq 将失去作用。
revalidate_freq 用于控制 opcache 多久生成一次缓存字节码,这里配置了默认 10s。所以一般我们在开发环境中将上面两个值配置为:

opcache.validate_timestamps=1;
opcache.revalidate_freq=1;

php.net上有人提供的方法存放到 /usr/local/bin/opcache-clear ,需要重置的时候执行一下: “opcache-clear”(仅供参考):

#!/bin/bash
WEBDIR=/var/www/html/
RANDOM_NAME=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 13)
echo "<?php opcache_reset(); ?>" > ${WEBDIR}${RANDOM_NAME}.php
curl http://localhost/${RANDOM_NAME}.php
rm ${WEBDIR}${RANDOM_NAME}.php

PHP开发的针对opcache进行图形化的参考:

https://github.com/rlerdorf/opcache-status

https://github.com/PeeHaa/OpCacheGUI

nginx.conf中修改

# fastcgi_pass 127.0.0.1:9000;

改为:
fastcgi_pass unix:/tmp/php-cgi.sock;

# fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
改为:
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

默认WEB目录:/usr/local/www/nginx-dist 执行PHP可能需要添加相应的执行权限及目录用户归www
保存后重启php-fpm和nginx:

root@kiccleaf:/home # service php-fpm restart
root@kiccleaf:/home # service nginx restart

启动Mysql,正常情况下

root@kiccleaf:/usr/local/etc # service mysql-server start
Installing MariaDB/MySQL system tables in '/var/db/mysql' ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system


Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr/local' ; /usr/local/bin/mysqld_safe --datadir='/var/db/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/local/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Consider joining MariaDB's strong and vibrant community:
Get Involved
Starting mysql.

mysql如果进程中没有看到说明启动失败,可以看错误信息文件:/var/log/mysql/mysqld.err

2020-08-29 22:52:52 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-08-29 22:52:52 0 [Note] InnoDB: Uses event mutexes
2020-08-29 22:52:52 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-08-29 22:52:52 0 [Note] InnoDB: Number of pools: 1
2020-08-29 22:52:52 0 [Note] InnoDB: Using SSE2 crc32 instructions
2020-08-29 22:52:52 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2020-08-29 22:52:52 0 [Note] InnoDB: Completed initialization of buffer pool
2020-08-29 22:52:52 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2020-08-29 22:52:52 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2020-08-29 22:52:52 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2020-08-29 22:52:52 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2020-08-29 22:52:52 0 [Note] InnoDB: Waiting for purge to start
2020-08-29 22:52:52 0 [Note] InnoDB: 10.4.13 started; log sequence number 61026; transaction id 21
2020-08-29 22:52:52 0 [Note] InnoDB: Loading buffer pool(s) from /var/db/mysql/ib_buffer_pool
2020-08-29 22:52:52 0 [Note] InnoDB: Buffer pool(s) load completed at 200829 22:52:52
2020-08-29 22:52:52 0 [Note] Plugin 'FEEDBACK' is disabled.
2020-08-29 22:52:52 0 [Note] Server socket created on IP: '127.0.0.1'.
2020-08-29 22:52:52 0 [ERROR] Can't start server : Bind on unix socket: Permission denied
2020-08-29 22:52:52 0 [ERROR] Do you already have another mysqld server running on socket: /var/run/mysql/mysql.sock ?
2020-08-29 22:52:52 0 [ERROR] Aborting

关键的错误信息已经提示:Can’t start server : Bind on unix socket: Permission denied 和Do you already have another mysqld server running on socket: /var/run/mysql/mysql.sock ?启动权限有关,需要找到启动:/var/run/mysql目录 权限:root wheel需要修改成mysql用户权限,然后重启mysql就成功了。

原目录权限
drwxr-xr-x  2 root  wheel      512 Aug 29 22:09 mysql/

变更目录所有者权限
root@kiccleaf:/var/run # chown -R mysql:mysql mysql/

运行mysql
root@kiccleaf:/var/run # service mysql-server start
Starting mysql.
查看一下mysql目录下是否生成了mysql.sock文件
root@kiccleaf:/var/run # ll mysql/
total 0
srwxrwxrwx  1 mysql  mysql  0 Aug 29 23:03 mysql.sock=
查看进程是否已经启动,找到mysqld_safe 
root@kiccleaf:/var/run # ps aux
mysql 1092   0.0  0.0  11988  2976  -  Ss   23:03     0:00.99 /bin/sh /usr/local/bin/mysqld_safe --defaults-extra-file=/usr/local/etc/my.cnf --user=mysql

接下去初始mysql操作

root@kiccleaf:/var/run # /usr/local/bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

#输入mysql的root密码。默认没有,直接回车
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

#是否切换到unix套接字身份验证[Y/n]
Switch to unix_socket authentication [Y/n] n
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

#是否设置root密码,选Y,输入2次需要设定的密码
Change the root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

#是否删除匿名用户?果断删除
Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

#是否不允许远程root登录,正式环境下应该选择Y,我是在测试环境需要连接。
Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

#是否删除test数据库
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

#是否加载权限使之生效
Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

在默认的WEB目录下/usr/local/www/nginx-dist创建index.php内容:

<?php
phpinfo();
?>

打开浏览器,输入http://IP地址/index.php,可以看到成功的页面了。到此FreeBSD12系统下的基础配置已经完成。

Leave a Comment

PHP短连接生成算法

看到一朋友写的PHP短连接生成的算法,拿来修改一下原文件地址:https://www.cnblogs.com/zemliu/archive/2012/09/24/2700661.html

<?php
    #短连接生成算法

    class Short_Url {
        #字符表
        public static $charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        public static function short($url) {
            $key = "alexis";
            $urlhash = md5($key . $url);
            $len = strlen($urlhash);
            #将加密后的串分成4段,每段4字节,对每段进行计算,一共可以生成四组短连接
            for ($i = 0; $i < 4; $i++) {
                $urlhash_piece = substr($urlhash, $i * $len / 4, $len / 4);
                #将分段的位与0x3fffffff做位与,0x3fffffff表示二进制数的30个1,即30位以后的加密串都归零
                $hex = hexdec($urlhash_piece) & 0x3fffffff; #此处需要用到hexdec()将16进制字符串转为10进制数值型,否则运算会不正常

                $short_url = "http://t.cn/";
                #生成6位短连接
                for ($j = 0; $j < 6; $j++) {
                    #将得到的值与0x0000003d,3d为61,即charset的坐标最大值
                    $short_url .= self::$charset[$hex & 0x0000003d];
                    #循环完以后将hex右移5位
                    $hex = $hex >> 5;
                }
                $short_url_list[] = $short_url;
            }
            return $short_url_list;
        }
    }
    $url = "http://www.cnblogs.com/zemliu/";
    $short = Short_Url::short($url);
    print_r($short);
?>
[root@kiccleaf ~]# php shorturl.php 
Array
(
    [0] => http://t.cn/KyfLyH
    [1] => http://t.cn/bPafHS
    [2] => http://t.cn/H880aD
    [3] => http://t.cn/TmvDK0
)

生成的短url存到服务器里,做一个映射,short_url => original_url,输入短url的时候按照映射转回长url,然后访问原始url即可,原作者输出了四组短网址。

其实在实际应用中只需要一个就够了,简单的修改如下:

<?php
    #短连接生成算法

    class Short_Url {
        #字符表
        public static $charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        public static function short($url) {
            $key = "alexis";
            $urlhash = md5($key . $url);
            $len = strlen($urlhash);
               $urlhash_piece = substr($urlhash, 1 * $len / 4, $len / 4);
                #将分段的位与0x3fffffff做位与,0x3fffffff表示二进制数的30个1,即30位以后的加密串都归零
                $hex = hexdec($urlhash_piece) & 0x3fffffff;
                #此处需要用到hexdec()将16进制字符串转为10进制数值型,否则运算会不正常
                $short_url = "http://t.cn/";
                #生成6位短连接
                for ($j = 0; $j < 6; $j++) {
                    #将得到的值与0x0000003d,3d为61,即charset的坐标最大值
                    $short_url .= self::$charset[$hex & 0x0000003d];
                    #循环完以后将hex右移5位
                    $hex = $hex >> 5;
                }
            return $short_url;
        }
    }

    $url = "http://www.cnblogs.com/zemliu/";
    $short = Short_Url::short($url);
    print_r($short);
?>

输出单个短网址,进行保存

[root@kiccleaf ~]# php shorturl1.php 
http://t.cn/KyfLyH
Leave a Comment

CentOS8安装PHP8

最新系统上来了这大半年都没有时间安装用用,php-8.0.0beta2 也发布出来了,先记录一下,CentOS8安装选择最小安装(跟原来安装差不多没变化),所以安装速度很快,因为是最小安装所以有些工具没有,能少则少的原则

简单说一下yum源修改

先安装wget工具:

yum install -y wget
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

或者用

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
yum makecache 生成缓存

系统缺少命令ifconfig,netstat,whois等命令需要安装net-tools.x86_64,另外习惯使用vim编辑器,所以每次都会安装,常用的screen也是要安装的,但在CentOS8系统下直接yum install screen是安装失败的

[root@kiccleaf ~]# yum install screen
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository PowerTools is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Last metadata expiration check: 0:01:32 ago on Tue 25 Aug 2020 02:16:39 PM CST.
No match for argument: screen
Error: Unable to find a match: screen
办法总是有的,先安装epel-release
[root@kiccleaf ~]# yum install -y epel-release
Installed:
  epel-release-8-8.el8.noarch                                                                                                                                                                                                               

Complete!
[root@kiccleaf ~]# yum install -y screen
Installed:
  screen-4.6.2-10.el8.x86_64                                                                                                                                                                                                                

Complete!
[root@kiccleaf ~]# 
安装成功了!测试一下
[root@kiccleaf ~]# screen -S kiccleaf
新的窗体里面了
[root@kiccleaf ~]#
Ctrl+ad  临时退出窗体
[detached from 35676.kiccleaf]

重新进入刚才的窗体
[root@kiccleaf ~]# screen -r kiccleaf
退出窗体
[root@kiccleaf ~]# exit
exit
[screen is terminating]
到此完美使用screen工具了。
接下去安装vim和网络命令
[root@kiccleaf ~]# yum install -y net-tools.x86_64 vim 
来看一下系统的版本吧
[root@kiccleaf ~]# cat /etc/redhat-release 
CentOS Linux release 8.2.2004 (Core) 
[root@kiccleaf ~]# 

先下载PHP8源码包,下载网址:https://downloads.php.net/~pollita/

[root@kiccleaf ]# wget https://downloads.php.net/~pollita/php-8.0.0beta2.tar.gz
[root@kiccleaf ]# tar zxvf php-8.0.0beta2.tar.gz
[root@kiccleaf ]# cd php-8.0.0beta2
根据自己的需求进行配置安装相应的扩展
[root@kiccleaf php-8.0.0beta2]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --enable-static --enable-sockets --with-zip --enable-calendar --enable-bcmath --enable-mbstring --with-zlib --with-iconv=/usr/local/libiconv --enable-gd --enable-mbstring --with-curl --with-freetype --disable-ipv6 --disable-debug --with-openssl --enable-intl --enable-opcache

[root@kiccleaf php-8.0.0beta2]# make 
[root@kiccleaf php-8.0.0beta2]# make install

在执行中可能会遇到一些问题,这里简单说明一下:

1. configure: error: iconv does not support errno

[root@kiccleaf ]# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz
[root@kiccleaf ]# tar zxvf libiconv-1.15.tar.gz
[root@kiccleaf libiconv-1.15]#  cd libiconv-1.15
[root@kiccleaf libiconv-1.15]# ./configure --prefix=/usr/local/libiconv
[root@kiccleaf libiconv-1.15]#  make 
[root@kiccleaf libiconv-1.15]#  make install
安装好PHP8后配置进行启动
[root@kiccleaf php-8.0.0beta2]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@kiccleaf php-8.0.0beta2]# chmod a+x /etc/init.d/php-fpm
[root@kiccleaf php-8.0.0beta2]# service php-fpm start
[root@kiccleaf php-8.0.0beta2]# php -v
PHP 8.0.0beta2 (cli) (built: Aug 24 2020 13:47:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
Leave a Comment

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

php编译中遇到error解决办法![转]

在编译php的过程中,经常会出现一些错误信息,网络上搜索了一下还是比较有用的,收藏一下!

1) Configure: error: xml2-config not found. Please check your libxml2 installation.
Solutions :
Quote:
#yum install libxml2 libxml2-devel (For Redhat & Fedora)
# aptitude install libxml2-dev      (For ubuntu)

2) Checking for pkg-config… /usr/bin/pkg-config 
configure: error: Cannot find OpenSSL’s <evp.h>
Solutions :
Quote:
#yum install openssl openssl-devel

3) Configure: error: Please reinstall the BZip2 distribution
Solutions :
Quote:
# yum install bzip2 bzip2-devel

4) Configure: error: Please reinstall the libcurl distribution - 
easy.h should be in <curl-dir>/include/curl/
Solutions :
Quote:
# yum install curl curl-devel   (For Redhat & Fedora)
# install libcurl4-gnutls-dev    (For Ubuntu) 

5) Configure: error: libjpeg.(also) not found.
Solutions :
Quote:
# yum install libjpeg libjpeg-devel

6) Configure: error: libpng.(also) not found.
Solutions :
Quote:
# yum install libpng libpng-devel

7) Configure: error: freetype.h not found. 
Solutions :
Quote:
#yum install freetype-devel

8) Configure: error: Unable to locate gmp.h
Solutions :
Quote:
# yum install gmp-devel

9) Configure: error: Cannot find MySQL header files under /usr. 
Note that the MySQL client library is not bundled anymore!
Solutions :
Quote:
# yum install mysql-devel            (For Redhat & Fedora)
# apt-get install libmysql++-dev      (For Ubuntu) 

10) Configure: error: Please reinstall the ncurses distribution
Solutions :
Quote:
# yum install ncurses ncurses-devel

11) Checking for unixODBC support… configure: error: ODBC header file ‘/usr/include/sqlext.h’ not found!
Solutions :
Quote:
# yum install unixODBC-devel

12) Configure: error: Cannot find pspell
Solutions :
Quote:
# yum install pspell-devel

13) configure: error: mcrypt.h not found. Please reinstall libmcrypt.
Solutions :
Quote:
# yum install libmcrypt libmcrypt-devel    (For Redhat & Fedora)
# apt-get install libmcrypt-dev 

14) Configure: error: snmp.h not found. Check your SNMP installation.
Solutions :
Quote:
# yum install net-snmp net-snmp-devel

15)configure: error: Please reinstall libmhash – I cannot find mhash.h
#yum install mhash-devel
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