Linux 环境搭建推荐教程(php运行环境)

2019-02-17 21:51:39王旭

# ./configure
"--prefix=/usr/local/php"
"--with-apxs2=/usr/local/apache2/bin/apxs"
"--with-config-file-path=/usr/local/php/etc"
"--with-MySQL=/usr/local/MySQL"
"--with-libxml-dir=/usr/local/libxml2"
"--with-gd=/usr/local/gd2"
"--with-jpeg-dir"
"--with-png-dir"
"--with-bz2"
"--with-freetype-dir"
"--with-iconv-dir"
"--with-zlib-dir "
"--with-openssl=/usr/local/openssl"
"--with-mcrypt=/usr/local/libmcrypt"
"--enable-soap"
"--enable-gd-native-ttf"
"--enable-ftp"
"--enable-mbstring"
"--enable-exif"
"--disable-ipv6"
"--disable-cgi"
"--disable-cli"
# make
# make install
# mkdir /usr/local/php/etc
# cp php.ini-dist /usr/local/php/etc/php.ini
5. 安装Zend Optimizer
# cd /usr/local/src
# tar xzvf ZendOptimizer-3.3.0-linux-glibc21-i386.tar.gz
# ./ZendOptimizer-3.3.0-linux-glibc21-i386/install.sh
安装Zend Optimizer过程的最后不要选择重启Apache。
6. 整合Apache与PHP
# vi /usr/local/apache2/conf/httpd.conf
找到:
AddType application/x-gzip .gz .tgz
在该行下面添加
AddType application/x-httpd-php .php
找到:
DirectoryIndex index.html
将该行改为
DirectoryIndex index.html index.htm index.php
找到:
#Include conf/extra/httpd-mpm.conf
#Include conf/extra/httpd-info.conf
#Include conf/extra/httpd-vhosts.conf
#Include conf/extra/httpd-default.conf
去掉前面的“#”号,取消注释。
注意:以上 4 个扩展配置文件中的设置请按照相关原则进行合理配置!
修改完成后保存退出。
# /usr/local/apache2/bin/apachectl restart
7. 查看确认L.A.M.P环境信息、提升 PHP 安全性
在网站根目录放置 phpinfo.php 脚本,检查phpinfo中的各项信息是否正确。
确认 PHP 能够正常工作后,在 php.ini 中进行设置提升 PHP 安全性。
# vi /etc/php.ini
找到:
disable_functions =
设置为:
phpinfo,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
四、服务器安全性设置
1. 设置系统防火墙
# vi /usr/local/sbin/fw.sh
将以下脚本命令粘贴到 fw.sh 文件中。
#!/bin/bash
# Stop iptables service first
service iptables stop
# Load FTP Kernel modules
/sbin/modprobe ip_conntrack_ftp
/sbin/modprobe ip_nat_ftp
# Inital chains default policy
/sbin/iptables -F -t filter
/sbin/iptables -P INPUT DROP
/sbin/iptables -P OUTPUT ACCEPT