您当前的位置:首页 > php

Ubuntu 14.04 64bit 编译安装Nginx1.7+PHP5.4+MySQL5.6

我的操作系统是14.04,其它linux系统的操作流程类似。主要安装的软件是Nginx1.7+PHP5.4+MySQL5.6FWtlinux系统宝典

1. 创建必要目录FWtlinux系统宝典

sudo mkdir ~/setupFWtlinux系统宝典
sudo mkdir /opt/softwareFWtlinux系统宝典
sudo chmod 777 /opt/softwareFWtlinux系统宝典

2. 下载必要软件FWtlinux系统宝典

cd ~/DownloadsFWtlinux系统宝典

wget http://am1.php.net/distributions/php-5.4.29.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/php-5.4.29.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://nginx.org/download/nginx-1.7.1.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/nginx-1.7.1.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.19-linux-glibc2.5-x86_64.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/mysql-5.6.19-linux-glibc2.5-x86_64.tar.gz -C ~/setup/FWtlinux系统宝典

wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.33.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/pcre-8.33.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://www.ijg.org/files/jpegsrc.v9.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/jpegsrc.v9.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz ~/DownloadsFWtlinux系统宝典
tar zxvf ~/Downloads/libpng-1.6.2.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/freetype-2.4.12.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/mhash-0.9.9.9.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/libmcrypt-2.5.8.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/mcrypt-2.6.8.tar.gz -C ~/setup/FWtlinux系统宝典

wget ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/termcap-1.3.1.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/autoconf-latest.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://ftp.gnu.org/gnu/m4/m4-latest.tar.gzFWtlinux系统宝典
tar zxvf ~/Downloads/m4-latest.tar.gz -C ~/setup/FWtlinux系统宝典

wget http://pecl.php.net/get/memcache-2.2.7.tgzFWtlinux系统宝典
tar zxvf ~/Downloads/memcache-2.2.7.tgz -C ~/setup/FWtlinux系统宝典

以上软件我已经打包好放到百度网盘,相关链接:FWtlinux系统宝典

3. 安装nginxFWtlinux系统宝典

sudo apt-get install libpcre3 libpcre3-devFWtlinux系统宝典
sudo apt-get install libssl-dev openssl libcurl4-openssl-devFWtlinux系统宝典
sudo apt-get install build-essentialFWtlinux系统宝典

sudo /usr/sbin/groupadd wwwFWtlinux系统宝典
sudo /usr/sbin/useradd -g www wwwFWtlinux系统宝典

cd ~/setup/pcre-8.33/FWtlinux系统宝典
./configure --prefix=/opt/software/pcreFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

cd ../nginx-1.7.1/FWtlinux系统宝典
./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_moduleFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

 FWtlinux系统宝典

 FWtlinux系统宝典

4. 安装MySQL FWtlinux系统宝典

cd ~/setupFWtlinux系统宝典
sudo mv mysql-5.6.19-linux-glibc2.5-x86_64 /opt/software/mysqlFWtlinux系统宝典
sudo mkdir -p /opt/software/mysql/dataFWtlinux系统宝典

sudo apt-get install libaio-devFWtlinux系统宝典

sudo /usr/sbin/groupadd mysqlFWtlinux系统宝典
sudo /usr/sbin/useradd -g mysql mysqlFWtlinux系统宝典

/opt/software/mysql/scripts/mysql_install_db --basedir=/opt/software/mysql --datadir=/opt/software/mysql/data --user=mysqlFWtlinux系统宝典
sed -i "s#/usr/local/mysql#/opt/software/mysql#g" /opt/software/mysql/bin/mysqld_safeFWtlinux系统宝典

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

 FWtlinux系统宝典

 FWtlinux系统宝典

5. 安装PHP依赖库 FWtlinux系统宝典

cd ~/setupFWtlinux系统宝典
sudo mkdir -p /opt/software/libs/FWtlinux系统宝典

cd jpeg-9/FWtlinux系统宝典
./configure --prefix=/opt/software/libs --enable-shared --enable-static --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

cd ../libpng-1.6.2/FWtlinux系统宝典
./configure --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

cd ../freetype-2.4.12/FWtlinux系统宝典
./configure --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

cd ../libmcrypt-2.5.8/FWtlinux系统宝典
./configure --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

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

cd http://www.linuxidc.com/mhash-0.9.9.9/FWtlinux系统宝典
./configure --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

6. 设置类库加载路径FWtlinux系统宝典

sudo vim /etc/ld.so.conf.d/opt-software-libs.confFWtlinux系统宝典
输入FWtlinux系统宝典
/opt/software/libs/libFWtlinux系统宝典
然后FWtlinux系统宝典
sudo ldconfigFWtlinux系统宝典

cd ../mcrypt-2.6.8/FWtlinux系统宝典
export LDFLAGS="-L/opt/software/libs/lib -L/usr/lib"FWtlinux系统宝典
export CFLAGS="-I/opt/software/libs/include -I/usr/include"FWtlinux系统宝典
touch malloc.hFWtlinux系统宝典
./configure --prefix=/opt/software/libs --with-libmcrypt-prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

cd ../termcap-1.3.1/FWtlinux系统宝典
./configure --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

7. 安装PHPFWtlinux系统宝典

sudo apt-get install libxml2-devFWtlinux系统宝典
export LIBS="-lm -ltermcap -lresolv"FWtlinux系统宝典
export DYLD_LIBRARY_PATH="/opt/software/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"FWtlinux系统宝典
export LD_LIBRARY_PATH="/opt/software/mysql/lib/:/lib/:/usr/lib/:/usr/local/lib:/lib64/:/usr/lib64/:/usr/local/lib64"FWtlinux系统宝典

cd ../php-5.4.29/FWtlinux系统宝典
./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-soapFWtlinux系统宝典

sudo ln -s /opt/software/mysql/lib/libmysqlclient.so.18 /usr/lib/FWtlinux系统宝典

wget http://pear.php.net/go-pear.pharFWtlinux系统宝典
sudo mv go-pear.phar /opt/software/php/binFWtlinux系统宝典

sudo make && sudo make installFWtlinux系统宝典

sudo cp php.ini-development /opt/software/php/etc/php.iniFWtlinux系统宝典
sudo ln -s /opt/software/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylibFWtlinux系统宝典
sudo cp /opt/software/php/etc/php-fpm.conf.default /opt/software/php/etc/php-fpm.confFWtlinux系统宝典

8. 安装PHP扩展FWtlinux系统宝典

cd ../m4-1.4.17/FWtlinux系统宝典
./configure --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典
export PATH=/home/davidhhuan/setup/m4-1.4.17:$PATHFWtlinux系统宝典

cd ../autoconf-2.69/FWtlinux系统宝典
./configure --prefix=/opt/software/libsFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

cd ../memcache-2.2.7/FWtlinux系统宝典
export PHP_AUTOCONF="/opt/software/libs/bin/autoconf"FWtlinux系统宝典
export PHP_AUTOHEADER="/opt/software/libs/bin/autoheader"FWtlinux系统宝典
/opt/software/php/bin/phpizeFWtlinux系统宝典
./configure --with-php-config=/opt/software/php/bin/php-configFWtlinux系统宝典
sudo make && sudo make installFWtlinux系统宝典

9. 设置开机自启动FWtlinux系统宝典

NginxFWtlinux系统宝典

sudo vim /etc/init.d/nginxFWtlinux系统宝典

内容如下FWtlinux系统宝典

#! /bin/shFWtlinux系统宝典

### BEGIN INIT INFOFWtlinux系统宝典
# Provides:          nginxFWtlinux系统宝典
# Required-Start:    $local_fs $remote_fs $network $syslogFWtlinux系统宝典
# Required-Stop:    $local_fs $remote_fs $network $syslogFWtlinux系统宝典
# Default-Start:    2 3 4 5FWtlinux系统宝典
# Default-Stop:      0 1 6FWtlinux系统宝典
# Short-Description: starts the nginx web serverFWtlinux系统宝典
# Description:      starts nginx using start-stop-daemonFWtlinux系统宝典
### END INIT INFOFWtlinux系统宝典

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binFWtlinux系统宝典
DAEMON=/opt/software/nginx/sbin/nginxFWtlinux系统宝典
NAME=nginxFWtlinux系统宝典
DESC=nginxFWtlinux系统宝典

DAEMON_OPTS=''FWtlinux系统宝典

test -x $DAEMON || exit 0FWtlinux系统宝典

# Include nginx defaults if availableFWtlinux系统宝典
#if [ -f /etc/default/nginx ] ; thenFWtlinux系统宝典
#      . /etc/default/nginxFWtlinux系统宝典
#fiFWtlinux系统宝典

set -eFWtlinux系统宝典

. /lib/lsb/init-functionsFWtlinux系统宝典

#test_nginx_config() {FWtlinux系统宝典
#  if $DAEMON -t $DAEMON_OPTSFWtlinux系统宝典
#  thenFWtlinux系统宝典
#    return 0FWtlinux系统宝典
#  elseFWtlinux系统宝典
#    return $?FWtlinux系统宝典
#  fiFWtlinux系统宝典
#}FWtlinux系统宝典

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

exit 0FWtlinux系统宝典

sudo update-rc.d nginx defaultsFWtlinux系统宝典

php-fpmFWtlinux系统宝典

sudo cp /opt/setup/php-5.4.29/sapi/fpm/init.d.php-fpm.in /etc/init.d/php-fpmFWtlinux系统宝典
sudo groupadd nobodyFWtlinux系统宝典
sudo touch /opt/software/php/var/run/php-fpm.pidFWtlinux系统宝典
sudo update-rc.d php-fpm defaultsFWtlinux系统宝典
vim /etc/init.d/php-fpmFWtlinux系统宝典

替换如下内容FWtlinux系统宝典

prefix=@prefix@FWtlinux系统宝典
exec_prefix=@exec_prefix@FWtlinux系统宝典

php_fpm_BIN=@sbindir@/php-fpmFWtlinux系统宝典
php_fpm_CONF=@sysconfdir@/php-fpm.confFWtlinux系统宝典
php_fpm_PID=@localstatedir@/run/php-fpm.pidFWtlinux系统宝典

变成FWtlinux系统宝典

prefix=/opt/software/phpFWtlinux系统宝典
exec_prefix=/opt/software/php/binFWtlinux系统宝典

php_fpm_BIN=/opt/software/php/sbin/php-fpmFWtlinux系统宝典
php_fpm_CONF=/opt/software/php/etc/php-fpm.confFWtlinux系统宝典
php_fpm_PID=/opt/software/php/var/run/php-fpm.pidFWtlinux系统宝典

MySQLFWtlinux系统宝典

sudo cp /opt/software/mysql/support-files/mysql.server /etc/init.d/mysqldFWtlinux系统宝典
sudo vim /etc/init.d/mysqldFWtlinux系统宝典
#找到FWtlinux系统宝典
basedir=FWtlinux系统宝典
datadir=FWtlinux系统宝典
#变成FWtlinux系统宝典
basedir=/opt/software/mysqlFWtlinux系统宝典
datadir=/opt/software/mysql/dataFWtlinux系统宝典

sudo update-rc.d mysqld defaultsFWtlinux系统宝典

10. 加入环境变量FWtlinux系统宝典

sudo vim /etc/profileFWtlinux系统宝典

加入FWtlinux系统宝典

export PATH=$PATH:/opt/software/mysql/bin:/opt/software/php/bin:/opt/software/php/sbin:/opt/software/mysql/binFWtlinux系统宝典

加载FWtlinux系统宝典

source /etc/profileFWtlinux系统宝典

至此,基本上就可以使用了。FWtlinux系统宝典

Have fun with Ubuntu!FWtlinux系统宝典

6.2实战部署Nginx+MySQL+PHP FWtlinux系统宝典

使用Nginx搭建WEB服务器 FWtlinux系统宝典

搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 FWtlinux系统宝典

CentOS 6.3下Nginx性能调优 FWtlinux系统宝典

CentOS 6.3下配置Nginx加载ngx_pagespeed模块 FWtlinux系统宝典

CentOS 6.4安装配置Nginx+Pcre+php-fpm FWtlinux系统宝典

Nginx安装配置使用详细笔记 FWtlinux系统宝典

Nginx日志过滤 使用ngx_log_if不记录特定日志 FWtlinux系统宝典

Nginx 的详细介绍FWtlinux系统宝典
Nginx 的下载地址FWtlinux系统宝典

更多Ubuntu相关信息见 专题页面 FWtlinux系统宝典



沪ICP备10206494号-4