首页 > 代码库 > 配置php
配置php
php安装
官网:http://www.php.net/
端口号:无
把php放到最后安装,是因为在编译php的时候,有指定mysql和apache,如果不先安装好mysql和apache就没有办法安装php,而mysql和apache的安装顺序就无所谓了。
实验用的是php5.6版本,编译安装php需要很多相关的包,提前下载好,避免编译过程中出现较多错误,其中还需下载epel源。
查看php编译参数:/usr/local/php/bin/php-i |less
在Linux测试用:curl
步骤:
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.19.tar.gz
tar -zxvf php-5.6.19.tar.gz
cd php-5.6.19
wget http://www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
rpm -ivh epel-release-6-8_32.noarch.rpm
yum install -y libxml2-devel
yum install -y openssl openssl-devel
yum install -y bzip2 bzip2-devel
yum install -y libpng libpng-devel
yum install -y freetype freetype-devel
yum install -y libjpeg-devel //这个包容易忽视
yum install -y libmcrypt-devel //这个需要epel源
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql--with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir--with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt--enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets--enable-exif
echo $?
make
make install
echo $?
php编译完成。
cp /usr/local/src/php-5.6.19/php.ini-production /usr/local/php/etc/php.ini //拷贝配置文件
修改apache配置文件
vim/usr/local/apache2/conf/httpd.conf
//找到1:
<Directory/>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
</Directory>
//改为:
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow fromall
</Directory>
//不修改这个地方,访问网站会禁止访问,显示403,如discuz论坛
//找到2:
AddType application/x-gzip .gz .tgz
要想支持php解析,必须加上相应的类型,添加一行
AddType application/x-httpd-php .php
//找到3:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
//改为:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
针对php索引,一个站点的默认页为index.php
找到4:
#ServerName www.example.com:80
//改为:
ServerName localhost:80 //不改启动会有警告
php配置文件
vim /usr/local/php/etc/php.ini //打开php配置文件
1配置disable_functions
disable_functions =eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close
2配置error_log
display_errors = Off
log_errors = On //错误日志开关
error_log =/usr/local/php/logs/php_errors.log
error_reporting = E_ALL & ~E_STRICT //日志级别
3配置open_basedir
open_basedir = /dir1/:/dir2/ //web用户只允许访问这两个目录
除了在php.ini中定义open_basedir外,还可以在apapche配置文件或者虚拟主机配置文件定义,针对每个虚拟主机去限制
vim/usr/local/apache2/conf/extra/httpd-vhosts.conf
添加一行:
php_admin_value open_basedir"/data/www:/tmp"
4配置短标签
short_open_tag = On
动态加载php模块
/usr/local/php/bin/php –m //查看php模块
cd /usr/local/src/php-5.6.19/ext //php的模块
cd curl //进入curl模块进行编译
yum install -y autoconf //产生configure文件需要的包
yum install -y libcurl-devel //编译需要的包
/usr/local/php/bin/phpize //产生configure文件
#若是有报Cannot findconfig.m4.,就把当前*.m4文件该为config.m4
./configure--with-php-config=/usr/local/php/bin/php-config //开始编译
make
make install
ls /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226 //编译的模块都在这
vim /usr/local/php/etc/php.ini
找到extension= ,在下面添加一行
extension=curl.so
/usr/local/php/bin/php –m //可以查看到curl,说明动态编译成功
php添加memcache模块
wget http://www.lishiming.net/data/attachment/forum/memcache-2.2.3.tgz
tar zxf memcache-2.2.3.tgz
cd memcache-2.2.3
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make && make install
//安装完成后有提示,记住它
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
vim /usr/local/php/etc/php.ini
//找到
extension_dir = "./"改为extension_dir= "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"
//并且到相应的位置添加一行
extension=memcache.so
/usr/local/php/bin/php –m //查看模块,查看有没增加memcached模块
php 添加 redis 扩展模块
wget http://pecl.php.net/get/redis-2.2.5.tgz
tar zxvf redis-2.2.5.tgz
cd redis-2.2.5
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make
make install
vim /usr/local/php/etc/php.ini
找到extension= ,在下面添加一行
extension=redis.so
本文出自 “11736718” 博客,请务必保留此出处http://11746718.blog.51cto.com/11736718/1870796
配置php