最近把系統升級到 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
#! /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 --with-imap --with-imap-ssl --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() 文件 ,浏覽器輸出這個畫面表示配置成功
http://xxxxxx/Linuxjc/1159966.html TechArticle