linux之centos7中安装php7 后面有systemctl管理文件php-fpm.service
安装gcc gcc-c++ wget
安装gcc gcc-c++ wget
yum -y install gcc gcc-c++ wget
1
yum-yinstallgccgcc-c++wget
.安装一些库
安装php库
yum -y install php-mcrypt libmcrypt-devel libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
1
yum-yinstallphp-mcryptlibmcrypt-devellibxml2libxml2-developensslopenssl-develcurl-devellibjpeg-devellibpng-develfreetype-devellibmcrypt-devel
wget PHP7的下载地址
下载php7.0.0rc5
wget https://downloads.php.net/~ab/php-7.0.0RC5.tar.gz
1
wgethttps://downloads.php.net/~ab/php-7.0.0RC5.tar.gz
下载后解压进入目录
解压php
tar zxvf php-7.0.0RC5.tar.gz
1
tarzxvfphp-7.0.0RC5.tar.gz
进入php目录
cd php-7.0.0RC5
1
cdphp-7.0.0RC5
# 配置参数
./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-mcrypt=/usr/include \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-mysql-sock=/tmp/mysql.sock \
--enable-mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--with-openssl \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir
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
./configure--prefix=/usr/local/php7\
--with-config-file-path=/usr/local/php7/etc\
--with-mcrypt=/usr/include\
--with-mysqli=mysqlnd\
--with-pdo-mysql=mysqlnd\
--with-mysql-sock=/tmp/mysql.sock\
--enable-mysqlnd\
--with-gd\
--with-iconv\
--with-zlib\
--enable-bcmath\
--enable-shmop\
--enable-sysvsem\
--enable-inline-optimization\
--enable-mbregex\
--enable-fpm\
--enable-mbstring\
--enable-ftp\
--enable-gd-native-ttf\
--with-openssl\
--enable-pcntl\
--enable-sockets\
--with-xmlrpc\
--enable-zip\
--enable-soap\
--with-gettext\
--with-curl\
--with-jpeg-dir\
--with-freetype-dir
编译
make php编译php
make
1
make
安装
安装php
make install
1
makeinstall
复制php.ini
配置安装好的php
cp php.ini-production /usr/local/php7/etc/php.ini
1
cpphp.ini-production/usr/local/php7/etc/php.ini
复制php-fpm.conf
复php-fpm.conf
cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
1
cp/usr/local/php7/etc/php-fpm.conf.default/usr/local/php7/etc/php-fpm.conf
复制php-fpm下的conf
复php-fpm下的conf
cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
1
cp/usr/local/php7/etc/php-fpm.d/www.conf.default/usr/local/php7/etc/php-fpm.d/www.conf
然后在php.ini中加入opcache
编辑php.ini
vim /usr/local/php7/etc/php.ini
1
vim/usr/local/php7/etc/php.ini
加入so
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/opcache.so
1
zend_extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20151012/opcache.so
把php.ini中的这两expose_php版本号关掉
expose_php = Off
cgi.fix_pathinfo=0
1
2
expose_php=Off
cgi.fix_pathinfo=0
编辑 /php-fpm.conf
vim /usr/local/php7/etc/php-fpm.conf
1
vim/usr/local/php7/etc/php-fpm.conf
pid=/run/php-fpm.pid
然后把php-fpm加入systemd中
vim /usr/lib/systemd/system/php-fpm.service
1
vim/usr/lib/systemd/system/php-fpm.service
写入以下内容下面为systemctl管理php-fpm启动文件
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
[Unit]
Description=ThePHPFastCGIProcessManager
After=syslog.targetnetwork.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm--nodaemonize--fpm-config/usr/local/php7/etc/php-fpm.conf
ExecReload=/bin/kill-USR2$MAINPID
ExecStop=/bin/kill-SIGINT$MAINPID
[Install]
WantedBy=multi-user.target
然后开启php-fpm用来管理php
systemctl start php-fpm.service
1
systemctlstartphp-fpm.service
加到开机自启动
systemctl enable php-fpm.service
1
systemctlenablephp-fpm.service