本文目录一览:
centos6.5怎么安装php5.5
1.******已安装Nginx******
ps -aux | grep nginx
netstat -anptu | grep 80
2.清除系统中php痕迹:
yum remove php
rm -rvf /etc/php
rm -rvf /etc/php.ini
rm -f /usr/bin/php
3.安装php所需软件包:
tar zxvf autoconf-2.68.tar.gz -C /usr/src
cd /usr/src/autoconf-2.68/
./configure make make install
tar zxvf libiconv-1.14.tar.gz -C /usr/src
cd /usr/src/libiconv-1.14/
./configure make make install
tar zxvf libmcrypt-2.5.8.tar.gz -C /usr/src
cd /usr/src/libmcrypt-2.5.8/
./configure make make install
ldconfig
cd libltdl/
./configure --enable-ltdl-install
make make install
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
tar zxvf mhash-0.9.9.9.tar.gz -C /usr/src
cd /usr/src/mhash-0.9.9.9/
./configure make make install
tar zxvf mcrypt-2.6.8.tar.gz -C /usr/src
cd /usr/src/mcrypt-2.6.8/
./configure make make install
4.加载php动态模块:
ln -s /usr/local/lib/libmcrypt.la /usr/lib64/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib64/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8
/usr/lib64/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib64/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib64/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib64/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib64/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1
/usr/lib64/libmhash.so.2.0.1
cp -R /usr/lib64/libpng.* /usr/lib/
cp -R /usr/lib64/libjpeg.* /usr/lib/
echo "/lib" /etc/ld.so.conf
echo "/usr/lib" /etc/ld.so.conf
echo "/usr/lib64" /etc/ld.so.conf
echo "/usr/local/lib" /etc/ld.so.conf
echo "* soft nproc 65535" /etc/security/limits.conf
echo "* hard nproc 65535" /etc/security/limits.conf
echo "* soft nofile 65535" /etc/security/limits.conf
echo "* hard nofile 65535" /etc/security/limits.conf
echo "fs.file-max=65535" /etc/sysctl.conf
ldconfig
5.解压、配置、编译、安装php:
tar zxvf php-5.5.25.tar.gz -C /usr/src
cd /usr/src/php-5.5.25/
./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-opcache \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--without-pear \
--with-gettext \
--disable-fileinfo
make ZEND_EXTRA_LIBS='-liconv'
make install
6.链接php可执行文件:
ln -s /usr/local/php/bin/php /usr/bin/php
ln -s /usr/local/php/bin/phpize /usr/bin/phpize
ln -s /usr/local/php/sbin/php-fpm /usr/bin/php-fpm
7.编辑php.ini配置文件:
cp /usr/src/php-5.5.25/php.ini-production
/usr/local/php/etc/php.ini
ln -s /usr/local/php/etc/php.ini /etc/php.ini
vim /etc/php.ini
[PHP]
engine = On
zend.ze1_compatibility_mode = Off
short_open_tag = On
asp_tags = Off
precision
= 12
y2k_compliance = On
output_buffering = On
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func=
serialize_precision = 100
safe_mode = Off
safe_mode_gid = Off
safe_mode_include_dir =
safe_mode_exec_dir =
safe_mode_allowed_env_vars = PHP_
safe_mode_protected_env_vars = LD_LIBRARY_PATH
disable_functions =
passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket
disable_classes =
expose_php = On
error_reporting = E_ALL ~E_NOTICE
display_errors = On
display_startup_errors = Off
log_errors = Off
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
variables_order = "EGPCS"
register_globals = Off
register_long_arrays = Off
register_argc_argv = On
auto_globals_jit = On
post_max_size = 50M
magic_quotes_gpc = Off
magic_quotes_runtime = Off
magic_quotes_sybase = Off
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
doc_root =
user_dir =
extension_dir =
"/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/"
enable_dl = On
cgi.fix_pathinfo=0
file_uploads = On
upload_max_filesize = 50M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
[Date]
date.timezone = PRC
[filter]
[iconv]
[sqlite]
[Pcre]
[Syslog]
define_syslog_variables = Off
[mail function]
SMTP = localhost
smtp_port = 25
[SQL]
sql.safe_mode = Off
[ODBC]
odbc.allow_persistent = On
odbc.check_persistent = On
odbc.max_persistent = -1
odbc.max_links = -1
odbc.defaultlrl = 4096
odbc.defaultbinmode = 1
[MySQL]
mysql.allow_persistent = On
mysql.max_persistent = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_socket =
mysql.default_host =
mysql.default_user =
mysql.default_password =
mysql.connect_timeout = 60
mysql.trace_mode = Off
[MySQLi]
mysqli.max_links = -1
mysqli.default_port = 3306
mysqli.default_socket =
mysqli.default_host =
mysqli.default_user =
mysqli.default_pw =
mysqli.reconnect = Off
[mSQL]
msql.allow_persistent = On
msql.max_persistent = -1
msql.max_links = -1
[OCI8]
[PostgresSQL]
pgsql.allow_persistent = On
pgsql.auto_reset_persistent = Off
pgsql.max_persistent = -1
pgsql.max_links = -1
pgsql.ignore_notice = 0
pgsql.log_notice = 0
[Sybase]
sybase.allow_persistent = On
sybase.max_persistent = -1
sybase.max_links = -1
sybase.min_error_severity = 10
sybase.min_message_severity = 10
sybase.compatability_mode = Off
[Sybase-CT]
sybct.allow_persistent = On
sybct.max_persistent = -1
sybct.max_links = -1
sybct.min_server_severity = 10
sybct.min_client_severity = 10
[bcmath]
bcmath.scale = 0
[browscap]
[Informix]
ifx.default_host =
ifx.default_user =
ifx.default_password =
ifx.allow_persistent = On
ifx.max_persistent = -1
ifx.max_links = -1
ifx.textasvarchar = 0
ifx.byteasvarchar = 0
ifx.charasvarchar = 0
ifx.blobinfile = 0
ifx.nullformat = 0
[Session]
session.save_handler = files
session.use_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor
= 100
session.gc_maxlifetime = 1440
session.bug_compat_42 = 1
session.bug_compat_warn = 1
session.referer_check =
session.entropy_length = 0
session.entropy_file =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 4
url_rewriter.tags =
"a=href,area=href,frame=src,input=src,form=,fieldset="
[MSSQL]
mssql.allow_persistent = On
mssql.max_persistent = -1
mssql.max_links = -1
mssql.min_error_severity = 10
mssql.min_message_severity = 10
mssql.compatability_mode = Off
mssql.secure_connection = Off
[Assertion]
[COM]
[mbstring]
[FrontBase]
[gd]
[exif]
[Tidy]
tidy.clean_output = Off
[soap]
soap.wsdl_cache_enabled=1
soap.wsdl_cache_dir="/tmp"
soap.wsdl_cache_ttl=86400
[Zend Optimizer]
zend_extension =
/usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/opcache.so
zend_loader.enable = 1
zend_loader.disable_licensing = 0
zend_loader.obfuscation_level_support = 3
8.编辑php-fpm.conf配置文件:
cp /usr/local/php/etc/php-fpm.conf.default
/usr/local/php/etc/php-fpm.conf
vim /usr/local/php/etc/php-fpm.conf
[global]
pid = /home/php/pid/php-fpm.pid
error_log = /home/php/log/php-fpm_error.log
log_level = notice
[www]
listen = 127.0.0.1:9000
listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 6
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = /home/php/log/slow.log
9.编写php-fpm启动脚本
vim /etc/init.d/php-fpm
#!/bin/sh
# chkconfig:
2345 90
10
#
Description:
Start and
Stop php-fpm
# Provides:
php-fpm
#
Default-Start:
2 3 4 5
#
Default-Stop:
0 1 6
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=/home/php/pid/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
'created')
if [ -f "$2" ] ; then
try=''
break
fi
;;
'removed')
if [ ! -f "$2" ] ; then
try=''
break
fi
;;
esac
echo -n .
try=`expr $try + 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm..."
$php_fpm_BIN --daemonize $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Stoping php-fpm..."
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;
esac
10.创建目录并修改权限,重启nginx服务:
mkdir -p /home/php/log
mkdir -p /home/php/pid
chown -R www:www /home/php/log
chown -R www:www /home/php/pid
service nginx restart
11.添加php-fpm系统服务:
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --level 2345 php-fpm on
chkconfig --list | grep php-fpm
12.启动php-fpm服务:
service php-fpm start
ps -aux | grep php-fpm
netstat -anptu | grep 9000
13.配置php测试页:
vim /home/www/html/phpinfo.php
如何编译安装PHP扩展
一开始安装PHP的时候,我们并不知道需要哪些扩展,所以只有等到我们真正用到的时候才想办法去安装。
安装PHP扩展最简单的办法就是
sudo apt-get install php5-xxx
但有的时候并非我们所愿,源里面并没有我们需要的扩展,这时候就需要我们下载源码自己编译安装了。
这篇文章中我将介绍在本地Linux平台下编译安装PHP扩展的方法。
现在网站根目录下创建 index.php 打印基本的配置信息,以验证我们是否安装成功。
配置编译环境
我们需要安装一些编译必须的库,还有 php-dev 版本
Ubuntu
sudo apt-get install php5-dev php5-mysql gcc libpcre3-dev
Fedora
sudo yum install php-devel php-mysqlnd gcc libtool
RHEL
sudo yum install php-devel php-mysql gcc libtool
Suse
yast2 -i php5-pear php5-devel php5-mysql gcc
安装扩展
PHP有两种可供安装的扩展:一种是PHP原生的但是默认没有安装的,另一种的第三方开发的扩展。
下面依次介绍两种扩展的安装方法:
安装之前我们需要一份和当前机器上相同版本的PHP源码
cd code
wget
tar xvjf php-5.5.9.tar.bz2
cd php-5.5.9
前往此处 下载相应的源码包。
在 /ext 目录下面可以看到所有PHP原生的扩展。
安装原生扩展
以 PHP-intl 为例,这是PHP国际化的扩展。
为了安装这个扩展我们需要先安装ICU 库
sudo apt-get install icu-devtools icu-doc libicu-dev libicu52 libicu52-dbg
ICU 安装成功之后进入/ext/intl 目录:
cd intl
phpize
./configure --enable-intl
make
sudo make install
下面解释一下上面的每个命令:
phpize : 是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块
./configure --enable-intl: 配置编译环境,相当于告诉编译器编译PHP源码的时候加上intl这个扩展。
make: 将会把源码编译成 intl.so
make install : 将会把 intl.so 移动到当前安装的 PHP 的扩展目录。
接下来我们要做的就是在php.ini中启用这个扩展,这一步将会在最后给出示例。
安装第三方扩展
将以这个 扩展为例,这个扩展主要实现了PHP识别条形码的功能。
先安装必要的依赖
sudo apt-get install pkg-config
git clone
cd mongo-php-driver
phpize
./configure
make
sudo make install
将会生成一个文件,将其拷贝到PHP的扩展目录下面。
启用扩展
在php.ini中启用扩展的方式有很多:
直接在php.ini文件中添加 extension=mongo.so,这是最简单直接的方法。
也可以单独建一个ini文件,然后在php.ini中包含这些文件就可以了。
下面介绍一下第二种方法:
cd `/etc/php5/mods-available`
这个目录里可以放新建的ini文件,然后执行
sudo touch mongo.ini
echo "extension=mongo.so" | sudo tee -a mongo.ini
sudo touch intl.ini
echo "extension=intl.so" | sudo tee -a intl.ini
上面的命令将会创建ini文件,并且写如相应的配置信息。
然后执行下面的命令启用扩展即可(需要安装 php5enmod 工具):
sudo php5enmod mongo
sudo php5enmod intl
如果未安装 php5enmod 工具,则需要手动配置:
ln -s /etc/php5/mods-available/mongo.ini /etc/php5/cli/conf.d/mongo.ini
ln -s /etc/php5/mods-available/intl.ini /etc/php5/cli/conf.d/intl.ini
ln -s /etc/php5/mods-available/mongo.ini /etc/php5/fpm/conf.d/mongo.ini
ln -s /etc/php5/mods-available/intl.ini /etc/php5/fpm/conf.d/intl.ini
最后在执行一下重启操作就可以了:
sudo service nginx restart
sudo service php5-fpm restart
php-5.5.6 怎么安装
你如果是做开发版本的话,把php.ini-developement重命名为php.ini就行了,你在网上搜的教程都是针对老版本的。
如何安装PHP模块
php模块安装的方式
1、静态安装
将先将在安装php之前先将需要安装的程序装上,如ftp、mhash、mcrypt……安装完成后,解压php安装包,执行./configure
--with-ftp
--with-mhash
--wth-mcrypt等等。后面具体跟的参数可以参看./configure
--help查看。编译好后,执行make
make
install
就行了。
2、动态安装
而在往往我们进行编译php时经常会忘记添加某扩展,后来想添加扩展,但是因为安装php后又装了一些东西如PEAR等,不想再重新装php,于是可以采用phpize来动态加载需要安装的模块。
具体实现方法如下(这里以忘记安装pdo_mysql模块为例):
cd
/root/source/php-5.3.10/ext/pdo_mysql
/usr/local/php/bin/phpize
在安装完mysql后,并不是进入/root/source/mysql-5.5.21目录运行phpize,而是进入php的源文件中要增加的扩展模块的文件目录---也就是/root/source/php-5.3.10/ext/pdo_mysql目录执行phpize。如果不是这样操作的话就会提示下面的错误:
Cannot
find
config.m4.
Make
sure
that
you
run
'/usr/local/php/bin/phpize'
in
the
top
level
source
directory
of
the
module
关于上面的这个错误,我不得不鄙视下网上有些自以为是的家伙,自认为对所有的安装操作很懂,报上面的错误的时候,去修改源代码,搞的乱七八糟,误人子弟。根本不按php官方的文档操作。
目录/root/source/php-5.3.10/ext/pdo_mysql
,在运行phpize命令前并没有configure文件,只有config.m4文件。运行phpize就生成了一个可执行的configure文件。此时就可以按照下的方法编译了:
./configure
--with-php-config=/usr/bin/php-config
(还可以加一些其他的参数,可通过./configure
--help查看)
make
make
install
编译完成后会提示扩展模块生成在/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626目录。
修改php.ini文件
vi
/usr/local/php/etc/php.ini
在其文件结尾加入下面的内容:
extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626"
extension=pdo_mysql.so
安装完成后,重启php-fpm和web服务器。(因为我用的是php-fpm和tengine,如果用的是apache则也重启相应的程序,重新加载就行了)
php5.5 编译安装后bin目录中没有php
百度输入phpstudy下载安装 集成开发环境改一下用户环境变量path指向mysql的bin文件即可。e