1. 程式人生 > >【PHP】安裝

【PHP】安裝

author:咔咔

wechat:fangkangfk

 

這個基本沒有什麼問題,直接按照流程操作即可

 

環境:CentOS 7.4.1708

一、檢查當前系統是否已經安裝PHP

1

[[email protected] ~]# rpm -qa php 

二、檢視yum是否有可安裝的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

[[email protected] ~]# yum list | grep php

emacs-php-mode.noarch                       1.18.2-1.el7               

base    

graphviz-php.x86_64                         2.30.1-21.el7              base    

php.x86_64                                  5.4.16-45.el7              base    

php-bcmath.x86_64                           5.4.16-45.el7              base    

php-cli.x86_64                              5.4.16-45.el7              base    

php-common.x86_64                           5.4.16-45.el7              base    

php-dba.x86_64                              5.4.16-45.el7              base    

php-devel.x86_64                            5.4.16-45.el7              base    

php-embedded.x86_64                         5.4.16-45.el7              base    

php-enchant.x86_64                          5.4.16-45.el7              base    

php-fpm.x86_64                              5.4.16-45.el7              base    

php-gd.x86_64                               5.4.16-45.el7              base    

php-intl.x86_64                             5.4.16-45.el7              base    

php-ldap.x86_64                             5.4.16-45.el7              base    

php-mbstring.x86_64                         5.4.16-45.el7              base    

php-mysql.x86_64                            5.4.16-45.el7              base    

php-mysqlnd.x86_64                          5.4.16-45.el7              base    

php-odbc.x86_64                             5.4.16-45.el7              base    

php-pdo.x86_64                              5.4.16-45.el7              base    

php-pear.noarch                             1:1.9.4-21.el7             base    

php-pecl-memcache.x86_64                    3.0.8-4.el7                base    

php-pgsql.x86_64                            5.4.16-45.el7              base    

php-process.x86_64                          5.4.16-45.el7              base    

php-pspell.x86_64                           5.4.16-45.el7              base    

php-recode.x86_64                           5.4.16-45.el7              base    

php-snmp.x86_64                             5.4.16-45.el7              base    

php-soap.x86_64                             5.4.16-45.el7              base    

php-xml.x86_64                              5.4.16-45.el7              base    

php-xmlrpc.x86_64                           5.4.16-45.el7              base    

rrdtool-php.x86_64                          1.4.8-9.el7                base    

uuid-php.x86_64                             1.6.2-26.el7               base

三、安裝PHP

1

[[email protected] ~]# yum -y install php

四、檢視版本及支援的擴充套件

1

2

3

4

[[email protected] ~]# php -v

PHP 5.4.16 (cli) (built: Apr 12 2018 19:02:01)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

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

[[email protected] ~]# php -m 

[PHP Modules]

bz2

calendar

Core

ctype

curl

date

ereg

exif

fileinfo

filter

ftp

gettext

gmp

hash

iconv

json

libxml

mhash

openssl

pcntl

pcre

Phar

readline

Reflection

session

shmop

SimpleXML

sockets

SPL

standard

tokenizer

xml

zip

zlib

 

[Zend Modules]

1

2

3

4

5

6

7

8

9

10

11

12

13

14

[[email protected] ~]# ll /etc/php.d/

total 20

-rw-r--r-- 1 root root 49 Apr 12 15:04 curl.ini

-rw-r--r-- 1 root root 57 Apr 12 15:04 fileinfo.ini

-rw-r--r-- 1 root root 49 Apr 12 15:04 json.ini

-rw-r--r-- 1 root root 49 Apr 12 15:04 phar.ini

-rw-r--r-- 1 root root 47 Apr 12 15:04 zip.ini

[[email protected] ~]# ll /usr/lib64/php/modules/

total 3100

-rwxr-xr-x 1 root root   74776 Apr 12 15:04 curl.so

-rwxr-xr-x 1 root root 2713464 Apr 12 15:04 fileinfo.so

-rwxr-xr-x 1 root root   44784 Apr 12 15:04 json.so

-rwxr-xr-x 1 root root  272112 Apr 12 15:04 phar.so

-rwxr-xr-x 1 root root   58496 Apr 12 15:04 zip.so

五、安裝php-mysqlnd

當前系統已安裝的mysql版本是:

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

[[email protected] ~]# rpm -qi mysql-community-server

Name        : mysql-community-server

Version     : 8.0.11

Release     : 1.el7

Architecture: x86_64

Install Date: Thu 17 May 2018 09:40:08 PM EDT

Group       : Applications/Databases

Size        : 1633523890

License     : Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.

Signature   : DSA/SHA1, Sun 08 Apr 2018 01:07:21 PM EDT, Key ID 8c718d3b5072e1f5

Source RPM  : mysql-community-8.0.11-1.el7.src.rpm

Build Date  : Sun 08 Apr 2018 03:29:08 AM EDT

Build Host  : siv27.no.oracle.com

Relocations : (not relocatable)

Packager    : MySQL Release Engineering <[email protected]>

Vendor      : Oracle and/or its affiliates

URL         : http://www.mysql.com/

Summary     : A very fast and reliable SQL database server

Description :

The MySQL(TM) software delivers a very fast, multi-threaded, multi-user,

and robust SQL (Structured Query Language) database server. MySQL Server

is intended for mission-critical, heavy-load production systems as well

as for embedding into mass-deployed software. MySQL is a trademark of

Oracle and/or its affiliates

 

The MySQL software has Dual Licensing, which means you can use the MySQL

software free of charge under the GNU General Public License

(http://www.gnu.org/licenses/). You can also purchase commercial MySQL

licenses from Oracle and/or its affiliates if you do not wish to be bound by the terms of

the GPL. See the chapter "Licensing and Support" in the manual for

further info.

 

The MySQL web site (http://www.mysql.com/) provides the latest news and

information about the MySQL software.  Also please see the documentation

and the manual for more information.

 

This package includes the MySQL server binary as well as related utilities

to run and administer a MySQL server.

安裝php-mysqld外掛

1

[[email protected] ~]# yum -y install php-mysqlnd

  

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

[[email protected] ~]# ll /etc/php.d/

total 48

-rw-r--r-- 1 root root 49 Apr 12 15:04 curl.ini

-rw-r--r-- 1 root root 57 Apr 12 15:04 fileinfo.ini

-rw-r--r-- 1 root root 49 Apr 12 15:04 json.ini

-rw-r--r-- 1 root root 55 Apr 12 15:04 mysqlnd.ini

-rw-r--r-- 1 root root 69 Apr 12 15:04 mysqlnd_mysqli.ini

-rw-r--r-- 1 root root 67 Apr 12 15:04 mysqlnd_mysql.ini

-rw-r--r-- 1 root root 47 Apr 12 15:04 pdo.ini

-rw-r--r-- 1 root root 63 Apr 12 15:04 pdo_mysqlnd.ini

-rw-r--r-- 1 root root 61 Apr 12 15:04 pdo_sqlite.ini

-rw-r--r-- 1 root root 49 Apr 12 15:04 phar.ini

-rw-r--r-- 1 root root 55 Apr 12 15:04 sqlite3.ini

-rw-r--r-- 1 root root 47 Apr 12 15:04 zip.ini

[[email protected] ~]# ll /usr/lib64/php/modules/ 

total 3772

-rwxr-xr-x 1 root root   74776 Apr 12 15:04 curl.so

-rwxr-xr-x 1 root root 2713464 Apr 12 15:04 fileinfo.so

-rwxr-xr-x 1 root root   44784 Apr 12 15:04 json.so

-rwxr-xr-x 1 root root  133224 Apr 12 15:04 mysqlnd_mysqli.so

-rwxr-xr-x 1 root root   53624 Apr 12 15:04 mysqlnd_mysql.so

-rwxr-xr-x 1 root root  256632 Apr 12 15:04 mysqlnd.so

-rwxr-xr-x 1 root root   28880 Apr 12 15:04 pdo_mysqlnd.so

-rwxr-xr-x 1 root root  116408 Apr 12 15:04 pdo.so

-rwxr-xr-x 1 root root   29240 Apr 12 15:04 pdo_sqlite.so

-rwxr-xr-x 1 root root  272112 Apr 12 15:04 phar.so

-rwxr-xr-x 1 root root   51472 Apr 12 15:04 sqlite3.so

-rwxr-xr-x 1 root root   58496 Apr 12 15:04 zip.so

 

要讓PHP以FastCGI的方式與nginx進行互動,需要有PHP-FPM模組的支援。

 安裝PHP-FPM

1

[[email protected] ~]# yum -y install php-fpm

 

1

2

3

4

[[email protected] ~]# php-fpm -v

PHP 5.4.16 (fpm-fcgi) (built: Apr 12 2018 19:03:25)

Copyright (c) 1997-2013 The PHP Group

Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies

啟動PHP-FPM

1

[[email protected] ~]# systemctl start php-fpm

以上安裝完成後,接下來,配置Nginx支援PHP(FastCGI方式)。

修改 /usr/local/nginx/conf/nginx.conf 把如下圖紅色框中的#去掉就可以了。

這裡面都是預設的,root是配置php程式放置的根目錄。

還需要修改的就是fastcgi_param中的/scripts為$document_root

 

修改完成後,讓nginx重新載入配置以生效:

1

[[email protected] ~]# /usr/local/nginx/sbin/nginx -s reload

測試

1

2

3

4

5

6

7

[[email protected] ~]# cd /usr/local/nginx/html/

[[email protected] html]# touch index.php

[[email protected] html]# vim index.php

[[email protected] html]# cat index.php

<?php 

phpinfo(); 

?>