Home Backend Development PHP7 How to install PHP5 and PHP7 on CentOS

How to install PHP5 and PHP7 on CentOS

Jan 25, 2021 am 09:29 AM
centos

How to install PHP5 and PHP7 on CentOS

Recommended (free): PHP7

##Install PHP5

  • Download and decompress the binary package

1

2

3

[root@test-a src]# cd /usr/local/src/

[root@test-a src]# wget  http://cn2.php.net/distributions/php-5.6.32.tar.bz2

[root@test-a src]# tar jxvf php-5.6.32.tar.bz2

Copy after login
  • Compile and install PHP

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

./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

 

#报错:

...

configure: error: Cannot find OpenSSL's <evp.h>

 

# 安装openssl

[root@test-a php-5.6.32]# yum install openssl-devel -y

...

Total size: 14 M

Total download size: 151 k

Downloading packages:

Delta RPMs disabled because /usr/bin/applydeltarpm not installed.

libselinux-utils-2.5-12.el7.x8 FAILED

http://mirrors.163.com/centos/7/os/x86_64/Packages/libselinux-utils-2.5-12.el7.x86_64.rpm: [Errno 14] HTTP Error 416 - Requested Range Not Satisfiable

Trying other mirror.

 

Error downloading packages:

  libselinux-utils-2.5-12.el7.x86_64: [Errno 256] No more mirrors to try.

 

# 安装过程报错,需要安装deltarpm

[root@test-a php-5.6.32]# yum install deltarpm

...

Downloading packages:

No Presto metadata available for base

libselinux-utils-2.5-12.el7.x8 FAILED

http://mirrors.163.com/centos/7/os/x86_64/Packages/libselinux-utils-2.5-12.el7.x86_64.rpm: [Errno 14] HTTP Error 416 - Requested Range Not Satisfiable

Trying other mirror.

 

 

Error downloading packages:

  libselinux-utils-2.5-12.el7.x86_64: [Errno 256] No more mirrors to try.

# 还是报错,由于之前用的Base源是163的,换回默认的Base源再试就OK了... :(

# 继续初始化配置过程,报错

...

checking for BZip2 support… yes checking for BZip2 in default path… not found configure: error: Please reinstall the BZip2 distribution 

[root@test-a php-5.6.32]# yum -y install bzip2-devel

# 继续报错

...

checking for stdarg.h... (cached) yes

checking for mcrypt support... yes

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

# 继续报错

[root@test-a php-5.6.32]# yum install -y libmcrypt-devel

 

#继续报错

...

checking for MySQL support... yes

checking for specified location of the MySQL UNIX socket... no

configure: error: Cannot find libmysqlclient_r under /usr/local/mysql.

Note that the MySQL client library is not bundled anymore!

# PHP默认是去/usr/local/mysql/lib/mysql/搜索,没有找到报错,复制或者做个软连接就行.

[root@test-a php-5.6.32]# cp /usr/local/mysql/lib/libmysqlclient.so /usr/local/mysql/lib/mysql/libmysqlclient_r.so

 

# 再次安装,苍了个天,看见Thank you...啦 成功!

...

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

 

 

# 编译

[root@test-a php-5.6.32]# make

...

Build complete.

Don't forget to run 'make test'.

 

# 安装

[root@test-a php-5.6.32]# make install

Copy after login
  • View php modules(all static)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

[root@test-a php-5.6.32]#  /usr/local/php/bin/php -m

[PHP Modules]

bz2

Core

ctype

date

dom

ereg

exif

fileinfo

filter

gd

hash

iconv

json

libxml

mbstring

mcrypt

mysql

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]

 

# 拷贝配置文件

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

 

# 查看php信息

[root@test-a php-5.6.32]#  /usr/local/php/bin/php -i

Copy after login

Install PHP7

  • Download and unzip the installation package

1

2

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

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

Copy after login
  • Configuration initialization

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

[root@test-a src]# cd php-7.1.6/

[root@test-a 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

# 出错

....

checking for mysql_set_server_option in -lmysqlclient_r... no

configure: error: wrong mysql library version or lib not found. Check config.log for more information.

# 由于php已经带了这个模块,所以编译时不指定mysqli的路径,继续

[root@test-a 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 --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

 

#出错

...

checking for mysql_commit in -lmysqlclient_r... (cached) no

configure: error: PDO_MYSQL configure failed, MySQL 4.1 needed. Please check config.log for more information.

 

#编译时不指定pdo的路径,继续

root@test-a 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 --with-mysqli --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

Copy after login
  • Compile and install

1

2

3

4

[root@test-a php-7.1.6]# make

[root@test-a php-7.1.6]# make install

[root@test-a php-7.1.6]# ls /usr/local/apache2.4/modules/libphp*

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

Copy after login

For more related learning, please pay attention to the PHP7 Tutorial column~

The above is the detailed content of How to install PHP5 and PHP7 on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to input Chinese in centos How to input Chinese in centos Apr 07, 2024 pm 08:21 PM

Methods for using Chinese input in CentOS include: using the fcitx input method: install and enable fcitx, set shortcut keys, press the shortcut keys to switch input methods, and input pinyin to generate candidate words. Use iBus input method: Install and enable iBus, set shortcut keys, press the shortcut keys to switch input methods, and input pinyin to generate candidate words.

How to read USB disk files in centos7 How to read USB disk files in centos7 Apr 07, 2024 pm 08:18 PM

To read U disk files in CentOS 7, you need to first connect the U disk and confirm its device name. Then, use the following steps to read the file: Mount the USB flash drive: mount /dev/sdb1 /media/sdb1 (replace "/dev/sdb1" with the actual device name) Browse the USB flash drive file: ls /media/sdb1; cd /media /sdb1/directory; cat file name

How to enter root permissions in centos7 How to enter root permissions in centos7 Apr 02, 2024 pm 08:57 PM

There are two ways to enter the root authority of CentOS 7: use the sudo command: enter sudo su - in the terminal and enter the current user password. Log in directly as the root user: Select "Other" on the login screen, enter "root" and the root password. Note: Operate carefully with root privileges, perform tasks with sudo privileges, and change the root password regularly.

SCP usage tips-recursively exclude files SCP usage tips-recursively exclude files Apr 22, 2024 am 09:04 AM

One can use the scp command to securely copy files between network hosts. It uses ssh for data transfer and authentication. Typical syntax is: scpfile1user@host:/path/to/dest/scp -r/path/to/source/user@host:/path/to/dest/scp exclude files I don't think you can when using scp command Filter or exclude files. However, there is a good workaround to exclude the file and copy it securely using ssh. This page explains how to filter or exclude files when copying directories recursively using scp. How to use rsync command to exclude files The syntax is: rsyncav-essh-

What to do if you forget your password to log in to centos What to do if you forget your password to log in to centos Apr 07, 2024 pm 07:33 PM

Solutions for forgotten CentOS passwords include: Single-user mode: Enter single-user mode and reset the password using passwd root. Rescue Mode: Boot from CentOS Live CD/USB, mount root partition and reset password. Remote access: Use SSH to connect remotely and reset the password with sudo passwd root.

How to enable root permissions in centos7 How to enable root permissions in centos7 Apr 07, 2024 pm 08:03 PM

CentOS 7 disables root permissions by default. You can enable it by following the following steps: Temporarily enable it: Enter "su root" on the terminal and enter the root password. Permanently enabled: Edit "/etc/ssh/sshd_config", change "PermitRootLogin no" to "yes", and restart the SSH service.

How to obtain root permissions in centos7 How to obtain root permissions in centos7 Apr 07, 2024 pm 07:57 PM

There are several ways to gain root privileges in CentOS 7: 1. Run the command using "su". 2. Use "sudo" to run a single command. 3. Enable the root user and set a password. NOTE: Be cautious when using root privileges as they may damage the system.

How to enter root permissions in centos How to enter root permissions in centos Apr 07, 2024 pm 08:06 PM

There are two ways to perform tasks with root privileges in CentOS: 1) Use the sudo command to temporarily obtain root privileges; 2) Log in directly using the root user password. Extreme caution should be used when using root privileges and it is recommended to only use them when necessary.

See all articles