微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

centos7编译安装php7.2

去官网下载PHP7.2安装包,选择一个结点下载:
http://PHP.net/downloads.PHP

下载:
wget -ivh http://cn.PHP.net/distributions/PHP-7.2.12.tar.gz
解压源码包:
tar -zxf PHP-7.2.12.tar.gz

安装编译PHP需要的依赖包:
yum install gcc autoconf gcc-c++
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
yum install systemd-devel
yum install openjpeg-devel

添加www用户
创建群组:groupadd www
创建一个用户,不允许登陆和不创主目录:useradd -s /sbin/nologin -g www -M www

 

编译参数:

开发环境:
    --enable-PHPdbg\
    --enable-dtrace\
生产环境:
    --disable-PHPdbg\
    --disable-dtrace\

./configure \
--prefix=/usr/local/PHP \
--with-config-file-path=/usr/local/PHP/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pdo-sqlite \
--with-pdo-MysqL \
--with-MysqLi \
--with-MysqL-sock \
--enable-MysqLnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=PHP-fpm \
--with-fpm-group=PHP-fpm \
--with-fpm-systemd \
--disable-fileinfo

执行编译:
make && make install


PHP-ini:
源码包里面有配置文件:
    PHP.ini-development     测试开发环境
    PHP.ini-production         生产环境

复制一份到指定的目录下(根据自己的情况选用,自己可以对比下这两个文件的差异):
cp PHP.ini-production /usr/local/PHP/etc/PHP.ini

PHP-fpm复制一份新的PHP-fpm配置文件
cd /usr/local/PHP/etc
cp PHP-fpm.conf.default PHP-fpm.conf
vim PHP-fpm.conf

配置错误日志:error_log = /usr/local/PHP/var/PHP-fpm.log
配置pid文件:pid = /usr/local/PHP/var/run/PHP-fpm.pid
保存退出
cd /usr/local/PHP/etc/PHP-fpm.d
cp www.conf.default  www.conf

管理PHP-fpm配置:

cd /usr/local/src/PHP-7.2.4
cp ./sapi/fpm/PHP-fpm.service 到 /usr/lib/systemd/system/下

也执行以下命令启动PHP-fpm服务:
cp sapi/fpm/PHP-fpm.service /usr/local/PHP/bin/
/usr/local/bin/PHP-fpm
启动完毕之后,PHP-fpm服务认使用9000端口,使用 netstat -tln | grep 9000 可以查看端口使用情况:


配置开机启动PHP-fpm:
systemctl enable PHP-fpm

启动PHP-fpm:
systemctl start PHP-fpm

查看状态:
systemctl status PHP-fpm

添加环境变量:
vim  /etc/profile

在末尾追加:
export PATH=$PATH:'/usr/local/PHP/bin/'

保存退出
source /etc/profile

测试:
PHP -v

看到PHP版本信息就表示已经成功了。


如果需要区分web和cli环境,可以将 /usr/local/PHP/etc/PHP.ini 复制一份,重命名PHP-cli.ini

cp /usr/local/PHP/etc/PHP.ini  /usr/local/PHP/etc/PHP-cli.ini 

需要调整配置,就在各自的配置文件中进行调整即可。


设置Nginx
Nginx配置:
server {
listen 80;
server_name www.demo.com;

#charset koi8-r;
access_log /var/logs/Nginx/access.log main;
error_log /var/logs/Nginx/error.log;

root /wwwroot;
location / {
index index.PHP;
try_files $uri /index.PHP?_RW_=$uri;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/Nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.PHP$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.PHP$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME /wwwroot$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files,if Apache's document root
# concurs with Nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

修改完这些保存并退出,然后重启Nginx
/usr/local/Nginx/Nginx -s stop
/usr/local/Nginx/Nginx
或者
/usr/local/Nginx/Nginx -s reload

访问网站,如果能正常打开页面,就证明设置成功了,有些时候会遇到一些权限问题,比如我就遇到了缓存目录没有写权限,chmod 755 cache修改目录的权限,然后程序就能正常运行了。

done!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐