前言:
阿里云服务器系统版本是centos 6.8, nginx-1.8.1, mysql-5.6.16, php-5.6.31
一.nginx
安装依赖包
<pre>yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel</pre>
下载nginx并编译
tar xvf nginx-1.8.1.tar.gzv
cd nginx-1.8.1.tar.gz
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx
make
make install
nginx操作
启动: /usr/local/nginx/sbin/nginx
关闭: /usr/local/nginx/sbin/nginx -s stop
重启: /usr/local/nginx/sbin/nginx -s reload
nginx脚本
vim /etc/init.d/nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
增加权限:chmod +x /etc/init.d/nginx
开机启动:chkconfig nginx on
二. MySQL
安装依赖,部分在安装nginx的时候装过:
yum install gcc gcc-c++ ncurses-devel perl
安装cmake
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
tar xvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2
./bootstrap
make
make install
设置MySQL用户和组
groupadd mysql
useradd -r -g mysql mysql
建立安装目录以及数据库文件目录
mkdir -p /usr/local/mysql
mkdir -p /data/mysqldb
安装mysql
tar xvf mysql-5.6.16.tar.gz
cd mysql-5.6.16.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1m -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1
make
make install
修改目录权限
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysqldb
初始化mysql
cd /usr/local/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb
复制配置文件
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
复制mysql服务启动脚本及加入PATH路径
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
vim /etc/profile
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
source /etc/profile
修改配置文件
vim /etc/my.cnf
datadir = /data/mysqldb
开启mysql并加入开机启动项
service mysqld start
chkconfig mysqld on
运行安全脚本
/usr/local/mysql/bin/mysql_secure_installation
<h1>三. PHP</h1>
1.安装依赖, 部分已装过
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel
安装加密扩展库, 下载 libmcrypt-2.5.8.tar.gz(http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/)
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
编译php, 下载php-5.6.31.tar.gz(http://cn2.php.net/downloads.php)
tar zxvf php-5.6.31.tar.gz
cd php-5.6.31
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysql-sock --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-fpm --with-ncurses --enable-soap --with-libxml-dir --with-XMLrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --disable-mbregex --disable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-pdo-mysql --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sqlite-utf8 --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear
make
make install
复制php配置文件
cp php.ini-development /usr/local/php/lib/php.in
修改php.ini
timezone = "Asia/Shanghai"
short_open_tag = On
session.save_path = "/tmp/session"
复制php-fpm配置
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
修改php-fpm中的用户组与nginx相同
复制php-fpm启动脚本到service
cp php-5.6.31/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
开启php-fpm并加入开机启动项
service php-fpm start
chkconfig php-fpm on
<h1>四.配置nginx支持php</h1>
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.confbak
vi /usr/local/nginx/conf/nginx.conf
1.打开server中php的注释
2.index后添加index.php
3.修改成fastcgi_param一行为:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
<h1>五. 测试</h1>
vi /usr/local/nginx/html/index.php
<?php
phpinfo();
?>
浏览器输入 localhost/index.php