ubuntu 下编译安装 nginx+php+mysql 全过程

2013.06.28

网上的大部分的nginx和php及mysql的Linux下安装都很陈旧,好多还是apt-get | yum 等安装的,但是网上的这些源很多都是旧版本的,如果想安装最新的只有自己编译安装了。下面是我在ubuntu 12.04下安装nginx-1.5.1,php-5.5.0,mysql-5.6.10。

1.安装nginx

mkdir -p /Data/tgz

cd /Data/tgz

apt-get install wget

sudo apt-get install libpcre3 libpcre3-dev

sudo apt-get install libssl-dev openssl

/usr/sbin/groupadd www

/usr/sbin/useradd -g www www

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gz

tar zxvf pcre-8.33.tar.gz

cd pcre-8.33

./configure --prefix=/Data/apps/pcre

make && make install

cd ../

wget http://nginx.org/download/nginx-1.5.1.tar.gz

tar zxvf nginx-1.5.1.tar.gz

cd nginx-1.5.1

./configure --user=www --group=www --prefix=/Data/apps/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/Data/tgz/pcre-8.33 --with-http_realip_module --with-http_image_filter_module

make

make install

cd ../

2.安装mysql

wget http://downloads.mysql.com/archives/mysql-5.6/mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz

tar zxvf mysql-5.6.10-linux-glibc2.5-x86_64.tar.gz

mv mysql-5.6.10-linux-glibc2.5-x86_64 /Data/apps/mysql

/usr/sbin/groupadd mysql

/usr/sbin/useradd -g mysql mysql

mkdir -p /Data/data/mysql/data

sudo apt-get install libaio-dev

/Data/apps/mysql/scripts/mysql_install_db --basedir=/Data/apps/mysql --datadir=/Data/data/mysql/data --user=mysql

sed -i "s#/usr/local/mysql#/Data/apps/mysql#g" /Data/apps/mysql/bin/mysqld_safe

3.安装PHP依赖库

mkdir -p /Data/apps/libs/

tar zxvf jpegsrc.v9.tar.gz

cd jpeg-9/

./configure --prefix=/Data/apps/libs --enable-shared --enable-static --prefix=/Data/apps/libs

make

make install

cd ../

wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz

tar zxvf libpng-1.6.2.tar.gz

cd libpng-1.6.2/

./configure --prefix=/Data/apps/libs

make

make install

cd ../

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz

tar zxvf freetype-2.4.12.tar.gz

cd freetype-2.4.12/

./configure --prefix=/Data/apps/libs

make

make install

cd ../

wget "http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz?modtime=1175740843&big_mirror=0"

wget "http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz?modtime=1171868460&big_mirror=0"

wget "http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz?modtime=1194463373&big_mirror=0"

tar zxvf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8/

./configure --prefix=/Data/apps/libs

make

make install

cd libltdl/

./configure --prefix=/Data/apps/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=/Data/apps/libs

make

make install

cd ../

vi /etc/ld.so.conf

添加:

/Data/apps/libs/lib

然后:

ldconfig

tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

export LDFLAGS="-L/Data/apps/libs/lib -L/usr/lib"

export CFLAGS="-I/Data/apps/libs/include -I/usr/include"

touch malloc.h

./configure --prefix=/Data/apps/libs --with-libmcrypt-prefix=/Data/apps/libs

make

make install

cd ../

4.编译安装PHP 5.5.0

wget http://www.php.net/get/php-5.5.0.tar.bz2/from/hk2.php.net/mirror

tar zxvf php-5.5.0.tar.bz2

cd php-5.5.0/

export LIBS="-lm -ltermcap -lresolv"

export DYLD_LIBRARY_PATH="/Data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"

export LD_LIBRARY_PATH="/Data/apps/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"

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

make

make install

cp php.ini-development /Data/apps/php/etc/php.ini

cd ../

ln -s /Data/apps/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

mv /Data/apps/php/etc/php-fpm.conf.default /Data/apps/php/etc/php-fpm.conf

5.编译安装PHP扩展

wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz

tar zxvf autoconf-latest.tar.gz

cd autoconf-2.69/

./configure --prefix=/Data/apps/libs

make

make install

cd ../

wget http://pecl.php.net/get/memcache-2.2.7.tgz

tar zxvf memcache-2.2.7.tgz

cd memcache-2.2.7/

export PHP_AUTOCONF="/Data/apps/libs/bin/autoconf"

export PHP_AUTOHEADER="/Data/apps/libs/bin/autoheader"

/Data/apps/php/bin/phpize

./configure --with-php-config=/Data/apps/php/bin/php-config

make

make install

cd ../

打开 /Data/apps/php/etc/php.ini 查找 ; extension_dir = "ext"

  在其后增加一行:

extension = "memcache.so"

主要参考了 张宴的安装过程 http://blog.s135.com/nginx_php_v7/

Comments
Write a Comment