最近把ubuntu14系统升级到 ubuntu16长期支持版 ,重新部署了lnmp环境
约定几个目录 源码目录 /usr/local/src
mysql /usr/local/mysql
php /usr/local/php
nginx /usr/local/nginx
gcc/g++ :MySQL 5.6开始,需要使用g++进行编译。
bison :MySQL语法解析器需要使用bison进行编译。
libncurses5-dev :用于终端操作的开发包.(注:Debian/Ubuntu下需要安装libncurses5-dev;Redhat下需要安装 ncurses-devel)
zlib :MySQL使用zlib进行压缩
libxml2 :用于XML输入输出方式的支持。
openssl :使用openssl安全套接字方式通信。
dtrace :用于诊断MySQL问题。
cmake :MySQL 5.5开始,使用cmake进行工程管理,cmake需要2.8以上版本。
sudo apt-get install gcc
sudo apt-get install libxml2
sudo apt-get install libncurses5-dev bison
安装cmake 下载地址 https://cmake.org/download/
mkdir /usr/local/src
tar zxvf cmake-3.6.1.tar.gz
mv cmake-3.6.1 /usr/local/src
cd cmake-3.6.1
./configure make && make install
vim ~/.bashrc
添加
export PATH="/usr/local/src/cmake-3.6.1/bin/cmake:$PATH"
从MySQL 5.7.5开始Boost库是必需的,下载Boost库 http://sourceforge.net/projects/boost/files/boost/
tar zxvf boost_1_59_0.tar.gz
mv boost_1_59_0 /usr/local/
mkdir -p /usr/local/mysql/
mkdir -p /usr/local/mysql/data/
根据需要另外创建mysql socket 文件保存目录,如果要重新指定存放位置,需要重新编译
groupadd mysql 添加mysql 用户组
useradd mysql -g mysql 添加mysql用户 并指定mysql用户组
chown -R mysql:mysql /usr/local/mysql/ 改变指定目录以及其子目录下权限为mysql用户和mysql用户组
mysql官方下载地址
http://dev.mysql.com/downloads/mysql/ 此次有个坑:一定要选择选择可编译版本
tar zxvf mysql-5.7.14.tar.gz
cd mysql-5.7.14
编译
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 -DWITHOUT_FEDERATED_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock -DCOMPILATION_COMMENT="string"-DENABLED_PROFILING=1 -DOPTIMIZER_TRACE=1 -DWITH_DEBUG=1 -DWITH_BOOST=/usr/local/boost
make && make install
在5.5和5.6版本中,mysql数据库是使用mysqld_db_install命令进行初始化的;在5.7之后,数据库初始化发生了改变,需要mysqld命令进行初始化:
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
---以root初始化操作时要加--user=mysql参数,生成一个随机密码(注意保存登录时用)
chown -R mysql:mysql /usr/local/mysql/data
复制默认配置文件到/etc
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
sudo chown mysql:mysql /etc/my.cnf
vim /etc/my.cnf
[client]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
[mysqld]
port = 3306
socket = /usr/local/mysql/data/mysql.sock
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
/usr/local/mysql/bin/mysqld_safe --user --defaults-file/etc/my.cnf
netstat -altn | grep 3306 或 ps -ef|grep mysql
tcp6 0 0 :::3306 :::* LISTEN
/usr/local/mysql/bin/mysql -uroot -p
mysql> set password for root@localhost=password('新密码');
Query OK, 0 rows affected, 1 warning (0.00 sec)
cd /usr/local/mysql/
cp support-files/mysql.server /etc/init.d/mysql
sudo chmod 755 /etc/init.d/mysql
sudo apt-get install sysv-rc-conf
sudo sysv-rc-conf mysql on
systemctl enable mysql.service
sudo /etc/init.d/mysql {stop|start} 或者 sudo service mysql start | stop
sudo vim ~/.bashrc
export PATH="/usr/local/mysql/bin/:$PATH"
export PATH
准备工作
需要 zlib 库 http://www.zlib.net/
tar -xvf zlib-1.2.8.tar.gz -C /usr/local/src
mv /usr/local/src/zlib-1.2.8 /usr/local/src/zlib
cd /usr/local/src/zlib
./configure --shared && make test && make install
cp zutil.h /usr/local/include
cp zutil.c /usr/local/include
mkdir /usr/local/zlib
./configure --prefix=/usr/local/zlib
Add /usr/local/zlib/lib to /etc/ld.so.conf
ldconfig
需要 pcre 库 http://www.pcre.org/
tar zxvf pcre-8.39.tar.gz -C /usr/local/src
mv /usr/local/src/pcre-8.39 /usr/local/src/prce
cd /usr/local/prce
./configure && make && make install
ssl功能需要openssl库 http://www.openssl.org/source/ 下载1.0.2g版本
tar zxvf openssl-1.0.2g.tar.gz -C /usr/local/src
cd /usr/local/openssl-1.0.2g
./config --prefix=/usr/local/ shared
make test && make install
添加到动态链接库
Add /usr/local/lib to /etc/ld.so.conf
ldconfig
groupadd www
useradd www -g www
chown -R www:www /usr/local/nginx
nginx官网 http://nginx.org/
tar zxvf nginx-1.10.1.tar.gz -C /usr/local/src
cd /usr/local/src/nginx-1.10.1
编译安装
./configure --prefix=/usr/local/nginx --with-openssl=/usr/local/src/openssl-1.0.2g --with-pcre=/usr/local/src/pcre --with-zlib=/usr/local/src/zlib --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-http_stub_status_module
make && make install
/usr/local/nginx/sbin/nginx
ps -ef | grep nginx
/usr/local/nginx/sbin/nginx -s stop, quit, reopen, reload
创建nginx启动脚本
vim /etc/init.d/nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#! /bin/sh
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC=
"nginx daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
set -e
[ -x
"$DAEMON"
] ||
exit
0
do_start() {
$DAEMON -c $CONFIGFILE || echo -n
"nginx already running"
}
do_stop() {
kill -
INT
`cat $PIDFILE` || echo -n
"nginx not running"
}
do_reload() {
kill -HUP `cat $PIDFILE` || echo -n
"nginx can't reload"
}
case
"$1"
in
start)
echo -n
"Starting $DESC: $NAME"
do_start
echo
"."
;;
stop)
echo -n
"Stopping $DESC: $NAME"
do_stop
echo
"."
;;
reload|graceful)
echo -n
"Reloading $DESC configuration..."
do_reload
echo
"."
;;
restart)
echo -n
"Restarting $DESC: $NAME"
do_stop
do_start
echo
"."
;;
*)
echo
"Usage: $SCRIPTNAME {start|stop|reload|restart}"
>&2
exit
3
;;
esac
exit
0
|
:wq
sudo chmod 755 /etc/init.d/nginx
sudo sysv-rc-conf nginx on
/etc/init.d/nginx {start|stop|reload|restart}
vim /usr/local/nginx/conf/nginx.conf
location / {
root /www;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /www$fastcgi_script_name;
include fastcgi_params;
}
//注:黑体www为web根目录,改成对应目录即可
apt-get 安装php 7 php5.6
php 7
apt-get install php7.0-mysql php7.0-curl php7.0-gd php7.0-intl php-pear php-imagick php7.0-imap php7.0-mcrypt php-memcache php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-mbstring php-gettext
php 5.6
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6
sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml
t1lib(php字体类扩展) 版本t1lib-5.1.2.tar.gz http://www.t1lib.org/
解压
tar zxvf t1lib-5.1.2.tar.gz -C /usr/local/src
cd /usr/local/src t1lib-5.1.2
./configure
提示错误 : X11/Xaw/Label.h: No such file or directory
缺少libxaw库
sudo apt-get install libxaw7-dev
./configure && make without_doc && make install
官网下载php5.6.25源码包
tar zxvf php-5.6.23.tar.gz -C /usr/local/src
cd /usr/local/src/
编译安装
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/usr/local/mysql/data/mysql.sock --enable-mbstring --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --with-fpm-group=www --with-fpm-user=www --enable-bcmath --enable-bcmath --enable-soap --enable-calendar --with-pcre-dir=/usr/local/src/pcre --with-mcrypt --enable-xml --with-xmlrpc --with-xsl --enable-sockets --enable-opcache --with-gd --with-jpeg-dir --with-png-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf --enable-dtrace --with-openssl --with-kerberos --with-openssl-dir=/usr/local/src/openssl-1.0.2g --enable-zip --with-zlib-dir=/usr/local/src/zlib --with-t1lib=/usr/local/share/t1lib --with-libxml-dir --with-iconv-dir --with-libzip --enable-intl --with-curl=DIR --enable-ftp
提示Cannot find sys/sdt.h which is required for DTrace support
根据官方提示dTrace某些开发版需要安装 SystemTap SDT 开发包
apt-cache search SystemTap SDT
apt-get install systemtap-sdt-dev
提示curl 编译失败
apt-get install libcurl4-gnutls-dev
apt-get install curl php5.6-curl
提示重新安装libzip
apt-get install libzip-dev
make clean
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql-sock=/usr/local/mysql/data/mysql.sock --enable-mbstring --enable-mysqlnd --with-mysql=mysqlnd --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --enable-fpm --with-fpm-group=www --with-fpm-user=www --enable-bcmath --enable-bcmath --enable-soap --enable-calendar --with-pcre-dir=/usr/local/src/pcre --with-mcrypt --enable-xml --with-xmlrpc --with-xsl --enable-sockets --enable-opcache --with-gd --with-jpeg-dir --with-png-dir --with-xpm-dir --with-freetype-dir --enable-gd-native-ttf --enable-dtrace --with-openssl --with-kerberos --with-openssl-dir=/usr/local/src/openssl-1.0.2g --enable-zip --with-zlib-dir=/usr/local/src/zlib --with-t1lib=/usr/local/share/t1lib --with-libxml-dir --with-iconv-dir --with-libzip --enable-intl --with-curl=DIR --enable-ftp
make && make test
测试通过进行安装
make install
从源文件复制php.ini到目录
cp php.ini-development /usr/local/php/etc/php.ini
复制php-fpm.conf
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sudo cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
sudo sysv-rc-conf php-fpm on
sudo cp ./sapi/fpm/init.d.php-fpm /usr/local/php/sbin/init.d.php-fpm
sudo chmod 755 /etc/init.d/php-fpm
cd /usr/local/php/sbin/
chmod 755 init.d.php-fpm
./init.d.php-fpm {start|stop|force-quit|restart|reload|status}
vim ~/.bashrc
export PATH="/usr/local/php/bin/:$PATH"
export PATH="/usr/local/php/sbin/:$PATH"
export PATH
chown -R www:www /usr/local/php
查看端口
sudo netstat -tulpn
pm.max_children = 5
pm.start_servers = 2 在启动时启动的子进程数量
pm.min_spare_servers = 1 处于空闲"idle"状态的最小子进程,如果空闲进程数量小于这个值,那么相应的子进程会被创建
pm.max_spare_servers = 3 最大空闲子进程数量,空闲子进程数量超过这个值,那么相应的子进程会被杀掉。
在nginx web 目录建立 phpinfo() 文件 ,浏览器输出这个画面表示配置成功