帮助文档>Linux实用技巧 > Centos7如何安装php

Centos7如何安装php

发布时间:2021-09-24 04:23

Centos7如何安装php?本教程以Centos7系统为例

本配置适用于centos7版本

1.安装vim编辑工具

yum install vim -y

 

2.安装lrzsz上传工具

yum install lrzsz -y

安装完后可以使用rz命令上传所需要的软件工具(最好进入家目录/home在上传方便以后查找)

3.指定环境版本和上传环境安装包

php5.6.6.tar具体版本不一定,这边只是随机安装1个版本,具体看需要什么版本

安装关联包

yum -y install libxml2-devel

yum -y install bzip2 bzip2-devel

yum -y install curl-devel

yum -y install libjpeg-devel

yum -y install libpng-devel

yum -y install freetype-devel

yum -y install libmcrypt-devel

4.安装php5.6.6.tar

4.1进入上传文件目录解压php5.6.6.tar文件

[root@vt178m5c home]# tar jxf php5.6.6.tar.bz2

4.2进入php5.6.6解压文件开始编译安装php

[root@vt178m5c home]# cd php-5.6.6

[root@vt178m5c php-5.6.6]# ./configure \

--prefix=/usr/local/php \

--with-config-file-path=/usr/local/php \

--with-bz2 \

--with-curl --with-curlwrappers --enable-ftp --enable-sockets --disable-ipv6 --with-gd \

--with-mcrypt --with-mhash \

--with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-iconv-dir \

--enable-mbstring --enable-calendar --enable-fpm --with-gettext --with-libxml-dir=/usr/local \

--with-zlib --enable-zend-multibyte --with-pdo-mysql=/usr/local/mysql \

--with-mysqli=/usr/local/mysql/bin/mysql_config \

--with-mysql=/usr/local/mysql

4.3编译完确认没有报错后开始安装php

make && make install

4.4拷贝php配置文件到所安装的phplib目录下命名为php.ini

[root@vt178m5c php-5.6.6]# cp php.ini-production /usr/local/php/lib/php.ini

4.5进入php-fpm配置文件

[root@vt178m5c php-5.6.6]# cd /usr/local/php/etc/

4.6拷贝php-fpm.conf.default文件,新副本命名为php-fpm.conf

[root@vt178m5c etc]# cp php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

4.7修改php-fpm配置文件开启php-fpm.pid

[root@svbkq091 etc]# vim /usr/local/php/etc/php-fpm.conf

找到

;pid = run/php-fpm.pid

删掉注释

pid = run/php-fpm.pid

4.8编写php-fpm启动脚本

[root@svbkq091 etc]# vim /etc/init.d/php-fpm

脚本代码:

#!/bin/bash

#

# Startup script for the PHP-FPM server.

#

# chkconfig: 345 85 15

# description: PHP is an HTML-embedded scripting language

# processname: php-fpm

# config: /usr/local/php/lib/php.ini

# Source function library.

. /etc/rc.d/init.d/functions

PHP_PATH=/usr/local

DESC="php-fpm daemon"

NAME=php-fpm

# php-fpm路径

DAEMON=$PHP_PATH/php/sbin/$NAME

# 配置文件路径

CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf

# PID文件路径(在php-fpm.conf设置)

PIDFILE=$PHP_PATH/php/var/run/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.

test -x $DAEMON || exit 0



rh_start() {

$DAEMON -y $CONFIGFILE || echo -n " already running"

}

rh_stop() {

kill -QUIT `cat $PIDFILE` || echo -n " not running"

}

rh_reload() {

kill -HUP `cat $PIDFILE` || echo -n " can't reload"

}

case "$1" in

start)

echo -n "Starting $DESC: $NAME"

rh_start

echo "."

;;

stop)

echo -n "Stopping $DESC: $NAME"

rh_stop

echo "."

;;

reload)

echo -n "Reloading $DESC configuration..."

rh_reload

echo "reloaded."

;;

restart)

echo -n "Restarting $DESC: $NAME"

rh_stop

sleep 1

rh_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2

exit 3

;;

esac

exit 0

编写完脚本记得修改下脚本权限

[root@svbkq091 etc]# chmod 755 /etc/init.d/php-fpm

4.9 php-fpm启动|停止|重启

[root@svbkq091 etc]# /etc/init.d/php-fpm start 启动php-fpm

[root@svbkq091 etc]# /etc/init.d/php-fpm stop 关闭php-fpm

[root@svbkq091 etc]# /etc/init.d/php-fpm restart 重启php-fpm

 

本文导读

客户热线:13306992629

客户服务中心
Baidu
map