php 编译安装
- 下载源码
- 安装
- 安装后配置
下载源码
php-7.1.11.tar.bz2
安装
安装依赖包
yum install -y epel-release bzip2yum 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 \makemake 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-/etc/php.ini /usr/local/php/etc/ # 升级cp /usr/local/php- /etc/php-fpm.conf /usr/local/php/etc/ # 升级cd /usr/local/php/etc/cp php.ini-production php.inicp php-fpm.conf.default php-fpm.confcp php-fpm.d/www.conf.default php-fpm.d/www.confvim php-fpm.confpid = /var/run/php-fpm.piderror_log = /var/log/php-fpm.log
配置启动项
ln -s /usr/local/php/sbin/* /usr/sbin/ln -s /usr/local/php/bin/* /usr/bin/php -vphp-configvim /usr/lib/systemd/system/php-fpm.service[Unit]Description=The PHP FastCGI Process ManagerAfter=syslog.target network.target[Service]Type=simplePIDFile=/var/run/php-fpm.pidExecStart=/bin/nice --10 /usr/sbin/php-fpm --nodaemonize --fpm-config /etc/php/php-fpm.conf -c /etc/php/php.ini -RExecReload=/bin/kill -USR2 $MAINPIDExecStop=/bin/kill $MAINPID[Install]WantedBy=multi-user.target或者[Unit]Description=The PHP FastCGI Process ManagerAfter=syslog.target network.target[Service]Type=simplePIDFile=/var/run/php-fpm.pidEnvironment="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 -RExecReload=/bin/kill -USR2 $MAINPIDExecStop=/bin/kill $MAINPID[Install]WantedBy=multi-user.target
启动 php-fpm
systemctl start php-fpmps -ef|grep php-fpmsystemctl enable php-fpm
测试
vim /etc/nginx/nginx.conf # 在nginx的配置文件中设置支持phplocation / {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/htmlvim index.php systemctl restart nginx # 重启nginx服务浏览器中访问 IP/index.php
php 安装结束,安装后还需要优化。
升级php版本:ln -s /usr/local/php-/usr/local/php # 把新版本的安装目录链接到 php 上\cp -r /usr/local/php- /etc/* /usr/local/php/etc/ # 把旧版本的php配置文件拷贝到新版本的相应目录php -v # 查看是否配置好php的链接php-config systemctl restart php-fpm # 重启php-fpm 访问测试页面
有疑惑之处请发邮件到下面的邮箱。
2017-11-6 by achxku@163.com