[Ubuntu] Ubuntu14.04 64bit 編譯安裝nginx1.7+php5.4+mysql5.6

個人操做系統是Ubuntu14.04,其它linux系統的操做流程相似。php

主要安裝的軟件是nginx1.7+php5.4+mysql5.6mysql

 

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/1o6DL4EIlinux

 

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=shared,mysqlnd --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. 設置開機自啓動

Nginxnginx

sudo vim /etc/init.d/nginx

內容以下web

#! /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-fpmsql

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

替換以下內容vim

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

 

變成api

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

 

 

MySQLcurl

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

加入socket

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

加載

source /etc/profile

 

 

至此,基本上就能夠使用了。

 

Have fun with Ubuntu!

相關文章
相關標籤/搜索