Ubuntu14.04 64bit 编译安装nginx1.7+php5.4+mysql5.6

我的操作系统是Ubuntu14.04,其它linux系统的操作流程类似。

主要安装的软件是nginx1.7+php5.4+mysql5.6

 

1. 创建必要目录

sudo mkdir ~/setup
sudo mkdir /opt/software
sudo chmod 777 /opt/software

 

2. 下载必要软件

复制代码
cd ~/Downloads

wget http://am1.php.net/distributions/php-5.4.29.tar.gz
tar zxvf ~/Downloads/php-5.4.29.tar.gz -C ~/setup/

wget http://nginx.org/download/nginx-1.7.1.tar.gz
tar zxvf ~/Downloads/nginx-1.7.1.tar.gz -C ~/setup/

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz
tar zxvf ~/Downloads/mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz -C ~/setup/

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz
tar zxvf ~/Downloads/pcre-8.33.tar.gz -C ~/setup/

wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
tar zxvf ~/Downloads/jpegsrc.v9.tar.gz -C ~/setup/

wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz ~/Downloads
tar zxvf ~/Downloads/libpng-1.6.2.tar.gz -C ~/setup/

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz
tar zxvf ~/Downloads/freetype-2.4.12.tar.gz -C ~/setup/

wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
tar zxvf ~/Downloads/mhash-0.9.9.9.tar.gz -C ~/setup/

wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
tar zxvf ~/Downloads/libmcrypt-2.5.8.tar.gz -C ~/setup/

wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
tar zxvf ~/Downloads/mcrypt-2.6.8.tar.gz -C ~/setup/

wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
tar zxvf ~/Downloads/termcap-1.3.1.tar.gz -C ~/setup/

wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar zxvf ~/Downloads/autoconf-latest.tar.gz -C ~/setup/

wget http://ftp.gnu.org/gnu/m4/m4-latest.tar.gz
tar zxvf ~/Downloads/m4-latest.tar.gz -C ~/setup/

wget http://pecl.php.net/get/memcache-2.2.7.tgz
tar zxvf ~/Downloads/memcache-2.2.7.tgz -C ~/setup/
复制代码

以上软件我已经打包好放到百度网盘,相关链接:http://pan.baidu.com/s/1o6DL4EI

 

3. 安装nginx

复制代码
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install libssl-dev openssl libcurl4-openssl-dev
sudo apt-get install build-essential

sudo /usr/sbin/groupadd www
sudo /usr/sbin/useradd -g www www

cd ~/setup/pcre-8.33/
./configure --prefix=/opt/software/pcre
sudo make && sudo make install

cd ../nginx-1.7.1/
./configure --user=www --group=www --prefix=/opt/software/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=~/setup/pcre-8.33 --with-http_realip_module
sudo make && sudo make install
复制代码

 

4. 安装MySQL

复制代码
cd ~/setup
sudo mv mysql-5.6.19-linux-glibc2.5-x86_64 /opt/software/mysql
sudo mkdir -p /opt/software/mysql/data

sudo apt-get install libaio-dev

sudo /usr/sbin/groupadd mysql
sudo /usr/sbin/useradd -g mysql mysql

/opt/software/mysql/scripts/mysql_install_db --basedir=/opt/software/mysql --datadir=/opt/software/mysql/data --user=mysql
sed -i "s#/usr/local/mysql#/opt/software/mysql#g" /opt/software/mysql/bin/mysqld_safe

#启动mysql进程
/opt/software/mysql/bin/mysqld --basedir=/opt/software/mysql --datadir=/opt/software/mysql/data > /dev/null 2>&1
#设置root的密码为123456
/opt/software/mysql/bin/mysqladmin -u root password '123456'
复制代码

 

5. 安装PHP依赖库

复制代码
cd ~/setup
sudo mkdir -p /opt/software/libs/

cd jpeg-9/
./configure --prefix=/opt/software/libs --enable-shared --enable-static --prefix=/opt/software/libs
sudo make && sudo make install

cd ../libpng-1.6.2/
./configure --prefix=/opt/software/libs
sudo make && sudo make install

cd ../freetype-2.4.12/
./configure --prefix=/opt/software/libs
sudo make && sudo make install

cd ../libmcrypt-2.5.8/
./configure --prefix=/opt/software/libs
sudo make && sudo make install

#注意这里不是返回上级目录,而是在当前目录
cd libltdl/
./configure --prefix=/opt/software/libs --enable-ltdl-install
sudo make && sudo make install

cd ../../mhash-0.9.9.9/
./configure --prefix=/opt/software/libs
sudo make && sudo make install
复制代码

 

6. 设置类库加载路径

复制代码
sudo vim /etc/ld.so.conf.d/opt-software-libs.conf
输入
/opt/software/libs/lib
然后
sudo ldconfig

cd ../mcrypt-2.6.8/
export LDFLAGS="-L/opt/software/libs/lib -L/usr/lib"
export CFLAGS="-I/opt/software/libs/include -I/usr/include"
touch malloc.h
./configure --prefix=/opt/software/libs --with-libmcrypt-prefix=/opt/software/libs
sudo make && sudo make install

cd ../termcap-1.3.1/
./configure --prefix=/opt/software/libs
sudo make && sudo make install
复制代码

 

7. 安装PHP

复制代码
sudo apt-get install libxml2-dev
export LIBS="-lm -ltermcap -lresolv"
export DYLD_LIBRARY_PATH="/opt/software/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"
export LD_LIBRARY_PATH="/opt/software/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"

cd ../php-5.4.29/
./configure --prefix=/opt/software/php --with-config-file-path=/opt/software/php/etc --with-mysql=/opt/software/mysql --with-mysqli=/opt/software/mysql/bin/mysql_config --with-iconv-dir --with-freetype-dir=/opt/software/libs --with-jpeg-dir=/opt/software/libs --with-png-dir=/opt/software/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=/opt/software/libs --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap

sudo ln -s /opt/software/mysql/lib/libmysqlclient.so.18 /usr/lib/

wget http://pear.php.net/go-pear.phar
sudo mv go-pear.phar /opt/software/php/bin

sudo make && sudo make install

sudo cp php.ini-development /opt/software/php/etc/php.ini
sudo ln -s /opt/software/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
sudo cp /opt/software/php/etc/php-fpm.conf.default /opt/software/php/etc/php-fpm.conf
复制代码

 

8. 安装PHP扩展

复制代码
cd ../m4-1.4.17/
./configure --prefix=/opt/software/libs
sudo make && sudo make install
export PATH=/home/davidhhuan/setup/m4-1.4.17:$PATH

cd ../autoconf-2.69/
./configure --prefix=/opt/software/libs
sudo make && sudo make install

cd ../memcache-2.2.7/
export PHP_AUTOCONF="/opt/software/libs/bin/autoconf"
export PHP_AUTOHEADER="/opt/software/libs/bin/autoheader"
/opt/software/php/bin/phpize
./configure --with-php-config=/opt/software/php/bin/php-config
sudo make && sudo make install
复制代码

 

9. 设置开机自启动

Nginx

sudo vim /etc/init.d/nginx

内容如下

复制代码
#! /bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/software/nginx/sbin/nginx
NAME=nginx
DESC=nginx

DAEMON_OPTS=''

test -x $DAEMON || exit 0

# Include nginx defaults if available
#if [ -f /etc/default/nginx ] ; then
#       . /etc/default/nginx
#fi

set -e

. /lib/lsb/init-functions

#test_nginx_config() {
#  if $DAEMON -t $DAEMON_OPTS
#  then
#    return 0
#  else
#    return $?
#  fi
#}

case "$1" in
  start)
        echo -n "Starting $DESC: "
        start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON || true
        echo "$NAME."
        ;;
  stop)
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
                --exec $DAEMON || true
        echo "$NAME."
        ;;
  restart|force-reload)
        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON || true
        sleep 1
        start-stop-daemon --start --quiet --pidfile \
                /var/run/$NAME.pid --exec $DAEMON || true
        echo "$NAME."
        ;;
  reload)
        echo -n "Reloading $DESC configuration: "
        start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
            --exec $DAEMON || true
        echo "$NAME."
        ;;
  status)
        status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
        ;;
  *)
        echo "Usage: $NAME {start|stop|restart|reload|force-reload|status}" >&2
        exit 1
        ;;
esac

exit 0
复制代码

 

sudo update-rc.d nginx defaults

 

php-fpm

sudo cp /opt/setup/php-5.4.29/sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpm
sudo groupadd nobody
sudo touch /opt/software/php/var/run/php-fpm.pid
sudo update-rc.d php-fpm defaults
vim /etc/init.d/php-fpm

替换如下内容

prefix=@prefix@
exec_prefix=@exec_prefix@

php_fpm_BIN=@sbindir@/php-fpm
php_fpm_CONF=@sysconfdir@/php-fpm.conf
php_fpm_PID=@localstatedir@/run/php-fpm.pid

 

变成

prefix=/opt/software/php
exec_prefix=/opt/software/php/bin

php_fpm_BIN=/opt/software/php/sbin/php-fpm
php_fpm_CONF=/opt/software/php/etc/php-fpm.conf
php_fpm_PID=/opt/software/php/var/run/php-fpm.pid

 

 

MySQL

复制代码
sudo cp /opt/software/mysql/support-files/mysql.server /etc/init.d/mysqld
sudo vim /etc/init.d/mysqld
#找到
basedir=
datadir=
#变成
basedir=/opt/software/mysql
datadir=/opt/software/mysql/data

sudo update-rc.d mysqld defaults
复制代码

 

10. 加入环境变量

sudo vim /etc/profile

加入

export PATH=$PATH:/opt/software/mysql/bin:/opt/software/php/bin:/opt/software/php/sbin:/opt/software/mysql/bin

加载

source /etc/profile

 

 

至此,基本上就可以使用了。

posted @ 2015-05-12 09:19  Bonker  阅读(540)  评论(0编辑  收藏  举报