Ubuntu 14 编译安装 PHP 5.4.45 + Nginx 1.4.7 + MySQL 5.6.26 笔记

Ubuntu 14 编译安装 PHP 5.4.45 + Nginx  1.8.0/1.4.7 + MySQL 5.6.26 笔记,主要是给自己的PC机安装,非生产环境!

一、下载必要的源码

1.1.下载PHP

wget -c http://cn2.php.net/distributions/php-5.4.45.tar.gz

1.2.下载Nginx

wget -c http://nginx.org/download/nginx-1.4.7.tar.gz

1.3.下载MySQL

wget -c  http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

2、PHP库

wget -c http://www.ijg.org/files/jpegsrc.v9.tar.gz
wget -c http://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz
wget -c http://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz
wget -c http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
wget -c http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
wget -c http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
wget -c http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
wget -c ftp://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz
wget -c http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
wget -c http://ftp.gnu.org/gnu/m4/m4-latest.tar.gz
wget -c http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
wget -c http://pecl.php.net/get/memcache-2.2.7.tgz

3、Nginx库

3.1.正则表达式库 PERL 5 regular expression pattern matching

官网:http://sourceforge.net/projects/pcre/files/pcre/,下载

wget -c ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.bz2

3.2.zbli压缩

wget -c http://prdownloads.sourceforge.net/libpng/zlib-1.2.8.tar.gz

3.3.openssl

wget -c ftp://ftp.openssl.org/source/openssl-1.0.2.tar.gz

源码存放路径 规划

/opt/software-backup/lnmp/

/config  #配置文件 存放地

/source  #源码包 存放地

/source2  #源码包 拷贝 存放地,解压后的文件都在这

/lib/

/autoconf-latest.tar.gz

/m4-latest.tar.gz

/termcap-1.3.1.tar.gz

/mysql/

/mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz

/nginx/

/ext/

/nginx-gridfs/

/mongo-c-driver-0.3.1.tar.gz

/nginx-gridfs-0.8.tar.gz

/lib/

/openssl-1.0.2.tar.gz

/pcre-8.38.tar.bz2

/zlib-1.2.8.tar.gz

/nginx-1.4.7.tar.gz

/php/

/ext/

/memcache-2.2.7.tgz

/lib/

/bzip2-1.0.6.tar.gz

/freetype-2.4.12.tar.gz

/jpegsrc.v9.tar.gz

/libiconv-1.14.tar.gz

/libmcrypt-2.5.8.tar.gz

/libpng-1.6.2.tar.gz

/mcrypt-2.6.8.tar.gz

/mhash-0.9.9.9.tar.gz

/php-5.4.45.tar.gz

 

二、安装 C/C++ 编译器

sudo apt-get -y install gcc build-essential make

三、安装Nginx

sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install libssl-dev openssl libcurl4-openssl-dev
sudo apt-get install build-essential libtool

#安装pcre库
cd /opt/software-backup/lnmp/source2/nginx/lib
sudo tar -xjvf ./pcre-8.38.tar.bz2
cd ./pcre-8.38
sudo ./configure
sudo make && sudo make install

#安装zlib库
cd /opt/software-backup/lnmp/source2/nginx/lib
sudo tar -xzvf ./zlib-1.2.8.tar.gz
cd ./zlib-1.2.8
sudo ./configure
sudo make && sudo make install

#安装ssl
cd /opt/software-backup/lnmp/source2/nginx/lib
sudo tar -xzvf ./openssl-1.0.2.tar.gz
cd openssl-1.0.2

#安装第三方插件
#解压nginx-grids
#cd /opt/software-backup/lnmp/source2/nginx/ext/nginx-gridfs
#tar -xzvf ./nginx-gridfs-0.8.tar.gz

#解压mongo-c-driver
sudo tar -xzvf ./mongo-c-driver-0.3.1.tar.gz
sudo mv ./mongo-c-driver-0.3.1/* ./nginx-gridfs-0.8/mongo-c-driver

#添加nginx用户组及用户
#sudo groupadd www
#sudo useradd -g www -s /usr/sbin/nologin www #不让www用户直接登录

#安装nginx
cd /opt/software-backup/lnmp/source2/nginx
sudo tar -xzvf ./nginx-1.4.7.tar.gz
cd ./nginx-1.4.7
sudo mkdir /opt/software/nginx

sudo ./configure --prefix=/opt/software/nginx --user=jianbao --group=jianbao --sbin-path=/opt/software/nginx/nginx --conf-path=/opt/software/nginx/conf/nginx.conf --pid-path=/opt/software/nginx/logs/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-pcre=/opt/software-backup/lnmp/source2/nginx/lib/pcre-8.38 --with-zlib=/opt/software-backup/lnmp/source2/nginx/lib/zlib-1.2.8 --with-openssl=/opt/software-backup/lnmp/source2/nginx/lib/openssl-1.0.2

sudo make && sudo make install

#复制配置文件
sudo cp -rf /opt/software-backup/lnmp/config/nginx.conf  /opt/software/nginx/conf/nginx.conf
 
#创建www目录
#sudo mkdir /var/www
 
#创建虚拟主机配置文件目录
sudo mkdir /opt/software/nginx/conf/vhost
 
#设置权限
sudo chmod -R +x /opt/software/nginx/
sudo chown -R jianbao:jianbao /opt/software/nginx
 
#设置开机自动启动
sudo cp -rf /opt/software-backup/lnmp/config/nginx /etc/init.d/nginx
sudo update-rc.d nginx defaults
sudo service nginx start #启动nginx

 

三、安装MySQL

#安装依赖库
sudo apt-get install libaio-dev

#移动到安装目录
sudo mkdir /opt/software/mysql
cd /opt/software-backup/lnmp/source2/mysql
tar -xzvf ./mysql-5.6.26-linux-glibc2.5-x86_64.tar.gz
sudo mv ./mysql-5.6.26-linux-glibc2.5-x86_64/* /opt/software/mysql

# 新建用户
sudo groupadd mysql
sudo useradd -g mysql -s /usr/sbin/nologin mysql   #不让mysql用户直接登录
sudo chown -R mysql:mysql  /opt/software/mysql/

#初始化数据库
sudo /opt/software/mysql/scripts/mysql_install_db --basedir=/opt/software/mysql --datadir=/opt/software/mysql/data --user=mysql

#配置mysqld_safe(安装路径替换)
sudo sed -i "s#/usr/local/mysql#/opt/software/mysql#g" /opt/software/mysql/bin/mysqld_safe


#设置basedir, datadir
sudo sed -i "s#basedir=/usr/local/mysql#basedir=/opt/software/mysql#g" /etc/init.d/mysqld
sudo sed -i "s#datadir=/usr/local/mysql/data#datadir=/opt/software/mysql/data#g" /etc/init.d/mysqld
sudo sed -i "s#bindir=/usr/local/mysql/bin#bindir=/opt/software/mysql/bin#g" /etc/init.d/mysqld
sudo sed -i "s#libexecdir=/usr/local/mysql/bin#libexecdir=/opt/software/mysql/bin#g" /etc/init.d/mysqld

#修改配置文件
sudo cp /opt/software-backup/lnmp/config/my.cnf  /opt/software/mysql/

#设置开机自动启动
sudo cp /opt/software/mysql/support-files/mysql.server /etc/init.d/mysqld
sudo update-rc.d mysqld defaults
sudo service mysqld start #启动mysql
​
#设置root的密码为123456
sudo /opt/software/mysql/bin/mysqladmin -u root password

 

四、安装PHP

##################################################
### 1、安装PHP依赖库
##################################################

# 安装依赖库
sudo apt-get install libxml2-dev libjpeg-dev libpng-dev libfreetype6-dev

#安装 libmcryp
cd /opt/software-backup/lnmp/source2/php/lib
sudo tar -xzvf ./libmcrypt-2.5.8.tar.gz
cd ./libmcrypt-2.5.8
sudo ./configure --prefix=/usr
sudo make && sudo make install
 
#安装 mhash
cd /opt/software-backup/lnmp/source2/php/lib
sudo tar -xzvf ./mhash-0.9.9.9.tar.gz
cd ./mhash-0.9.9.9
sudo ./configure --prefix=/usr
sudo make && sudo make install
 
#安装 mcrypt
sudo /sbin/ldconfig  #搜索出可共享的动态链接库
cd /opt/software-backup/lnmp/source2/php/lib
sudo tar -xzvf ./mcrypt-2.6.8.tar.gz
cd ./mcrypt-2.6.8
sudo ./configure
sudo make && sudo make install
 
#安装 libiconv
cd /opt/software-backup/lnmp/source2/php/lib
sudo tar -xzvf ./libiconv-1.14.tar.gz
cd ./libiconv-1.14
sudo ./configure --prefix=/usr
sudo make && sudo make install

#安装bzip2
cd /opt/software-backup/lnmp/source2/php/lib
sudo tar -xzvf ./bzip2-1.0.6.tar.gz
cd ./bzip2-1.0.6
sudo make && sudo make install

##################################################
### 2、安装 PHP php-5.4.45
##################################################
cd /opt/software-backup/lnmp/source2/php
sudo tar -xzvf ./php-5.4.45.tar.gz
cd ./php-5.4.45
 
#生成配置
sudo ./configure --prefix=/opt/software/php --with-config-file-path=/opt/software/php/etc --with-openssl --with-zlib --with-bz2 --with-gd --with-jpeg-dir --with-png-dir --with-gettext --with-mhash --with-freetype-dir --with-mcrypt --with-iconv --with-curl --with-curlwrappers --with-xmlrpc --with-mysql=/opt/software/mysql --with-pdo-mysql=/opt/software/mysql --with-mysqli=/opt/software/mysql/bin/mysql_config --enable-zip --enable-mbstring --enable-mbregex --enable-bcmath --enable-soap --enable-sockets --enable-ftp --enable-gd-native-ttf --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-fpm --with-fpm-user=jianbao --with-fpm-group=jianbao --without-pear 
 
#编译安装
sudo make && make install
 
##################################################
### 4、配置php.ini
##################################################
#cp ./php.ini-production /opt/software/php/etc/php.ini #复制php配置文件到安装目录
sudo mv /etc/php.ini /etc/php.ini.old
sudo cp -rf /opt/software-backup/lnmp/config/php.ini  /opt/software/php/etc/php.ini
sudo ln -s /opt/software/php/etc/php.ini /etc/php.ini #添加软链接
 
##################################################
### 5、配置php-fpm
##################################################
#cp /opt/software/php/etc/php-fpm.conf.default /opt/software/php/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
sudo cp -rf /opt/software-backup/lnmp/config/php-fpm.conf /opt/software/php/etc/php-fpm.conf
 
#设置 php-fpm 开机启动
sudo cp -rf /opt/software-backup/lnmp/config/php-fpm  /etc/init.d/php-fpm #拷贝php-fpm到启动目录
sudo chmod +x /etc/init.d/php-fpm #添加执行权限
sudo update-rc.d php-fpm defaults #设置开机启动
 
sudo service php-fpm start  #启动php-fpm
sudo service nginx restart  #重启nginx
 
sudo cp -rf /opt/software-backup/lnmp/source2/index.php  /opt/software/nginx/html
sudo chmod -R +x /opt/software/nginx/html
sudo chown -R jianbao:jianbao /opt/software/nginx/html
posted @ 2016-07-18 13:45  52php  阅读(1635)  评论(0编辑  收藏  举报