Ubuntu 14.04 LNMP源碼編譯環境搭建 Nginx-1.9.1 PHP-5.6.9 Mariadb-10.0.19 完整教程

教程導航

1.源碼下載

2.源碼編譯

3.環境配置

1.源碼下載

cd /usr
wget http://mirrors.opencas.cn/mariadb/mariadb-10.0.19/source/mariadb-10.0.19.tar.gz
wget http://php.net/distributions/php-5.6.9.tar.gz
wget http://nginx.org/download/nginx-1.9.1.tar.gz
wget http://ncu.dl.sourceforge.net/project/pcre/pcre/8.37/pcre-8.37.tar.gz
wget http://zlib.net/zlib-1.2.8.tar.gz
wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz
wget http://curl.haxx.se/download/curl-7.42.1.tar.gz
wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz
wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.17.tar.gz
wget http://download.icu-project.org/files/icu4c/55.1/icu4c-55_1-src.tgz
wget http://ncu.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

2.源碼編譯

2.1編譯環境搭建

apt-get install build-essential -p
apt-get install libncurses5-dev -p
apt-get install mysql-client -p

2.2解壓源碼

tar -zxvf mariadb-10.0.19.tar.gz
tar -zxvf php-5.6.9.tar.gz
tar -zxvf nginx-1.9.1.tar.gz
tar -zxvf pcre-8.37.tar.gz
tar -zxvf zlib-1.2.8.tar.gz
tar -zxvf openssl-1.0.2a.tar.gz
tar -zxvf curl-7.42.1.tar.gz
tar -zxvf jpegsrc.v9a.tar.gz
tar -zxvf libpng-1.6.17.tar.gz
tar -zxvf icu4c-55_1-src.tgz
tar -zxvf libmcrypt-2.5.8.tar.gz

2.3編譯部分必要庫

cd pcre-8.37
./configure && make && make install
cd ..
cd zlib-1.2.8
./configure && make && make install
cd ..
cd openssl-1.0.2a
./configure && make && make install
cd ..
cd curl-7.42.1
./configure && make && make install
cd ..
cd jpegsrc.v9a
./configure && make && make install
cd ..
cd libpng-1.6.17
./configure && make && make install
cd ..
cd icu4c-55_1-src
./configure && make && make install
cd ..
cd libmcrypt-2.5.8
./configure && make && make install
cd ..
編譯Nginx

./configure --prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=www-data \
--group=www-data \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-http_spdy_module \
--with-ipv6 \
--with-threads \
--with-stream \
--with-stream_ssl_module \
--with-http_ssl_module \
--with-pcre=/usr/pcre-8.37 \
--with-zlib=/usr/zlib-1.2.8 \
--with-openssl=/usr/openssl-1.0.2a
make && make install
cd ..

編譯php

cd php-5.6.9
./configure --prefix=/usr/local/php \
--enable-fpm \
--enable-mysqlnd \
--with-mysql \
--with-mysqli \
--with-pdo-mysql \
--enable-opcache \
--enable-pcntl \
--enable-mbstring \
--enable-soap \
--enable-zip \
--enable-calendar \
--enable-bcmath \
--enable-exif \
--enable-ftp \
--enable-intl \
--with-openssl \
--with-zlib \
--with-curl \
--with-gd \
--with-zlib-dir \
--with-png-dir \
--with-jpeg-dir \
--with-gettext \
--with-mhash \
--with-mcrypt \
--disable-fileinfo
make && make install
cd ..

編譯Mariadb


cd mariadb-10.0.19
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mydata  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STPRAGE_ENGINE=1  -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWIYH_READLINE=1 -DWIYH_SSL=system -DVITH_ZLIB=system -DWITH_LOBWRAP=0 -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
make && make install
cd ..
3.配置環境

3.1nginx

vi /etc/nginx/nginx.conf
--------start-------------
location ~ \.php$ {
	fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
	fastcgi_param  SCRIPT_FILENAME  /var/www/html/$fastcgi_script_name;
	include        fastcgi_params;
}
---------end-------------

3.2php

cp php.ini-production /usr/local/php/lib/php/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
------start---------
pid = run/php-fpm.pid
user = www-data
group = www-data
------end-----------
3.3 Maridb

groupadd mysql
useradd -g mysql mysql -s /bin/false
mkdir -p /usr/local/mysql
mkdir -p /data/mydata
chown -R mysql:mysql /data/mydata
chown -R mysql:mysql /usr/local/mysql
chmod 744 -R /data/mydata
chmod 744 -R /usr/local/mysql
cp /usr/mariadb-10.0.19/support-files/my-huge.cnf  /etc/my.cnf 
vi /etc/my.cnf
------start------
[mysqld]
basedir=/usr/local/mysql
user=mysql
pid-file = /usr/local/mysql/mysql.pid
datadir = /data/mydata
#thread_concurrency = 2
------end---------
/usr/mariadb-10.0.19/scripts/mysql_install_db --user=mysql --datadir=/data/mydata --basedir=/usr/local/mysql
cp /usr/mariadb-10.0.19/support-files/mysql.server  /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
service mysqld restart

3.4nginx bash啓動

vi /etc/init.d/nginx
---------start---------
#!/bin/sh
### BEGIN INIT INFO
# Provides:    nginx
# Required-Start:
# Required-Stop:
# Default-Start:        2 3 4 5
# Default-Stop:        0 1 6
# Short-Description: nginx
# Description: nginx server
### END INIT INFO
. /lib/lsb/init-functions
PROGRAM=/usr/sbin/nginx
nginx_pid=/var/run/nginx.pid
test -x $PROGRAM || exit 0
case "$1" in
  start)
    if [ -e $nginx_pid  ]
	then
    log_begin_msg "Nginx already start..."
	log_end_msg 1
	else
	log_begin_msg "Starting Nginx server"
	/usr/sbin/nginx
    log_end_msg 0
	fi
	exit 1
    ;;
  stop)
    if [ -e $nginx_pid  ]
    then
		PID=`cat /var/run/nginx.pid`
		log_begin_msg "Stopping Nginx server"
		if [ ! -z "$PID" ]; then
			kill -15 $PID
		fi
		log_end_msg 0
	else
		log_begin_msg "Nginx server PID file could not be found!"
		log_end_msg 1
	fi
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    log_success_msg "Usage: service nginx {start|stop|restart}"
    exit 1
esac
exit 0
--------end--------------
chmod +x /etc/init.d/nginx
service nginx restart

3.5 php-fpm bash啓動

vi /etc/init.d/php-fpm
--------------start-----------
#!/bin/sh
### BEGIN INIT INFO
# Provides:    PHP-FPM
# Required-Start:
# Required-Stop:
# Default-Start:        2 3 4 5
# Default-Stop:        0 1 6
# Short-Description: PHP-FPM
# Description: PHP-FPM server
### END INIT INFO
. /lib/lsb/init-functions
PROGRAM=/usr/local/php/sbin/php-fpm
php_pid=/usr/local/php/var/run/php-fpm.pid
test -x $PROGRAM || exit 0
case "$1" in
  start)
    if [ -e $php_pid  ]
	then
    log_begin_msg "PHP-FPM already start..."
	log_end_msg 1
	else
	log_begin_msg "Starting PHP-FPM server"
	/usr/local/php/sbin/php-fpm
    log_end_msg 0
	fi
	exit 1
    ;;
  stop)
    if [ -e $php_pid  ]
    then
		PID=`cat $php_pid`
		log_begin_msg "Stopping PHP-FPM server"
		kill -15 $PID
		log_end_msg 0
	else
		log_begin_msg "PHP-FPM server PID file could not be found!"
		log_end_msg 1
	fi
    ;;
  restart)
    $0 stop
    $0 start
    ;;
  *)
    log_success_msg "Usage: service PHP-FPM {start|stop|restart}"
    exit 1
esac
exit 0
-----------end--------------
chmod +x /etc/init.d/php-fpm
service php-fpm restart


終結

update-rc.d nginx defaults
update-rc.d mysqld defaults
update-rc.d php-fpm defaults


發佈了12 篇原創文章 · 獲贊 7 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章