php5.3.10的安装
下面以最新的php-5.3.10为例进行安装。
1wget http://cn.php.net/distributions/php-5.3.10.tar.gz
2tar -zxvf php-5.3.10.tar.gz
3cd php-5.3.10
4./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
上面的具体参数可以使用./configure –help查看
1make ZEND_EXTRA_LIBS='-liconv'
2make test
3make && make install (此处最好分开做,因为make的时候会有报错出现。)
我在上面的make时就报了下面的错误
1root/source/php-5.3.10/sapi/cli/php: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
2make: *** [ext/phar/phar.php] Error 127
解决办法是(我的mysql安装目录是/usr/local/msyql,这个视自己的mysql安装路径而定。)
1ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/
264位系统应使用下面的这行
3ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
若报下面的错,就是在编绎mysql的时候没有加上mysqli这一项,把下面标红的那部分取消掉,重新编绎就行了。
1make: *** [ext/mysqli/mysqli.lo] Error 1
2./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
另外,也有报下面错的可能。该问题有可能是没有安装iconv这个编码转换的包,也有可以装了,但是仍有这个错。
1sapi/cli/php: error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
2make[1]: *** [install-pear-installer] Error 127
3make: *** [install-pear] Error 2
find / -name libiconv.so.2在/usr/lib/libiconv.so.2位置发现libiconv已经安装。
于是运行/sbin/ldconfig,再重新编译,不再报上面的错。ldconfig用于加载最新编绎过的包。
注:上面很多需要的包我都是通过通过./configure –prefix=/usr –libdir=/usr/lib –sysconfdir=/etc参数编绎。这样其在默认的目录就能找到该包了。
1cp php.ini-production /usr/local/php/etc/php.ini
2cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
3cp sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
修改php.ini文件和php-fpm文件中参数,可以手动更改也可以用下面的sed命令更改
1sed -i 's#short_open_tag = Off#short_open_tag = On#g' /usr/local/php/etc/php.ini
2sed -i 's#;pid = run/php-fpm.pid#pid = run/php-fpm.pid#g' /usr/local/php/etc/php-fpm.conf
3sed -i 's#pm.max_children = 5#pm.max_children = 32#g' /usr/local/php/etc/php-fpm.conf
4sed -i 's#pm.start_servers = 2#pm.start_servers = 16#g' /usr/local/php/etc/php-fpm.conf
5sed -i 's#pm.min_spare_servers = 1#pm.min_spare_servers = 8#g' /usr/local/php/etc/php-fpm.conf
6sed -i 's#pm.max_spare_servers = 3#pm.max_spare_servers = 32#g' /usr/local/php/etc/php-fpm.conf
7sed -i 's#;pm.max_requests = 500#pm.max_requests = 120#g' /usr/local/php/etc/php-fpm.conf
关于php-fpm几个重要参数的调整方面具体可以参看我的另一篇日志:https://blog.361way.com/php-fpm/890.html 另外php官方也给出了其中所有参数项的解释说明,具体见http://www.php.net/manual/en/install.fpm.configuration.php
设置开机启动
1chmod 755 /etc/init.d/php-fpm
2chkconfig --add php-fpm
3/etc/init.d/php-fpm start
至此,php的安装完毕。
最后可以再安装一些php的扩展包和开户php加速(具体软件包可以视网上的最新版进行安装):
1tar zxvf memcache-2.2.5.tgz
2cd memcache-2.2.5/
3/usr/local/php/bin/phpize
4./configure --with-php-config=/usr/local/php/bin/php-config
5make
6make install
7cd ../
8
9tar jxvf eaccelerator-0.9.6.1.tar.bz2
10cd eaccelerator-0.9.6.1/
11/usr/local//php/bin/phpize
12./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config
13make
14make install
15cd ../
16
17tar zxvf PDO_MYSQL-1.0.2.tgz
18cd PDO_MYSQL-1.0.2/
19/usr/local/php/bin/phpize
20./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
21make
22make install
23cd ../
24
25tar zxvf ImageMagick.tar.gz
26cd ImageMagick-6.5.1-2/
27./configure
28make
29make install
30cd ../
31
32tar zxvf imagick-2.3.0.tgz
33cd imagick-2.3.0/
34/usr/local/php/bin/phpize
35./configure --with-php-config=/usr/local/php/bin/php-config
36make
37make install
38cd ../
修改php.ini文件
手工修改:查找/usr/local/php/etc/php.ini中的extension_dir = “./”
修改为extension_dir = “/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/”
并在此行后增加以下几行,然后保存:
extension = “memcache.so”
extension = “pdo_mysql.so”
extension = “imagick.so”
再查找output_buffering = Off
修改为output_buffering = On
再查找; cgi.fix_pathinfo=0
修改为cgi.fix_pathinfo=0,防止Nginx文件类型错误解析漏洞。
配置eAccelerator加速PHP:
1mkdir -p /opt/webserver/eaccelerator_cache
2vi /usr/local/php/etc/php.ini
在php.ini配置文件的最末尾,加上以下配置信息:
1[eaccelerator]
2zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so"
3eaccelerator.shm_size="64"
4eaccelerator.cache_dir="/opt/webserver/eaccelerator_cache"
5eaccelerator.enable="1"
6eaccelerator.optimizer="1"
7eaccelerator.check_mtime="1"
8eaccelerator.debug="0"
9eaccelerator.filter=""
10eaccelerator.shm_max="0"
11eaccelerator.shm_ttl="3600"
12eaccelerator.shm_prune_period="3600"
13eaccelerator.shm_only="0"
14eaccelerator.compress="1"
15eaccelerator.compress_level="9"
php的安全性设置:
1找到:;open_basedir =
2修改为:open_basedir = .:/tmp/ #防止php木马跨站,重要!!
3找到:disable_functions =
4修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
5#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
6找到:;date.timezone =
7修改为:date.timezone = PRC
8找到:expose_php = On
9修改为:expose_php = OFF #禁止显示php版本的信息
10找到:display_errors = On
11修改为:display_errors = OFF #关闭错误提示
本文中其实关于加速的部分是错误的,因为当时我测试时,只是把php安装好以后,后面的eaccelerator加速部分是直接复制的原来的安装部分,并未进行测试,后来因为生产环境的需要,进行安装时,发现eaccelerator不支持最新的php5.3.10。于是换成更新速度最快的xcache发现支持。
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/php-install/888.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.