开发者社区> ibonker> 正文
阿里云
为了无法计算的价值
打开APP
阿里云APP内打开

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.
+关注继续查看

我的操作系统是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

 

 

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

作者:Bonker
出处:http://www.cnblogs.com/Bonker
QQ:519841366
       
本页版权归作者和博客园所有,欢迎转载,但未经作者同意必须保留此段声明, 且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
ubuntu系统下安装php环境
ubuntu系统下安装php环境
117 0
centos下 Apache、php、mysql默认安装路径
apache: 如果采用RPM包安装,安装路径应在 /etc/httpd目录下 apache配置文件:/etc/httpd/conf/httpd.conf Apache模块路径:/usr/sbin/apachectl web目录:/var/www/html 如果采用源代码安装,一般默认安装在/usr/local/apache2目录下 php: 如果采用RPM包安装,安装路
3021 0
MySQL PHP 语法
MySQL PHP 语法 MySQL 可应用于多种语言,包括 PERL, C, C++, JAVA 和 PHP。 在这些语言中,Mysql在PHP的web开发中是应用最广泛。 在本教程中我们大部分实例都采用了 PHP 语言。
799 0
+关注
ibonker
乐于分享
180
文章
0
问答
文章排行榜
最热
最新
相关电子书
更多
低代码开发师(初级)实战教程
立即下载
阿里巴巴DevOps 最佳实践手册
立即下载
冬季实战营第三期:MySQL数据库进阶实战
立即下载