centos7.4之php安裝

環境:CentOS 7.4.1708php

1、檢查當前系統是否已經安裝PHPhtml

[root@localhost ~]# rpm -qa php  

2、查看yum是否有可安裝的PHP軟件mysql

[root@localhost ~]# 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

3、安裝PHPnginx

[root@localhost ~]# yum -y install php

4、查看版本及支持的擴展web

[root@localhost ~]# 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
[root@localhost ~]# 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]
[root@localhost ~]# 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
[root@localhost ~]# 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

5、安裝php-mysqlndsql

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

[root@localhost ~]# 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 <mysql-build@oss.oracle.com>
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插件vim

[root@localhost ~]# yum -y install php-mysqlnd

  

[root@localhost ~]# 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
[root@localhost ~]# 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模塊的支持。session

 安裝PHP-FPMoracle

[root@localhost ~]# yum -y install php-fpm

 

[root@localhost ~]# 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

[root@localhost ~]# systemctl start php-fpm 
以上安裝完成後,接下來,配置Nginx支持PHP(FastCGI方式)。

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

這裏面都是默認的,root是配置php程序放置的根目錄。

還須要修改的就是fastcgi_param中的/scripts爲$document_root

 

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

[root@localhost ~]# /usr/local/nginx/sbin/nginx -s reload

測試

[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# touch index.php
[root@localhost html]# vim index.php 
[root@localhost html]# cat index.php 
<?php  
phpinfo();  
?> 

相關文章
相關標籤/搜索