1 nginx搭建
yum install -y make cmake gcc gcc-c++
yum install pcre-devel zlib-devel openssl-devel
groupadd nginx
useradd -g nginx -s /sbin/nologin -M nginx
./configure --with-http_ssl_module --user=nginx --group=nginx
make && make install
服务启动脚本
#!/bin/bash
### BEGIN INIT INFO
#Default-Start: 2 3 4 5
#Default-Stop: 0 1 6
### END INIT INFO
nginxd=/usr/local/nginx/sbin/nginx
nginx_pid=/usr/local/nginx/logs/nginx.pid
start() {
if [ -e $nginx_pid ]; then
echo "nginx is already running..."
exit 1
fi
echo $"Starting nginx..."
$nginxd
}
stop() {
echo $"Stopping nginx..."
$nginxd -s quit
}
reload() {
echo $"Reloading nginx..."
$nginxd -s reload
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
reload
;;
status)
if [ -e $nginx_pid ]; then
echo "nginx is running..."
else
echo "nginx is stop"
fi
;;
*)
echo $"Usage: nginx {start|stop|restart|status|help}"
exit 1
esac
安装mysql
#!/bin/bash
#set ff=unix
#set nobomb
#./mysql.sh mysql-5.6.21.tar.gz
name1="$1"
name2=${name1/.tar.gz/}
if ! grep -qi "^mysql" /etc/group; then
groupadd -g 27 mysql
fi
if ! id mysql >/dev/null 2>&1; then
useradd -u 27 -g mysql -s /sbin/nologin -M mysql
fi
yum install -y cmake make gcc gcc-c++ ncurses-devel bison >/dev/null 2>&1
yum install -y perl-Data-Dumper #7上安装
[ -d /usr/local/mysql5.6 ] && rm -rf /usr/local/mysql5.6
[ -d /database ] && rm -rf /database/* || mkdir /database
if [ -d "$name2" ]; then
[ -e "$name2/CMakeCache.txt" ] && rm -f "$name2/CMakeCache.txt"
else
tar xf "$name1"
fi
cd $name2
#cmake的作用主要就是用来产生CMakeCache.txt文件, 然后make就按这个cache文件来编译
#man cmake
#cmake -LH产生CMakeCache.txt文件, 然后查看全部变量
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=/usr/local/mysql5.6 \
-DMYSQL_DATADIR:PATH=/database \
-DSYSCONFDIR:PATH=/usr/local/mysql5.6/etc \
-DWITH_DEBUG:BOOL=on
make
make install
mkdir /usr/local/mysql5.6/etc
cat <<! >/usr/local/mysql5.6/etc/my.cnf
[mysqld]
basedir=/usr/local/mysql5.6
datadir=/database
socket=/tmp/mysql.sock
pid-file=/var/run/mysqld/mysql5.6.pid
port=3307
user=mysql
[mysqld_safe]
log-error=/var/log/mysqld/mysql5.6-error.log
!
[ -d /var/run/mysqld ] && rm -rf /var/run/mysqld/* || mkdir /var/run/mysqld
[ -d /var/log/mysqld ] && rm -rf /var/log/mysqld/* || mkdir /var/log/mysqld
chown -R mysql.mysql /usr/local/mysql5.6 /database /var/run/mysqld /var/log/mysqld
/usr/local/mysql5.6/scripts/mysql_install_db \
--basedir=/usr/local/mysql5.6 \
--datadir=/database \
--user=mysql
cp /usr/local/mysql5.6/support-files/mysql.server /etc/rc.d/init.d/mysql5.6
sed -i '/conf=/c conf=./etc/my.cnf' /etc/rc.d/init.d/mysql5.6
chkconfig --add mysql5.6
service mysql5.6 start
vi /etc/profile
PATH="$PATH:/usr/local/mysql5.6/bin/"
source /etc/profile
安装php
1 安装libmcrypt
tar xvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt
make && make install
2 安装mhash
tar xvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure --prefix=/usr/local/mhash
make && make install
3 为成功安装mcrypt需配置好相应的环境
vi /etc/ld.so.conf -->> 在ld.so.conf中追加这两行,之后使用ldconfig(configure dynamic linker run-time binding)
/usr/local/libmcrypt/lib
/usr/local/mhash/lib
ldconfig
export LDFLAGS="-L/usr/local/mhash/lib -I/usr/local/mhash/include"
export CFLAGS="-I/usr/local/mhash/include"
4 安装mcrypt
tar xvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure --prefix=/usr/local/mcrypt --with-libmcrypt-prefix=/usr/local/libmcrypt
make && make install
#!/bin/bash
#comment
yum install libxml2-devel libpng-devel -y >/dev/null 2>&1
./configure --prefix=/usr/local/php5.6 --with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6
--with-gd --with-config-file-path=/usr/local/php5.6 --enable-soap --enable-mbstring --enable-sockets --with-zlib --with-gettext --enable-calendar --enable-fpm
--with-fpm-user=daemon --with-fpm-group=daemon --with-mcrypt=/usr/local/libmcrypt
make
make install
之后将源码包中的php.ini-development复制到php5.6的安装目录下即可
cp php.ini-development /usr/local/php5.6/php.ini
1 使nginx支持php
vim /usr/local/nginx/conf/nginx.conf
location / {
root html; #指/usr/local/nginx/html
index index.php index.html index.htm;
if (!-e $request_filename){
rewrite ^(.*)$ /index.php?s=$1 last; #s名称随意
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
if (!-e $request_filename){ -->> -e 是否存在request_filename文件或文件夹
rewrite ^(.*)$ /index.php?s=$1 last; -->>last 完成rewrite
break; -->>break 终止匹配
}
}
先把请求都转发到index.php来处理,即TP的单一入口文件,然后把对php文件的请求交给fastcgi
来处理,tp为thinkphp框架,在php中使用的很多
rewrite模块写在location /和location ~ \.php$是对于http://172.17.10.252/abc/sdfjkl/sdf.php和
http://172.17.10.252/abc/sd.html,http://172.17.10.252/abc/s都能够支持
2 开启php相应端口供nginx使用
cp 源码包下/php.ini-development /usr/local/php5.6/php.ini
cd /usr/local/php5.6/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
pid = run/php-fpm.pid
cp 源码包下/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig php-fpm on
service php-fpm start
<?php
if(mysql_connect('localhost:/var/run/mysqld/mysql5.6.sock', 'root', 'abc'))
echo 'ok';
else
echo 'fail';