【CentOS 7架构20】,LNMP模式安装php#180103

本文详细介绍了在LAMP环境下安装配置PHP-FPM服务的过程,包括解决依赖问题、编译安装、配置启动参数及服务初始化等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

shallow丿ove


PHP安装

  • 和LAMP安装PHP方法有差别,需要开启php-fpm服务
  • cd /usr/local/src
  • wegt http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz
  • tar zxf php-5.6.30.tar.gz
  • useeradd -s /sbin/nologin php-fpm
  • cd php-5.6.30
  • ./configure --prefix=usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
  • make && make install
  • cp php.ini-production /usr/local/php-fpm/etc/php.ini
  • vi /usr/local/php/etc/php-fpm.conf
  • cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  • chmod 755 /etc/init.d/php-fpm
  • chkconfig --add php-fpm
  • chkconfig php-fpm on
  • service php-fpm start
  • ps aux | grep php-fpm
[root@localhost mysql]# cd /usr/local/src/
[root@localhost src]# ls
apr-1.6.3           httpd-2.2.34         mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz  php-7.1.6
apr-1.6.3.tar.gz    httpd-2.2.34.tar.gz  mysql-5.6.36-linux-glibc2.5-x86_64.tar.gz     php-7.1.6.tar
apr-util-1.6.1      httpd-2.4.29         php-5.6.30                                    phpredis-develop
apr-util-1.6.1.tar  httpd-2.4.29.tar.gz  php-5.6.30.tar                                phpredis-develop.zip
[root@localhost src]# cd php-5.6.30/
[root@localhost php-5.6.30]# 

清除编译过的文件

[root@localhost php-5.6.30]# make clean
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f 
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp5.la sapi/cli/php sapi/cgi/php-cgi    libphp5.la modules/* libs/*

[root@localhost php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl

报错 checking for cURL in default path... not found

[root@localhost php-5.6.30]# yum -y install libcurl-devel
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                     | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                                     | 7.5 kB  00:00:00     
epel                                                                                                     | 4.7 kB  00:00:00     
extras                                                                                                   | 3.4 kB  00:00:00     
updates                                                                                                  | 3.4 kB  00:00:00     
(1/4): updates/7/x86_64/primary_db                                                                       | 4.6 MB  00:00:01     
(2/4): epel/x86_64/group_gz                                                                              | 266 kB  00:00:01     
(3/4): epel/x86_64/updateinfo                                                                            | 865 kB  00:00:05     
epel/x86_64/primary_db         FAILED                                          
https://ftp.yzu.edu.tw/Linux/Fedora-EPEL/7/x86_64/repodata/d296e319c1d4642168425d74fd9dd7c58588812c456b3aaa31833c8639de11ba-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to ftp.yzu.edu.tw:443; Connection refused"
Trying other mirror.
(4/4): epel/x86_64/primary_db                                                                            | 6.2 MB  00:00:05     
Determining fastest mirrors
 * epel: mirror.dmmlabs.jp
Resolving Dependencies
--> Running transaction check
---> Package libcurl-devel.x86_64 0:7.29.0-42.el7_4.1 will be installed
updates/7/x86_64/filelists_db                                                                            | 2.8 MB  00:00:00     
--> Processing Dependency: libcurl = 7.29.0-42.el7_4.1 for package: libcurl-devel-7.29.0-42.el7_4.1.x86_64
--> Running transaction check
---> Package libcurl.x86_64 0:7.29.0-19.el7 will be updated
--> Processing Dependency: libcurl = 7.29.0-19.el7 for package: curl-7.29.0-19.el7.x86_64
---> Package libcurl.x86_64 0:7.29.0-42.el7_4.1 will be an update
--> Running transaction check
---> Package curl.x86_64 0:7.29.0-19.el7 will be updated
---> Package curl.x86_64 0:7.29.0-42.el7_4.1 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================================================================
 Package                         Arch                     Version                               Repository                 Size
================================================================================================================================
Installing:
 libcurl-devel                   x86_64                   7.29.0-42.el7_4.1                     updates                   300 k
Updating for dependencies:
 curl                            x86_64                   7.29.0-42.el7_4.1                     updates                   267 k
 libcurl                         x86_64                   7.29.0-42.el7_4.1                     updates                   219 k

Transaction Summary
================================================================================================================================
Install  1 Package
Upgrade             ( 2 Dependent packages)

Total download size: 786 k
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/3): libcurl-7.29.0-42.el7_4.1.x86_64.rpm                                                              | 219 kB  00:00:00     
(2/3): libcurl-devel-7.29.0-42.el7_4.1.x86_64.rpm                                                        | 300 kB  00:00:00     
(3/3): curl-7.29.0-42.el7_4.1.x86_64.rpm                                                                 | 267 kB  00:00:00     
--------------------------------------------------------------------------------------------------------------------------------
Total                                                                                           1.0 MB/s | 786 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libcurl-7.29.0-42.el7_4.1.x86_64                                                                             1/5 
  Updating   : curl-7.29.0-42.el7_4.1.x86_64                                                                                2/5 
  Installing : libcurl-devel-7.29.0-42.el7_4.1.x86_64                                                                       3/5 
  Cleanup    : curl-7.29.0-19.el7.x86_64                                                                                    4/5 
  Cleanup    : libcurl-7.29.0-19.el7.x86_64                                                                                 5/5 
  Verifying  : curl-7.29.0-42.el7_4.1.x86_64                                                                                1/5 
  Verifying  : libcurl-devel-7.29.0-42.el7_4.1.x86_64                                                                       2/5 
  Verifying  : libcurl-7.29.0-42.el7_4.1.x86_64                                                                             3/5 
  Verifying  : curl-7.29.0-19.el7.x86_64                                                                                    4/5 
  Verifying  : libcurl-7.29.0-19.el7.x86_64                                                                                 5/5 

Installed:
  libcurl-devel.x86_64 0:7.29.0-42.el7_4.1                                                                                      

Dependency Updated:
  curl.x86_64 0:7.29.0-42.el7_4.1                               libcurl.x86_64 0:7.29.0-42.el7_4.1                              

Complete!

[root@localhost php-5.6.30]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
	#

[root@localhost php-5.6.30]# echo $?
0
[root@localhost php-5.6.30]# make && make install
	#

[root@localhost php-5.6.30]# echo $?
0

[root@localhost php-5.6.30]# ls /usr/local/php-fpm/
bin  etc  include  lib  php  sbin  var
[root@localhost php-5.6.30]# ls /usr/local/php/
bin  etc  include  lib  php
[root@localhost php-5.6.30]# ls /usr/local/php-fpm/sbin/
php-fpm

php-fpm就是启动php-fpm服务的,而/var/log/存放日志/var/run/存放pid

[root@localhost php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -m
[PHP Modules]
cgi-fcgi
Core
ctype
curl
date
dom
ereg
exif
fileinfo
filter
ftp
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

[root@localhost php-5.6.30]# /usr/local/php-fpm/sbin/php-fpm -t
[03-Jan-2018 09:57:37] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2)
[03-Jan-2018 09:57:37] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf'
[03-Jan-2018 09:57:37] ERROR: FPM initialization failed

[root@localhost php-5.6.30]# ls /usr/local/php-fpm/etc/
pear.conf  php-fpm.conf.default
[root@localhost php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini

production适用于生产环境

[root@localhost etc]# vi php-fpm.conf
      1 [global]
      2 pid = /usr/local/php-fpm/var/run/php-fpm.pid
      3 error_log = /usr/local/php-fpm/var/log/php-fpm.log
      4 [www]
      5 listen = /tmp/php-fcgi.sock
      6 listen.mode = 666
      7 user = php-fpm
      8 group = php-fpm
      9 pm = dynamic
     10 pm.max_children = 50
     11 pm.start_servers = 20
     12 pm.min_spare_servers = 5
     13 pm.max_spare_servers = 35
     14 pm.max_requests = 500
     15 rlimit_files = 1024

[root@localhost etc]# cd /usr/local/src/php-5.6.30/
[root@localhost php-5.6.30]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@localhost php-5.6.30]# chmod 755 /etc/init.d/php-fpm 
[root@localhost php-5.6.30]# chkconfig --add php-fpm
[root@localhost php-5.6.30]# chkconfig php-fpm on
[root@localhost php-5.6.30]# useradd php-fpm
[root@localhost php-5.6.30]# service php-fpm start
Starting php-fpm  done

[root@localhost php-5.6.30]# ps aux | grep php-fpm
root       3234  0.1  0.2 123604  4948 ?        Ss   09:24   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm    3235  0.0  0.2 123604  4716 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3236  0.0  0.2 123604  4716 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3237  0.0  0.2 123604  4716 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3238  0.0  0.2 123604  4716 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3239  0.0  0.2 123604  4720 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3240  0.0  0.2 123604  4720 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3241  0.0  0.2 123604  4720 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3242  0.0  0.2 123604  4720 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3243  0.0  0.2 123604  4720 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3244  0.0  0.2 123604  4720 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3245  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3246  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3247  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3248  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3249  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3250  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3251  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3252  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3253  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
php-fpm    3254  0.0  0.2 123604  4724 ?        S    09:24   0:00 php-fpm: pool www
root       3256  0.0  0.0 112660   976 pts/0    S+   09:24   0:00 grep --color=auto php-fpm


转载于:https://my.oschina.net/u/3892756/blog/3069360

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值