把刚申请到的azure中国区试用虚拟机给重置了,然后源码编译nginx、php、mysql所有最新版玩玩,以下是编译安装笔记。
安装基本约定以及基本软件包下载:
mkdir /server
mkdir /server/src
mkdir /server/apps
mkdir /serverlibs
mkdir /server/data
mkdir /server/data/mysql
mkdir /server/data/mysql/data
cd /server/src
wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz
wget http://nginx.org/download/nginx-1.5.5.tar.gz
wget http://cn2.php.net/distributions/php-5.5.4.tar.gz
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.32.tar.gz
wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz
wget "https://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?big_mirror=0"
wget "https://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?big_mirror=0"
wget "https://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?big_mirror=0"
wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
一、Azure的yum配置修改,默认不允许安装kernel内核相关的内容
vi /etc/yum.conf
#将 exclude=kernel* 那一行注释掉即可 即修改为 #exclude=kernel*
二、yum更新必须的lib工具库
yum -y install openssl* gd gd2 gd-devel gd2-devel gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make
三、安装nginx
cd /server/src
tar zxvf pcre-8.32.tar.gz
cd pcre-8.32
./configure --prefix=/server/libs
make && make install
cd ..
/usr/sbin/groupadd nginx
/usr/sbin/useradd -g nginx nginx
ulimit -SHn 65535
tar zxvf nginx-1.5.5.tar.gz
cd nginx-1.5.5
./configure --user=nginx --group=nginx --prefix=/server/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/server/src/pcre-8.32 --with-http_realip_module --with-http_image_filter_module
make && make install
四、安装mysql
cd ..
#该版本mysql已经编译好 直接用
tar zxvf mysql-5.6.14-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.6.14-linux-glibc2.5-x86_64 /server/apps/mysql
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
#yum install libaio #azure已经自动安装过该lib
#配置文件
cp ./support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
#将basedir datasir修改如下:
basedir = /server/apps/mysql
datadir = /server/data/mysql/data
#mysql启动脚本 可以使用诸如 service mysql start|restart|stop命令管理mysql
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
vi /etc/rc.d/init.d/mysqld
同理修改basedir、datadir
#初始化mysql
/server/apps/mysql/scripts/mysql_install_db --basedir=/server/apps/mysql --datadir=/server/data/mysql/data --user=mysql
sed -i "s#/usr/local/mysql#/server/apps/mysql#g" /server/apps/mysql/bin/mysqld_safe
#修改mysql初始化root账户密码 实际mysql的root账户没有密码 设定一个密码而已
/server/apps/mysql/bin/mysqladmin -u root -p password #连续回车两次后输入新密码再回车然后重复密码 root账户即被设置了你设置的新密码
#mysql的环境变量设置 以后终端直接输入 mysql -u root -p即可进入mysql 而不需输入路径
vi /etc/profile
#在该文件的最后添加如下代码保存即可
export PATH=$PATH:/server/apps/mysql/bin
#然后使环境变量立即生效:
source /etc/profile
五、安装PHP依赖库
#安装php的基本依赖库
tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9/
./configure --prefix=/server/libs --enable-shared --enable-static --prefix=/server/libs
make && make install
cd ../
tar zxvf libpng-1.6.2.tar.gz
cd libpng-1.6.2/
./configure --prefix=/server/libs
make && make install
cd ../
tar zxvf freetype-2.4.12.tar.gz
cd freetype-2.4.12/
./configure --prefix=/server/libs
make && make install
cd ../
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure --prefix=/server/libs
make
make install
cd libltdl/
./configure --prefix=/server/libs --enable-ltdl-install
make
make install
cd ../../
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9/
./configure --prefix=/server/libs
make
make install
cd ../
#编辑lib库查询路径变量
vi /etc/ld.so.conf
#在文件末尾添加后保存
/server/libs/lib
#使更改生效
ldconfig
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
export LDFLAGS="-L/server/libs/lib -L/usr/lib"
export CFLAGS="-I/server/libs/include -I/usr/include"
touch malloc.h
./configure --prefix=/server/libs --with-libmcrypt-prefix=/server/libs
make
make install
cd ../
六、安装PHP
tar zxvf php-5.5.4.tar.gz
cd php-5.5.4
export LIBS="-lm -ltermcap -lresolv"
export DYLD_LIBRARY_PATH="/server/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
export LD_LIBRARY_PATH="/server/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
./configure --prefix=/server/apps/php --with-config-file-path=/server/apps/php/etc --with-config-file-scan-dir=/server/apps/php/etc/ini --with-mysql=/server/apps/mysql --with-mysqli=/server/apps/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir=/server/libs --with-jpeg-dir=/server/libs --with-png-dir=/server/libs --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt=/server/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-opcache --with-pdo-mysql
make
make test
make install
#编译php是最耗时的 本次大约需要6分钟左右(4核心cpu、7G内存) 记得我手头的另外一台1G内存、单核心cpu当时编译了15分钟左右
#添加php配置文件额外搜索目录
mkdir /server/apps/php/etc/ini
七、PHP、PHP-FPM、nginx支持php配置
#复制拷贝php主配置文件
cp php.ini-production /server/apps/php/etc/php.ini
#复制php-fpm启动脚本(可以采用诸如service php-fpm start|restart|stop命令的脚本)
#该启动脚本编译的时候已经将必须的配置路径设置好了, 复制即可使用
cp ./sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
#设置启动权限并加入开机启动
chmod +x /etc/rc.d/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置php通过nginx的php-fpm方式的开机启动
#ps补充mysql的
chmod +x /etc/rc.d/init.d/mysqld #mysql添加mysql的执行权限
chkconfig mysqld on #设置mysql开机启动
#php-fpm配置文件
cd /server/apps/php/etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
#修改如下(php-fpm与nginx的执行用户必须相同)
user = nginx
group = nginx
#nginx支持php-fpm
cd /server/apps/nginx/conf
vi nginx.conf
#修改如下所述部分
user nginx nginx;
pid /server/data/nginx.pid
#index 的位置添加 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;
}
八、nginx启动文件、启动nginx、mysql、php-fpm
笔者是个service xx start|stop|restart狂,所以在nginx没有启动文件的情况下,自己书写一个。
#nginx启动脚本
vi /etc/init.d/nginx
#写入如下内容[文件另提一个代码段],保存之后授予该执行文件权限
chmod 755 /etc/init.d/nginx
#或者chmod +x /etc/rc.d/init.d/nginx 是一个意思
#Server nginx - this script starts and stops the nginx daemon
# By www.jjonline.cn
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /server/apps/nginx/conf/nginx.conf
# pidfile: /server/data/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="/server/apps/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/server/apps/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
}
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
;;
test)
configtest || exit 0
;;
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
或者您可以点击下载这个nginx启动管理脚本:【下载】
启动nginx、mysql、php-fpm,太简单了:
service mysqld start
service nginx start
service php-fpm start
九、部分问题解决
启动php-fpm时提示“Starting php-fpm /server/apps/php/sbin/php-fpm: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory failed”
做个文件连接即可:
ln -s /server/apps/mysql/lib/mysql /usr/lib64/mysql
ln -s /server/apps/mysql/include/mysql /usr/include/mysql
ln -s /server/apps/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18 #注意64位和32位的路径区别
本次配置安装好后的,在线地址:https://42.159.4.81/ (因为是试用,预计10月25号以后该地址即将失效)
转载请注明本文标题和链接:《微软云虚拟机:centos6.3下nginx1.5.5、PHP5.5.4、mysql5.6.14环境安装笔记》
不错啊 省事了不少