查看yum的可安装的php版本列表:

    1. yum provides php

    安装PHP+php-fpm

    1. yum update
    2. #更新源
    3. rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
    4. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    5. yum install -y php72w php72w-opcache php72w-xml php72w-mcrypt php72w-gd php72w-devel php72w-mysql php72w-intl php72w-pecl-redis php72w-mbstring php72w-json php72w-fpm
    6. rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    7. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
    8. yum -y install php72w php72w-cli php72w-fpm php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

    PHP扩展

    1. php72w-cli
    2. php72w-common
    3. php72w-devel
    4. php72w-embedded
    5. php72w-fpm
    6. php72w-gd
    7. php72w-mbstring
    8. php72w-mysqlnd
    9. php72w-opcache
    10. php72w-pdo
    11. php72w-xml
    12. php72w
    13. php72w-bcmath
    14. php72w-dba
    15. php72w-enchant
    16. php72w-imap
    17. php72w-interbase
    18. php72w-intl
    19. php72w-ldap
    20. php72w-mcrypt
    21. php72w-odbc
    22. php72w-pdo_dblib
    23. php72w-pear
    24. php72w-pecl-apcu
    25. php72w-pecl-imagick
    26. php72w-pecl-xdebug
    27. php72w-pgsql
    28. php72w-phpdbg
    29. php72w-process
    30. php72w-pspell
    31. php72w-recode
    32. php72w-snmp
    33. php72w-soap
    34. php72w-tidy
    35. php72w-xmlrpc
    36. php72w-pecl-igbinary
    37. php72w-intl
    38. php72w-memcached
    39. php72w-pecl-mongodb
    40. php72w-pecl-redis

    修改php-fpm配置 /etc/php-fpm.d/www.conf
    定义 listen 相关参数 socket owner group 等
    nginx中fastcgi 需要proxy_pass 需要与此socket保持一致

    1. ; Start a new pool named 'www'.
    2. ; the variable $pool can we used in any directive and will be replaced by the
    3. ; pool name ('www' here)
    4. [www]
    5. ; Per pool prefix
    6. ; It only applies on the following directives:
    7. ; - 'access.log'
    8. ; - 'slowlog'
    9. ; - 'listen' (unixsocket)
    10. ; - 'chroot'
    11. ; - 'chdir'
    12. ; - 'php_values'
    13. ; - 'php_admin_values'
    14. ; When not set, the global prefix (or @php_fpm_prefix@) applies instead.
    15. ; Note: This directive can also be relative to the global prefix.
    16. ; Default Value: none
    17. ;prefix = /path/to/pools/$pool
    18. ; Unix user/group of processes
    19. ; Note: The user is mandatory. If the group is not set, the default user's group
    20. ; will be used.
    21. ; RPM: apache user chosen to provide access to the same directories as httpd
    22. user = apache
    23. ; RPM: Keep a group allowed to write in log dir.
    24. group = apache
    25. ; The address on which to accept FastCGI requests.
    26. ; Valid syntaxes are:
    27. ; 'ip.add.re.ss:port' - to listen on a TCP socket to a specific IPv4 address on
    28. ; a specific port;
    29. ; '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
    30. ; a specific port;
    31. ; 'port' - to listen on a TCP socket to all addresses
    32. ; (IPv6 and IPv4-mapped) on a specific port;
    33. ; '/path/to/unix/socket' - to listen on a unix socket.
    34. ; Note: This value is mandatory.
    35. ;listen = /run/php-fpm/www.sock
    36. ;listen = 127.0.0.1:9000
    37. listen = /dev/shm/php-fpm.sock
    38. listen.owner = nginx
    39. listen.group = nginx
    40. listen.mode = 0666
    41. user = nginx
    42. group = nginx
    43. ; Set listen(2) backlog.
    44. ; Default Value: 511
    45. ;listen.backlog = 511
    46. ; Set permissions for unix socket, if one is used. In Linux, read/write
    47. ; permissions must be set in order to allow connections from a web server.
    48. ; Default Values: user and group are set as the running user
    49. ; mode is set to 0660
    50. ;listen.owner = nobody
    51. ;listen.group = nobody
    52. ;listen.mode = 0660
    53. ; When POSIX Access Control Lists are supported you can set them using
    54. ; these options, value is a comma separated list of user/group names.
    55. ; When set, listen.owner and listen.group are ignored
    56. listen.acl_users = apache,nginx
    57. ;listen.acl_groups =
    58. ; List of addresses (IPv4/IPv6) of FastCGI clients which are allowed to connect.
    59. ; Equivalent to the FCGI_WEB_SERVER_ADDRS environment variable in the original
    60. ; PHP FCGI (5.2.2+). Makes sense only with a tcp listening socket. Each address
    61. ; must be separated by a comma. If this value is left blank, connections will be
    62. ; accepted from any ip address.
    63. ; Default Value: any
    64. listen.allowed_clients = 127.0.0.1
    65. ; Specify the nice(2) priority to apply to the pool processes (only if set)
    66. ; The value can vary from -19 (highest priority) to 20 (lower priority)
    67. ; Note: - It will only work if the FPM master process is launched as root
    68. ; - The pool processes will inherit the master process priority
    69. ; unless it specified otherwise
    70. ; Default Value: no set
    71. ; process.priority = -19
    72. ; Set the process dumpable flag (PR_SET_DUMPABLE prctl) even if the process user
    73. ; or group is differrent than the master process user. It allows to create process
    74. ; core dump and ptrace the process for the pool user.
    75. ; Default Value: no
    76. ; process.dumpable = yes
    77. ; Choose how the process manager will control the number of child processes.
    78. ; Possible Values:
    79. ; static - a fixed number (pm.max_children) of child processes;
    80. ; dynamic - the number of child processes are set dynamically based on the
    81. ; following directives. With this process management, there will be
    82. ; always at least 1 children.
    83. ; pm.max_children - the maximum number of children that can
    84. ; be alive at the same time.
    85. ; pm.start_servers - the number of children created on startup.
    86. ; pm.min_spare_servers - the minimum number of children in 'idle'
    87. ; state (waiting to process). If the number
    88. ; of 'idle' processes is less than this
    89. ; number then some children will be created.
    90. ; pm.max_spare_servers - the maximum number of children in 'idle'
    91. ; state (waiting to process). If the number
    92. ; of 'idle' processes is greater than this
    93. ; number then some children will be killed.
    94. ; ondemand - no children are created at startup. Children will be forked when
    95. ; new requests will connect. The following parameter are used:
    96. ; pm.max_children - the maximum number of children that
    97. ; can be alive at the same time.
    98. ; pm.process_idle_timeout - The number of seconds after which
    99. ; an idle process will be killed.
    100. ; Note: This value is mandatory.
    101. pm = dynamic
    102. ; The number of child processes to be created when pm is set to 'static' and the
    103. ; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
    104. ; This value sets the limit on the number of simultaneous requests that will be
    105. ; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
    106. ; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
    107. ; CGI. The below defaults are based on a server without much resources. Don't
    108. ; forget to tweak pm.* to fit your needs.
    109. ; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
    110. ; Note: This value is mandatory.
    111. pm.max_children = 50
    112. ; The number of child processes created on startup.
    113. ; Note: Used only when pm is set to 'dynamic'
    114. ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
    115. pm.start_servers = 5
    116. ; The desired minimum number of idle server processes.
    117. ; Note: Used only when pm is set to 'dynamic'
    118. ; Note: Mandatory when pm is set to 'dynamic'
    119. pm.min_spare_servers = 5
    120. ; The desired maximum number of idle server processes.
    121. ; Note: Used only when pm is set to 'dynamic'
    122. ; Note: Mandatory when pm is set to 'dynamic'
    123. pm.max_spare_servers = 35
    124. ; The number of seconds after which an idle process will be killed.
    125. ; Note: Used only when pm is set to 'ondemand'
    126. ; Default Value: 10s
    127. ;pm.process_idle_timeout = 10s;
    128. ; The number of requests each child process should execute before respawning.
    129. ; This can be useful to work around memory leaks in 3rd party libraries. For
    130. ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS.
    131. ; Default Value: 0
    132. ;pm.max_requests = 500
    133. ; The URI to view the FPM status page. If this value is not set, no URI will be
    134. ; recognized as a status page. It shows the following informations:
    135. ; pool - the name of the pool;
    136. ; process manager - static, dynamic or ondemand;
    137. ; start time - the date and time FPM has started;
    138. ; start since - number of seconds since FPM has started;
    139. ; accepted conn - the number of request accepted by the pool;
    140. ; listen queue - the number of request in the queue of pending
    141. ; connections (see backlog in listen(2));
    142. ; max listen queue - the maximum number of requests in the queue
    143. ; of pending connections since FPM has started;
    144. ; listen queue len - the size of the socket queue of pending connections;
    145. ; idle processes - the number of idle processes;
    146. ; active processes - the number of active processes;
    147. ; total processes - the number of idle + active processes;
    148. ; max active processes - the maximum number of active processes since FPM
    149. ; has started;
    150. ; max children reached - number of times, the process limit has been reached,
    151. ; when pm tries to start more children (works only for
    152. ; pm 'dynamic' and 'ondemand');
    153. ; Value are updated in real time.
    154. ; Example output:
    155. ; pool: www
    156. ; process manager: static
    157. ; start time: 01/Jul/2011:17:53:49 +0200
    158. ; start since: 62636
    159. ; accepted conn: 190460
    160. ; listen queue: 0
    161. ; max listen queue: 1
    162. ; listen queue len: 42
    163. ; idle processes: 4
    164. ; active processes: 11
    165. ; total processes: 15
    166. ; max active processes: 12
    167. ; max children reached: 0
    168. ;
    169. ; By default the status page output is formatted as text/plain. Passing either
    170. ; 'html', 'xml' or 'json' in the query string will return the corresponding
    171. ; output syntax. Example:
    172. ; http://www.foo.bar/status
    173. ; http://www.foo.bar/status?json
    174. ; http://www.foo.bar/status?html
    175. ; http://www.foo.bar/status?xml
    176. ;
    177. ; By default the status page only outputs short status. Passing 'full' in the
    178. ; query string will also return status for each pool process.
    179. ; Example:
    180. ; http://www.foo.bar/status?full
    181. ; http://www.foo.bar/status?json&full
    182. ; http://www.foo.bar/status?html&full
    183. ; http://www.foo.bar/status?xml&full
    184. ; The Full status returns for each process:
    185. ; pid - the PID of the process;
    186. ; state - the state of the process (Idle, Running, ...);
    187. ; start time - the date and time the process has started;
    188. ; start since - the number of seconds since the process has started;
    189. ; requests - the number of requests the process has served;
    190. ; request duration - the duration in µs of the requests;
    191. ; request method - the request method (GET, POST, ...);
    192. ; request URI - the request URI with the query string;
    193. ; content length - the content length of the request (only with POST);
    194. ; user - the user (PHP_AUTH_USER) (or '-' if not set);
    195. ; script - the main script called (or '-' if not set);
    196. ; last request cpu - the %cpu the last request consumed
    197. ; it's always 0 if the process is not in Idle state
    198. ; because CPU calculation is done when the request
    199. ; processing has terminated;
    200. ; last request memory - the max amount of memory the last request consumed
    201. ; it's always 0 if the process is not in Idle state
    202. ; because memory calculation is done when the request
    203. ; processing has terminated;
    204. ; If the process is in Idle state, then informations are related to the
    205. ; last request the process has served. Otherwise informations are related to
    206. ; the current request being served.
    207. ; Example output:
    208. ; ************************
    209. ; pid: 31330
    210. ; state: Running
    211. ; start time: 01/Jul/2011:17:53:49 +0200
    212. ; start since: 63087
    213. ; requests: 12808
    214. ; request duration: 1250261
    215. ; request method: GET
    216. ; request URI: /test_mem.php?N=10000
    217. ; content length: 0
    218. ; user: -
    219. ; script: /home/fat/web/docs/php/test_mem.php
    220. ; last request cpu: 0.00
    221. ; last request memory: 0
    222. ;
    223. ; Note: There is a real-time FPM status monitoring sample web page available
    224. ; It's available in: @EXPANDED_DATADIR@/fpm/status.html
    225. ;
    226. ; Note: The value must start with a leading slash (/). The value can be
    227. ; anything, but it may not be a good idea to use the .php extension or it
    228. ; may conflict with a real PHP file.
    229. ; Default Value: not set
    230. ;pm.status_path = /status
    231. ; The ping URI to call the monitoring page of FPM. If this value is not set, no
    232. ; URI will be recognized as a ping page. This could be used to test from outside
    233. ; that FPM is alive and responding, or to
    234. ; - create a graph of FPM availability (rrd or such);
    235. ; - remove a server from a group if it is not responding (load balancing);
    236. ; - trigger alerts for the operating team (24/7).
    237. ; Note: The value must start with a leading slash (/). The value can be
    238. ; anything, but it may not be a good idea to use the .php extension or it
    239. ; may conflict with a real PHP file.
    240. ; Default Value: not set
    241. ;ping.path = /ping
    242. ; This directive may be used to customize the response of a ping request. The
    243. ; response is formatted as text/plain with a 200 response code.
    244. ; Default Value: pong
    245. ;ping.response = pong
    246. ; The access log file
    247. ; Default: not set
    248. ;access.log = log/$pool.access.log
    249. ; The access log format.
    250. ; The following syntax is allowed
    251. ; %%: the '%' character
    252. ; %C: %CPU used by the request
    253. ; it can accept the following format:
    254. ; - %{user}C for user CPU only
    255. ; - %{system}C for system CPU only
    256. ; - %{total}C for user + system CPU (default)
    257. ; %d: time taken to serve the request
    258. ; it can accept the following format:
    259. ; - %{seconds}d (default)
    260. ; - %{miliseconds}d
    261. ; - %{mili}d
    262. ; - %{microseconds}d
    263. ; - %{micro}d
    264. ; %e: an environment variable (same as $_ENV or $_SERVER)
    265. ; it must be associated with embraces to specify the name of the env
    266. ; variable. Some exemples:
    267. ; - server specifics like: %{REQUEST_METHOD}e or %{SERVER_PROTOCOL}e
    268. ; - HTTP headers like: %{HTTP_HOST}e or %{HTTP_USER_AGENT}e
    269. ; %f: script filename
    270. ; %l: content-length of the request (for POST request only)
    271. ; %m: request method
    272. ; %M: peak of memory allocated by PHP
    273. ; it can accept the following format:
    274. ; - %{bytes}M (default)
    275. ; - %{kilobytes}M
    276. ; - %{kilo}M
    277. ; - %{megabytes}M
    278. ; - %{mega}M
    279. ; %n: pool name
    280. ; %o: output header
    281. ; it must be associated with embraces to specify the name of the header:
    282. ; - %{Content-Type}o
    283. ; - %{X-Powered-By}o
    284. ; - %{Transfert-Encoding}o
    285. ; - ....
    286. ; %p: PID of the child that serviced the request
    287. ; %P: PID of the parent of the child that serviced the request
    288. ; %q: the query string
    289. ; %Q: the '?' character if query string exists
    290. ; %r: the request URI (without the query string, see %q and %Q)
    291. ; %R: remote IP address
    292. ; %s: status (response code)
    293. ; %t: server time the request was received
    294. ; it can accept a strftime(3) format:
    295. ; %d/%b/%Y:%H:%M:%S %z (default)
    296. ; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
    297. ; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
    298. ; %T: time the log has been written (the request has finished)
    299. ; it can accept a strftime(3) format:
    300. ; %d/%b/%Y:%H:%M:%S %z (default)
    301. ; The strftime(3) format must be encapsuled in a %{<strftime_format>}t tag
    302. ; e.g. for a ISO8601 formatted timestring, use: %{%Y-%m-%dT%H:%M:%S%z}t
    303. ; %u: remote user
    304. ;
    305. ; Default: "%R - %u %t \"%m %r\" %s"
    306. ;access.format = "%R - %u %t \"%m %r%Q%q\" %s %f %{mili}d %{kilo}M %C%%"
    307. ; The log file for slow requests
    308. ; Default Value: not set
    309. ; Note: slowlog is mandatory if request_slowlog_timeout is set
    310. slowlog = /var/log/php-fpm/www-slow.log
    311. ; The timeout for serving a single request after which a PHP backtrace will be
    312. ; dumped to the 'slowlog' file. A value of '0s' means 'off'.
    313. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    314. ; Default Value: 0
    315. ;request_slowlog_timeout = 0
    316. ; The timeout for serving a single request after which the worker process will
    317. ; be killed. This option should be used when the 'max_execution_time' ini option
    318. ; does not stop script execution for some reason. A value of '0' means 'off'.
    319. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
    320. ; Default Value: 0
    321. ;request_terminate_timeout = 0
    322. ; Set open file descriptor rlimit.
    323. ; Default Value: system defined value
    324. ;rlimit_files = 1024
    325. ; Set max core size rlimit.
    326. ; Possible Values: 'unlimited' or an integer greater or equal to 0
    327. ; Default Value: system defined value
    328. ;rlimit_core = 0
    329. ; Chroot to this directory at the start. This value must be defined as an
    330. ; absolute path. When this value is not set, chroot is not used.
    331. ; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
    332. ; of its subdirectories. If the pool prefix is not set, the global prefix
    333. ; will be used instead.
    334. ; Note: chrooting is a great security feature and should be used whenever
    335. ; possible. However, all PHP paths will be relative to the chroot
    336. ; (error_log, sessions.save_path, ...).
    337. ; Default Value: not set
    338. ;chroot =
    339. ; Chdir to this directory at the start.
    340. ; Note: relative path can be used.
    341. ; Default Value: current directory or / when chroot
    342. ;chdir = /var/www
    343. ; Redirect worker stdout and stderr into main error log. If not set, stdout and
    344. ; stderr will be redirected to /dev/null according to FastCGI specs.
    345. ; Note: on highloaded environement, this can cause some delay in the page
    346. ; process time (several ms).
    347. ; Default Value: no
    348. ;catch_workers_output = yes
    349. ; Clear environment in FPM workers
    350. ; Prevents arbitrary environment variables from reaching FPM worker processes
    351. ; by clearing the environment in workers before env vars specified in this
    352. ; pool configuration are added.
    353. ; Setting to "no" will make all environment variables available to PHP code
    354. ; via getenv(), $_ENV and $_SERVER.
    355. ; Default Value: yes
    356. ;clear_env = no
    357. ; Limits the extensions of the main script FPM will allow to parse. This can
    358. ; prevent configuration mistakes on the web server side. You should only limit
    359. ; FPM to .php extensions to prevent malicious users to use other extensions to
    360. ; exectute php code.
    361. ; Note: set an empty value to allow all extensions.
    362. ; Default Value: .php
    363. ;security.limit_extensions = .php .php3 .php4 .php5 .php7
    364. ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from
    365. ; the current environment.
    366. ; Default Value: clean env
    367. ;env[HOSTNAME] = $HOSTNAME
    368. ;env[PATH] = /usr/local/bin:/usr/bin:/bin
    369. ;env[TMP] = /tmp
    370. ;env[TMPDIR] = /tmp
    371. ;env[TEMP] = /tmp
    372. ; Additional php.ini defines, specific to this pool of workers. These settings
    373. ; overwrite the values previously defined in the php.ini. The directives are the
    374. ; same as the PHP SAPI:
    375. ; php_value/php_flag - you can set classic ini defines which can
    376. ; be overwritten from PHP call 'ini_set'.
    377. ; php_admin_value/php_admin_flag - these directives won't be overwritten by
    378. ; PHP call 'ini_set'
    379. ; For php_*flag, valid values are on, off, 1, 0, true, false, yes or no.
    380. ; Defining 'extension' will load the corresponding shared extension from
    381. ; extension_dir. Defining 'disable_functions' or 'disable_classes' will not
    382. ; overwrite previously defined php.ini values, but will append the new value
    383. ; instead.
    384. ; Note: path INI options can be relative and will be expanded with the prefix
    385. ; (pool, global or @prefix@)
    386. ; Default Value: nothing is defined by default except the values in php.ini and
    387. ; specified at startup with the -d argument
    388. ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com
    389. ;php_flag[display_errors] = off
    390. php_admin_value[error_log] = /var/log/php-fpm/www-error.log
    391. php_admin_flag[log_errors] = on
    392. ;php_admin_value[memory_limit] = 128M
    393. ; Set the following data paths to directories owned by the FPM process user.
    394. ;
    395. ; Do not change the ownership of existing system directories, if the process
    396. ; user does not have write permission, create dedicated directories for this
    397. ; purpose.
    398. ;
    399. ; See warning about choosing the location of these directories on your system
    400. ; at http://php.net/session.save-path
    401. php_value[session.save_handler] = files
    402. php_value[session.save_path] = /var/lib/php/session
    403. php_value[soap.wsdl_cache_dir] = /var/lib/php/wsdlcache
    404. ;php_value[opcache.file_cache] = /var/lib/php/opcache

    启动php-fpm

    1. systemclt start php-fpm