为什么需要安装php
zabbix的网页后端语言使用php
php的安装相对复杂,需要解决很多依赖
php编译安装
yum -y install epel-release
yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel
cd /usr/local/src
wget "https://www.php.net/distributions/php-5.6.40.tar.gz"
tar -zxvf php-5.6.40.tar.gz
cd php-5.6.40
./configure \
--prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc \
--with-mysql=mysqlnd --with-mysqli=mysqlnd \
--enable-ctype --with-freetype-dir \
--with-jpeg-dir --with-png-dir \
--with-zlib --with-libxml-dir=/usr --enable-xml \
--disable-rpath --enable-bcmath --enable-shmop \
--enable-sysvsem --enable-inline-optimization \
--with-curl --with-iconv \
--enable-mbregex --enable-mbstring \
--with-mcrypt --with-gd --enable-gd-native-ttf \
--with-openssl --with-mhash --enable-pcntl \
--enable-sockets --with-ldap-sasl --with-xmlrpc \
--enable-zip --enable-soap \
--with-gettext --enable-fpm
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
php编译安装说明
--prefix 指定php的安装目录
--with-config-file-path 指定php的配置文件的位置
--with-mysql、--with-mysqli 让php可以操作mysql
--enable-fpm 主要是nginx要来调用php语言使用php-fpm
启动php-fpm
- 环境变量:
echo "export PATH=\$PATH:/usr/local/php/sbin:/usr/local/php/bin" >>/etc/profile && source /etc/profile
- 使用默认配置文件:mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
注意将"user"和"group"这两个变量的值都改为root
- 检查配置文件:php-fpm -t
- 查看php-fpm的listen配置
验证php-fpm的启动
- 进程 ps auxf | grep php-fpm
- 端口 netstat -tulnp | grep php-fpm
- 日志
使用systemctl管理php-fpm
cat >/usr/lib/systemd/system/php-fpm.service <<EOF
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm -R
[Install]
WantedBy=multi-user.target
EOF
"-R" 代表root用户启动
nginx默认配置无法处理php程序
cat >/usr/local/nginx/html/test.php <<EOF
<?php
echo "hello moto zabbix!!!!!!!";
?>
EOF
nginx+php-fpm结合的配置
配置文件:/usr/local/nginx/conf/nginx.conf
# 将第二个配置在配置文件中存在,需要去掉前面的注释,其次要修改fastcgi_param这一行
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;
}