php 编译安装指导
php 编译安装
- 下载源码
- 安装
- 安装后配置
下载源码
php下载地址:http://php.net/downloads.php
php-7.1.11.tar.bz2
安装
安装依赖包
yum install -y epel-release bzip2
yum install -y libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel
编译参数
./configure \
--prefix=/usr/local/php-7.1.11 \
--with-config-file-path=/usr/local/php-7.1.11/etc \
--enable-fpm \
--enable-exif \
--enable-sockets \
--enable-bcmath \
--enable-mbstring \
--enable-pcntl \
--enable-calendar \
--enable-opcache \
--enable-zip \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysqli=/usr/bin/mysql_config \
--with-pdo-mysql \
--enable-mysqlnd \
--with-zlib \
--with-gd \
--with-png-dir \
--with-jpeg-dir \
--with-gettext \
--with-freetype-dir \
--with-mcrypt \
--with-openssl \
--with-curl \
make
make install
安装后配置
创建安装目录链接文件
ln -s /usr/local/php-7.1.11 /usr/local/php
创建配置文件链接目录
ln -s /usr/local/php/etc /etc/php
\cp /usr/local/src/php-7.1.11/php.ini-production /usr/local/php/etc/
编辑配置文件
cp /usr/local/php-<old-version>/etc/php.ini /usr/local/php/etc/ # 升级
cp /usr/local/php-<old-version>/etc/php-fpm.conf /usr/local/php/etc/ # 升级
cd /usr/local/php/etc/
cp php.ini-production php.ini
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
vim php-fpm.conf
pid = /var/run/php-fpm.pid
error_log = /var/log/php-fpm.log
配置启动项
ln -s /usr/local/php/sbin/* /usr/sbin/
ln -s /usr/local/php/bin/* /usr/bin/
php -v
php-config
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/var/run/php-fpm.pid
ExecStart=/bin/nice --10 /usr/sbin/php-fpm --nodaemonize --fpm-config /etc/php/php-fpm.conf -c /etc/php/php.ini -R
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill $MAINPID
[Install]
WantedBy=multi-user.target
或者
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/var/run/php-fpm.pid
Environment="basedir=/usr/local/php"
ExecStart=/bin/nice --10 ${basedir}/sbin/php-fpm --nodaemonize --fpm-config ${basedir}/etc/php-fpm.conf -c ${basedir}/etc/php.ini -R
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill $MAINPID
[Install]
WantedBy=multi-user.target
启动 php-fpm
systemctl start php-fpm
ps -ef|grep php-fpm
systemctl enable php-fpm
测试
vim /etc/nginx/nginx.conf # 在nginx的配置文件中设置支持php
location / {
root html;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
cd /usr/local/nginx/html
vim index.php
<?php
echo "test page for php";
phpinfo();
?>
systemctl restart nginx # 重启nginx服务
浏览器中访问 IP/index.php
php 安装结束,安装后还需要优化。
升级php版本:
ln -s /usr/local/php-<version> /usr/local/php # 把新版本的安装目录链接到 php 上
\cp -r /usr/local/php-<old-version>/etc/* /usr/local/php/etc/ # 把旧版本的php配置文件拷贝到新版本的相应目录
php -v # 查看是否配置好php的链接
php-config
systemctl restart php-fpm # 重启php-fpm
访问测试页面
有疑惑之处请发邮件到下面的邮箱。
2017-11-6 by achxku@163.com
-- 衣带渐宽终不悔,为伊消得人憔悴。---