当前位置: 首页 > 工具软件 > PH7 > 使用案例 >

39.安装PH5\PH7

王杰
2023-12-01

11.10/11.11/11.12 安装PHP5

11.13 安装PHP7

php中mysql,mysqli,mysqlnd,pdo到底是什么 

http://blog.csdn.net/u013785951/article/details/60876816

查看编译参数 

http://ask.apelearn.com/question/1295

 

 

 

 

11.10/11.11/11.12 安装PHP5:

 

 

PHP官网www.php.net

当前主流版本为5.6/7.1

有些过老的版本可能不兼容7版本。7的性能比5有很大的提升

cd /usr/local/src/

wget http://cn2.php.net/distributions/php-5.6.32.tar.gz

tar zxf php-5.6.32.tar.gz

cd php-5.6.32

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --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

--prefix=/usr/local/php 指定安装目录

--with-apxs2 apxs2是Apache的一种工具,可以自动的把扩展的模块放到Apache的目录里,就是在我们用httpd -M的时候可以加载出来。阿鑫在做的时候,修改了他的路径(find一下apxs2,查到目录,修改一下就可以了)

--with-config-file-path=/usr/local/php/etc 指定php的配置文件

--with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config 指定这三种mysql不同的库。相当于php与mysql相互通信的驱动,所以是定义mysql的函数或者驱动的

后面的都是指定php的模块的

make && make install

cp php.ini-production /usr/local/php/etc/php.ini 我们指定了他的配置文件,要拷贝到那里去( --with-config-file-path).。如果是开发环境就用 php.ini-development,php.ini-production用于生产环境

 

知识点:

/usr/local/php/bin/ PHP的核心文件

/usr/local/apache2.4/modules/libphp5.so 这是我们安装php5的模块。我们需要的

/usr/local/php/bin/ -m 查看php加载的模块有哪些(静态的)。是可以扩展的,增加.so的文件

/usr/local/apache2.4/bin/httpd -M 可以查看Apache的模块。最后就是我们安装的php5的模块

php作为Apache的扩展模块存在的。也就是说Apache需要借助php module,也就是借助这个.so的文件

vim /usr/local/apache2.4/conf/httpd.conf 可以查看Apache的模块。php也在其中

 

实例:

[root@localhost]# cd /usr/local/src

[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.gz

[root@localhost src]#tar zxf php-5.6.32.tar.gz

[root@localhost src]# cd php-5.6.32/

[root@localhost php-5.6.32]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --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

以下的几个报错,安装PH5.6.32

1.configure: error: xml2-config not found. Please check your libxml2 installation.

#yum install -y libxml2-devel

2.configure: error: Cannot find OpenSSL's <evp.h>
#yum install -y openssl-devel

3.configure: error: Please reinstall the BZip2 distribution

#yum install -y bzip2 bzip2-devel

4.configure: error: jpeglib.h not found.
#yum -y install libjpeg-devel

5.configure: error: png.h not found.

#yum install -y libpng libpng-devel

6.configure: error: freetype-config not found.

#yum install -y freetype freetype-devel

7.configure: error: mcrypt.h not found. Please reinstall libmcrypt.

#yum install -y epel-release

#yum install -y libmcrypt-devel

编译完成

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

安装PH7提示报错

1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
 

#yum install -y perl* 

​#yum install -y httpd-devel

#find / -name apxs  得到的路径是:/usr/sbin/apxs

于是修改--with-apsx2=/usr/sbin/apxs指定到正确路径

还有n个报错,都是缺少一些库。安装就好了

[root@localhost php-5.6.32]# echo $? 直到成功。configure成功

0

[root@localhost php-5.6.32]# make 开始make

xt/standard/crypt_blowfish.lo ext/standard/crypt_sha512.lo ext/standard/crypt_sha256.lo ext/standard/php_crypt_r.lo ext/standard/array.lo ext/standard/base64.lo ext/standard/basic_functions.lo ext/standard/browscap.lo ext/standard/crc32.lo ext/standard/crypt.lo ext/standard/cyr_convert.lo ext/standard/datetime.lo ext/standard/dir.lo ext/standard/dl.lo ext/standard/dns.lo ext/standard/exec.lo ext/standard/file.lo ext/standard/filestat.lo ext/standard/flock_compat.lo ext/standard/formatted_print.lo ext/standard/fsock.lo ext/standard/head.lo ext/standard/html.lo ext/standard/image.lo ext/standard/info.lo ext/standard/iptc.lo ext/standard/lcg.lo ext/standard/link.lo ext/standard/mail.lo ext/standard/math.lo ext/standard/md5.lo ext/standard/metaphone.lo ext/standard/microtime.lo ext/standard/pack.lo ext/standard/pageinfo.lo ext/standard/quot_print.lo ext/standard/rand.lo ext/standard/soundex.lo ext/standard/string.lo ext/standard/scanf.lo ext/standard/syslog.lo ext/standard/type.lo ext/standard/uniqid.lo ext/standard/url.lo ext/standard/var.lo ext/standard/versioning.lo ext/standard/assert.lo ext/standard/strnatcmp.lo ext/standard/levenshtein.lo ext/standard/incomplete_class.lo ext/standard/url_scanner_ex.lo ext/standard/ftp_fopen_wrapper.lo ext/standard/http_fopen_wrapper.lo ext/standard/php_fopen_wrapper.lo ext/standard/credits.lo ext/standard/css.lo ext/standard/var_unserializer.lo ext/standard/ftok.lo ext/standard/sha1.lo ext/standard/user_filters.lo ext/standard/uuencode.lo ext/standard/filters.lo ext/standard/proc_open.lo ext/standard/streamsfuncs.lo ext/standard/http.lo ext/standard/password.lo ext/tokenizer/tokenizer.lo ext/tokenizer/tokenizer_data.lo ext/xml/xml.lo ext/xml/compat.lo ext/xmlreader/php_xmlreader.lo ext/xmlwriter/php_xmlwriter.lo TSRM/TSRM.lo TSRM/tsrm_strtok_r.lo main/main.lo main/snprintf.lo main/spprintf.lo main/php_sprintf.lo main/fopen_wrappers.lo main/alloca.lo main/php_scandir.lo main/php_ini.lo main/SAPI.lo main/rfc1867.lo main/php_content_types.lo main/strlcpy.lo main/strlcat.lo main/mergesort.lo main/reentrancy.lo main/php_variables.lo main/php_ticks.lo main/network.lo main/php_open_temporary_file.lo main/output.lo main/getopt.lo main/streams/streams.lo main/streams/cast.lo main/streams/memory.lo main/streams/filter.lo main/streams/plain_wrapper.lo main/streams/userspace.lo main/streams/transports.lo main/streams/xp_socket.lo main/streams/mmap.lo main/streams/glob_wrapper.lo Zend/zend_language_parser.lo Zend/zend_language_scanner.lo Zend/zend_ini_parser.lo Zend/zend_ini_scanner.lo Zend/zend_alloc.lo Zend/zend_compile.lo Zend/zend_constants.lo Zend/zend_dynamic_array.lo Zend/zend_dtrace.lo Zend/zend_execute_API.lo Zend/zend_highlight.lo Zend/zend_llist.lo Zend/zend_vm_opcodes.lo Zend/zend_opcode.lo Zend/zend_operators.lo Zend/zend_ptr_stack.lo Zend/zend_stack.lo Zend/zend_variables.lo Zend/zend.lo Zend/zend_API.lo Zend/zend_extensions.lo Zend/zend_hash.lo Zend/zend_list.lo Zend/zend_indent.lo Zend/zend_builtin_functions.lo Zend/zend_sprintf.lo Zend/zend_ini.lo Zend/zend_qsort.lo Zend/zend_multibyte.lo Zend/zend_ts_hash.lo Zend/zend_stream.lo Zend/zend_iterators.lo Zend/zend_interfaces.lo Zend/zend_exceptions.lo Zend/zend_strtod.lo Zend/zend_gc.lo Zend/zend_closures.lo Zend/zend_float.lo Zend/zend_string.lo Zend/zend_signal.lo Zend/zend_generators.lo Zend/zend_virtual_cwd.lo Zend/zend_ast.lo Zend/zend_objects.lo Zend/zend_object_handlers.lo Zend/zend_objects_API.lo Zend/zend_default_classes.lo Zend/zend_execute.lo main/internal_functions_cli.lo sapi/cgi/cgi_main.lo sapi/cgi/fastcgi.lo -lcrypt -lresolv -lcrypt -lrt -lmysqlclient_r -lmcrypt -lpng -lz -ljpeg -lbz2 -lz -lrt -lm -ldl -lnsl -lxml2 -lz -lm -ldl -lssl -lcrypto -lxml2 -lz -lm -ldl -lfreetype -lmysqlclient -lm -lrt -ldl -lmysqlclient -lm -lrt -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lxml2 -lz -lm -ldl -lcrypt  -o sapi/cgi/php-cgi
Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorytreeiterator.inc
invertedregexiterator.inc
directorygraphiterator.inc
pharcommand.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

[root@localhost php-5.6.32]# echo $? 查看是否成功

0

[root@localhost php-5.6.32]# make install

Installing PEAR environment:      /usr/local/php/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-5.6.32/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/

[root@localhost php-5.6.32]# echo $? 查看是否成功

0

[root@localhost php-5.6.32]# cp php.ini-production /usr/local/php/etc/php.ini

 

 

!!阿鑫在./configure的时候,因为--with exps的路径写错了。阿鑫的电脑路径是apache2,跟着阿铭老师写了2.4结果导致不成功。这点需要注意

 

 

 

----------------------------------------------------------------------------------------------------------------------------------------------------

 

 

11.13 安装PHP7:

 

 

 

 

cd /usr/local/src/

wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

tar xjvf php-7.1.6.tar.bz2 //tar -xvf axin.tar 解包,后面跟打包名

tar zxf php-7.1.6.tar.bz2 (报错,z : 表示 tar 包是被 gzip 压缩过的,所以解压时需要用 gunzip 解压

cd php-7.1.6

./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --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

Thank you for using PHP.

config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

make

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
directorygraphiterator.inc
pharcommand.inc
clicommand.inc
invertedregexiterator.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

&& make install

Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/usr/local/src/php-7.1.6/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/

ls /usr/local/apache2.4/modules/libphp7.so

/usr/local/apache2.4/modules/libphp7.so

cp php.ini-production /usr/local/php7/etc/php.ini 解释跟php5一样

 

 

ls /usr/local/apache2.4/modules 下就有libphp7.so。查看Apache的模块

libphp5.so            mod_authn_dbm.so        mod_cache_disk.so     mod_file_cache.so           mod_macro.so           mod_proxy_scgi.so      mod_session.so           mod_userdir.so
libphp7.so            mod_authn_file.so       mod_cache.so          mod_filter.so               mod_mime.so            mod_proxy.so           mod_setenvif.so          mod_version.so
mod_access_compat.so  mod_authn_socache.so    mod_cache_socache.so  mod_headers.so              mod_negotiation.so     mod_proxy_uwsgi.so     mod_slotmem_shm.so       mod_vhost_alias.so
mod_actions.so        mod_authz_core.so       mod_cgid.so           mod_include.so              mod_proxy_ajp.so       mod_proxy_wstunnel.so  mod_socache_dbm.so       mod_watchdog.so
mod_alias.so          mod_authz_dbd.so        mod_dav_fs.so         mod_info.so                 mod_proxy_balancer.so  mod_ratelimit.so       mod_socache_memcache.so
mod_allowmethods.so   mod_authz_dbm.so        mod_dav.so            mod_lbmethod_bybusyness.so  mod_proxy_connect.so   mod_remoteip.so        mod_socache_redis.so
mod_auth_basic.so     mod_authz_groupfile.so  mod_dbd.so            mod_lbmethod_byrequests.so  mod_proxy_express.so   mod_reqtimeout.so      mod_socache_shmcb.so
mod_auth_digest.so    mod_authz_host.so       mod_dir.so            mod_lbmethod_bytraffic.so   mod_proxy_fcgi.so      mod_request.so         mod_speling.so
mod_auth_form.so      mod_authz_owner.so      mod_dumpio.so         mod_lbmethod_heartbeat.so   mod_proxy_fdpass.so    mod_rewrite.so         mod_status.so
mod_authn_anon.so     mod_authz_user.so       mod_env.so            mod_log_config.so           mod_proxy_ftp.so       mod_sed.so             mod_substitute.so
mod_authn_core.so     mod_autoindex.so        mod_expires.so        mod_log_debug.so            mod_proxy_hcheck.so    mod_session_cookie.so  mod_unique_id.so

/usr/local/php7/bin/php -m 查看php7加载的模块

dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

/usr/local/apache2.4/bin/apachectl -M 查看Apache加载了几个php。最下面就是php7和php5

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ::1. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 setenvif_module (shared)
 version_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 php5_module (shared)
 php7_module (shared)

我们如何在PHP7和PHP5之间选择切换,修改配置文件:

vim /usr/local/apache2.4/conf/httpd.conf 在里面找到PHP5或PHP7(可/ 搜索php5.so),前面加#注释,注释掉这一个,就是使用另一个

#LoadModule php5_module modules/libphp5.so

LoadModule php7_module modules/libphp7.so

 

 

 

 

实例:

[root@localhost ~]# cd /usr/local/src

[root@localhost src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

[root@localhost src]# ls

[root@localhost src]# tar -jxvf php-7.1.6.tar.bz2

[root@localhost src]# ls

apr-1.6.3 apr-util-1.6.1.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz php-5.6.32.tar.bz2

apr-1.6.3.tar.gz httpd-2.4.34 mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz php-7.1.6

apr-util-1.6.1 httpd-2.4.34.tar.gz php-5.6.32 php-7.1.6.tar.bz2

[root@localhost src]# cd php-7.1.6/

[root@localhost php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --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

[root@localhost php-7.1.6]# echo $?

0

[root@localhost php-7.1.6]# make

[root@localhost php-7.1.6]# echo $?

0

[root@localhost php-7.1.6]# make install

[root@localhost php-7.1.6]# echo $?

0

[root@localhostphp-7.1.6]# cp php.ini-production /usr/local/php7/etc/php.ini

转载于:https://my.oschina.net/u/3866192/blog/3074147

 类似资料: