你好,游客 登录 注册 搜索
背景:
阅读新闻

PHP源码安装、简单配置、测试及连接数据库

[日期:2016-10-13] 来源:Linux社区  作者:firelowrie [字体: ]

主机环境 RedHat6.5 64位
实验环境 服务端 ip172.25.29.1  php
安装包  php-5.6.20.tar.bz2
        re2c-0.13.5-1.el6.x86_64.rpm
        libmcrypt-2.5.8-9.el6.x86_64.rpm
        libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
        Discuz_X3.2_SC_UTF8.zip
1.  安装php
1.解压
[root@server1 mnt# tar jxf php-5.6.20.tar.bz2    #解压
[root@server1 php-5.6.20]# rpm -vih libmcrypt-*  #安装libmcrypt库
[root@server1 php-5.6.20]# yum installre2c-0.13.5-1.el6.x86_64.rpm –y  #安装re2c
 
2.软件配置
[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php--with-config-file-path=/usr/local/lnmp/php/etc --with-openssl --with-snmp--with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir--with-jpeg-dir --with-freetype-dir --with-gettext --without-pear --with-gmp--enable-inline-optimization --enable-soap --enable-ftp --enable-sockets--enable-mbstring --with-mysqli --with-mysql --with-pdo-mysql --enable-fpm--with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
 
如果出现如下错误

[root@server1 php-5.6.20]# yum install libxml2-devel -y
 
重新配置
[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
 
如果出现如下错误

[root@server1 php-5.6.20]# yum provides */easy.h

[root@server1 php-5.6.20]# yum install -ylibcurl-devel-7.19.7-37.el6_4.x86_64
 
重新配置
[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
 
如果出现如下错误

[root@server1 php-5.6.20]# yum provides */jpeglib.h
[root@server1 php-5.6.20]# yum install -ylibjpeg-turbo-devel-1.2.1-1.el6.x86_64
 
重新配置
[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
 
如果出现如下错误

[root@server1 php-5.6.20]# yum provides */png.h
[root@server1 php-5.6.20]# yum install -ylibpng-devel-1.2.49-1.el6_2.x86_64
 
重新配置
[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
 
如果出现如下错误

[root@server1 php-5.6.20]# yum install -y freetype-devel
 
重新配置
[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
 
如果出现如下错误

[root@server1 php-5.6.20]# yum provides */gmp.h
[root@server1 php-5.6.20]# yum install -y gmp-devel-4.3.1-7.el6_2.2.x86_64
 
重新配置
[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-openssl--with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir--with-jpeg-dir --with-freetype-dir --with-gettext --without-pear --with-gmp--enable-inline-optimization --enable-soap --enable-ftp --enable-sockets--enable-mbstring --with-mysqli --with-mysql --with-pdo-mysql --enable-fpm--with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash
 
如果出现如下错误

[root@server1 php-5.6.20]# yum install -y net-snmp-devel
 
重新配置
[root@server1 php-5.6.20]# ./configure--prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc--with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir--with-png-dir --with-jpeg-dir --with-freetype-dir --with-gettext--without-pear --with-gmp --enable-inline-optimization --enable-soap--enable-ftp --enable-sockets --enable-mbstring --with-mysqli --with-mysql--with-pdo-mysql --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx--with-mcrypt --with-mhash
 
3.编译、链接、安装
[root@server1 php-5.6.20]# make #编译
[root@server1 php-5.6.20]# make install  #安装
 
2.php的简单配置
[root@server1 php-5.6.20]# cd /usr/local/lnmp/php/etc/
[root@server1 etc]# ls
php-fpm.conf.default
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf  #备份php的文件
[root@server1 etc]# ls
php-fpm.conf php-fpm.conf.default
[root@server1 etc]# cp /mnt/php-5.6.20/php.ini-production php.ini  #php的配置文件
[root@server1 etc]# ls
php-fpm.conf php-fpm.conf.default  php.ini


如果要连接数据库,就做以下修改
[root@server1 etc]# vim php.ini
925 date.timezone = Asia/Shanghai          #修改时区
1001 pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock  #指定连接数据库的sock文件的路径
1150 mysql.default_socket = /usr/local/lnmp/mysql/data/mysql.sock  #同上
1209 mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock  #同上
[root@server1 etc]# vim php-fpm.conf
25 pid = run/php-fpm.pid          #将pid的标记去掉
 
[root@server1 etc]# cd /mnt/php-5.6.20/sapi/fpm/
[root@server1 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm  #添加启动命令
[root@server1 fpm]# chmod +x /etc/init.d/php-fpm      #添加可执行权限
[root@server1 fpm]# ll /etc/init.d/php-fpm
-rwxr-xr-x 1 root root 2359 Sep 18 00:18 /etc/init.d/php-fpm
[root@server1 fpm]# /etc/init.d/php-fpm start        #开启php服务
Starting php-fpm  done
 
[root@server1 fpm]# cd /usr/local/lnmp/nginx/conf/
[root@server1 conf]# vim nginx.conf         
 51            root  html;
 52            index  index.php index.html index.htm;    #在nginx里添加默认访问目录为php优先
 50        location / {
 
 53        }
 
 75        location ~ \.php$ {
 76            root          html;
 77            fastcgi_pass  127.0.0.1:9000;
 78            fastcgi_index  index.php;
 79            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
 80            include        fastcgi.conf;        #设置成已存在的文件
 81        }
 
[root@server1 conf]# nginx –t      #检测
[root@server1 conf]# nginx          #开启
[root@server1 conf]# cd ..
[root@server1 nginx]# cd html
[root@server1 html]# vim index.php      #写一个简单的测试文件
<?php
phpinfo()
?>
[root@server1 html]# /etc/init.d/httpd start      #开启httpd
Starting httpd:                                          [  OK  ]
 
3.测试  172.25.29.1

PHP 7革新与性能优化 http://www.linuxidc.com/Linux/2015-09/123136.htm

PHP 7 ,你值得拥有  http://www.linuxidc.com/Linux/2015-06/118847.htm 

CentOS 7.x / Fedora 21 上面体验 PHP 7.0  http://www.linuxidc.com/Linux/2015-05/117960.htm 

CentOS 6.3 安装LNMP (PHP 5.4,MyySQL5.6) http://www.linuxidc.com/Linux/2013-04/82069.htm 

在部署LNMP的时候遇到Nginx启动失败的2个问题 http://www.linuxidc.com/Linux/2013-03/81120.htm 

Ubuntu安装Nginx php5-fpm MySQL(LNMP环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm 

《细说PHP》高清扫描PDF+光盘源码+全套教学视频 http://www.linuxidc.com/Linux/2014-03/97536.htm 

CentOS 6中配置PHP的LNMP的开发环境  http://www.linuxidc.com/Linux/2013-12/93869.htm 

PHP 的详细介绍请点这里
PHP 的下载地址请点这里

本文永久更新链接地址http://www.linuxidc.com/Linux/2016-10/135977.htm

linux
相关资讯       PHP源码安装 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款