Php环境搭建php
http://php.net/manual/zh/install.unix.nginx.php html
http://blog.sina.com.cn/s/blog_4991d72c0102vu2u.htmlmysql
1、安装相关包nginx
yum -y install epel-release
yum groupinstall "development tools"
yum -y install mhash mhash-devel libmcrypt libmcrypt-devel
yum -y install zlib zlib-devel libjpeg libjpeg-devel freetype freetype-devel gd gd-devel php-gd curl curl-devel libxml2 libxml2-devel libxslt libxslt-devel libmcrypt libmcrypt-devel libc-client-devel postgresql-devel
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.sosql
2、PHP下载vim
http://php.net/get/php-5.6.11.tar.gz/from/a/mirror后端
3、解压下载文件浏览器
tar zxf php-x.x.xbash
4、配置并构建 PHP。在此步骤您可使用不少选项自定义 PHP,例如启用某些扩展等。 运行 ./configure --help 命令来得到完整的可用选项清单。 在本示例中,咱们仅进行包含 PHP-FPM 和 MySQL 支持的简单配置。curl
cd ../php-x.x.x
./configure --prefix=/usr/local/php --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-bcmath --enable-shmop --enable-sysvsem --with-curl --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --with-kerberos --with-pcre-regex --enable-exif --enable-mbregex --enable-sysvshm --enable-inline-optimization --disable-rpath --with-pgsql --enable-calendar --with-zlib-dir --enable-xmlreader --enable-xmlwriter --enable-static --with-xsl --enable-ftp --enable-opcache --disable-fileinfo
make
make clean
sudo make install
安装过程当中若是进示错误:
xml2-config not found. Please check your libxml2 installation
则安装:
yum install libxml2
yum install libxml2-devel -y
而后从新执行:./configure
5、添加环境变量
export PATH=/usr/local/php/bin:$PATH
vim /etc/profile
最后一行添加
export PATH="/usr/local/php/bin:$PATH"
source /etc/profile
6、建立配置文件,并将其复制到正确的位置。
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
useradd www-data;
找到如下内容并修改:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = www-data
group = www-data
可经过:
vi /usr/local/php/etc/php-fpm.conf
listen = 127.0.0.1:8080
修改php的cgi服务 端口
启动服务:/usr/local/php/sbin/php-fpm
或者
[将 php-fpm 配置为服务]
#!/bin/bash
#
# Startup script for the PHP-FPM server.
#
# chkconfig: 345 85 15
# description: PHP is an HTML-embedded scripting language
# processname: php-fpm
# config: /usr/local/php/etc/php.ini
# Source function library.
. /etc/rc.d/init.d/functions
PHP_PATH=/usr/local
DESC="php-fpm daemon"
NAME=php-fpm
DAEMON=$PHP_PATH/php/sbin/$NAME
CONFIGFILE=$PHP_PATH/php/etc/php-fpm.conf
INI_CONFIGFILE=$PHP_PATH/php/etc/php.ini
PIDFILE=$PHP_PATH/php/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
rh_start() {
$DAEMON -y $CONFIGFILE -c $INI_CONFIGFILE || echo -n " already running"
}
rh_stop() {
kill -QUIT `cat $PIDFILE` || echo -n " not running"
}
rh_reload() {
kill -HUP `cat $PIDFILE` || echo -n " can't reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
rh_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
rh_stop
echo "."
;;
reload)
echo -n "Reloading $DESC configuration..."
rh_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
rh_stop
sleep 1
rh_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
chmod +x /etc/init.d/php-fpm
service php-fpm restart
chkconfig --level 35 php-fpm on
7、须要着重提醒的是,若是文件不存在,则阻止 Nginx 将请求发送到后端的 PHP-FPM 模块, 以免遭受恶意脚本注入的攻击。
将 php.ini 文件中的配置项 cgi.fix_pathinfo 设置为 0 。
打开 php.ini:
vim /usr/local/php/php.ini
定位到 cgi.fix_pathinfo= 并将其修改成以下所示:
cgi.fix_pathinfo=0
8、配置 Nginx 使其支持 PHP 应用:
vim /usr/local/nginx/conf/nginx.conf
修改默认的 location 块,使其支持 .php 文件:
location / {
root html;
index index.php index.html index.htm;
}
下一步配置来保证对于 .php 文件的请求将被传送到后端的 PHP-FPM 模块, 取消默认的 PHP 配置块的注释,并修改成下面的内容:
location ~* \.php$ {
root /home/project/myphptest;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:8080;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
}
重启 Nginx。
sudo /usr/local/nginx/sbin/nginx -s stop
sudo /usr/local/nginx/sbin/nginx
9、建立测试文件。
rm /usr/local/nginx/html/index.html
echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php
打开浏览器,访问 http://localhost,将会显示 phpinfo() 。