LNMP編譯安裝(stablerelease)-創(chuàng)新互聯(lián)

LNMP代表的就是:Linux系統(tǒng)下Nginx+MySQL+PHP這種網(wǎng)站服務(wù)器架構(gòu)。

創(chuàng)新互聯(lián)-專(zhuān)業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性?xún)r(jià)比潮南網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式潮南網(wǎng)站制作公司更省心,省錢(qián),快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋潮南地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴(lài)。

Linux是一類(lèi)Unix計(jì)算機(jī)操作系統(tǒng)的統(tǒng)稱(chēng),是目前最流行的免費(fèi)操作系統(tǒng)。代表版本有:debian、centos、ubuntu、fedora、gentoo等。

Nginx是一個(gè)高性能的HTTP和反向代理服務(wù)器,也是一個(gè)IMAP/POP3/SMTP代理服務(wù)器。

Mysql是一個(gè)小型關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng)。

PHP是一種在服務(wù)器端執(zhí)行的嵌入HTML文檔的腳本語(yǔ)言。

這四種軟件均為免費(fèi)開(kāi)源軟件,組合到一起,成為一個(gè)免費(fèi)、高效、擴(kuò)展性強(qiáng)的網(wǎng)站服務(wù)系統(tǒng)。[1]

系統(tǒng)環(huán)境:

    適合centos6.x x86_64位操作系統(tǒng)

源碼編譯安裝方式優(yōu)勢(shì):
1、自定義軟件功能
2、優(yōu)化編譯參數(shù),提高性能
3、解決不必要的軟件間依賴(lài)

一、下載解壓源碼包

     1.mysql免編譯二進(jìn)制包下載并解壓 (5.1.72)

     2.php源碼包下載并解壓 (5.3.27)

    3.nginx 源碼包下載并解壓(1.4.4)

[root@coderblog ~]#  wget -cP /usr/local/src   http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.72-linux-x86_64-glibc23.tar.gz [root@coderblog ~]#  cd /usr/local/src/ && tar -xzvf mysql-5.1.72-linux-x86_64-glibc23.tar.gz  #下載并解壓mysql免編譯二進(jìn)制包[root@coderblog src]# wget -c http://mirrors.sohu.com/php/php-5.3.27.tar.gz  [root@coderblog src]# tar -xzvf php-5.3.27.tar.gz  #下載并解壓php源碼包[root@coderblog src]# wget -c [root@coderblog src]# tar -xzvf nginx-1.4.4.tar.gz #下載并解壓nginx源碼包

二、安裝

安裝順序mysql > php > nginx

1) mysql安裝

[root@coderblog src]# mv mysql-5.1.72-linux-x86_64-glibc23 /usr/local/mysql
#移動(dòng)并重命名至/usr/local/mysql
[root@coderblog src]# useradd -s /sbin/nologin mysql
#建立mysql賬戶(hù)
[root@coderblog src]# cd /usr/local/mysql
[root@coderblog mysql]# mkdir -p /data/mysql ; chown -R mysql:mysql /data/mysql
[root@coderblog mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
#初始化數(shù)據(jù)庫(kù)

--user 定義數(shù)據(jù)庫(kù)的所屬主, --datadir 定義數(shù)據(jù)庫(kù)安裝到哪里,建議放到大空間的分區(qū)上,這個(gè)目錄需要自行創(chuàng)建。這一步驟很關(guān)鍵,如果你看到兩個(gè) “OK” 說(shuō)明執(zhí)行正確

[root@coderblog mysql]# cp support-files/my-large.cnf /etc/my.cnf
#拷貝配置文件

[root@coderblog mysql]# cp support-files/mysql.server  /etc/init.d/mysqld
[root@coderblog mysql]# chmod 755 /etc/init.d/mysqld
#拷貝啟動(dòng)文件并賦予權(quán)限
[root@coderblog mysql]# vim /etc/init.d/mysqld
#修改啟動(dòng)配置文件
需要修改的地方有 “datadir=/data/mysql” (前面初始化數(shù)據(jù)庫(kù)時(shí)定義的目錄)
               basedir=/usr/local/mysql
[root@coderblog mysql]# chkconfig --add mysqld #把啟動(dòng)腳本加入系統(tǒng)服務(wù)項(xiàng)
[root@coderblog mysql]# chkconfig mysqld on #設(shè)定開(kāi)機(jī)啟動(dòng)
[root@coderblog mysql]# service mysqld start #啟動(dòng)mysql

2)php安裝

[root@coderblog ~]# cd /usr/local/src/php-5.3.27 #切到剛剛解壓php之后的目錄
[root@coderblog php-5.3.27]# useradd -s /sbin/nologin php-fpm #創(chuàng)建相關(guān)用戶(hù)
[root@coderblog php-5.3.27]# yum install -y epel-release #安裝epel擴(kuò)展源
[root@coderblog php-5.3.27]# yum -y install pcre pcre-devel apr apr-devel zlib-devel libxml2-devel  openssl openssl-devel bzip2 bzip2-devel  libpng libpng-devel  freetype freetype-devel  libmcrypt-devel gcc libcurl-devel libtool-ltdl-devel libjpeg libjpeg-devel libpng libpng-devel 
#安裝所需環(huán)境
[root@coderblog php-5.3.27]#./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-mysql=/usr/local/mysql \
--with-mysql-sock=/tmp/mysql.sock \
--with-libxml-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-iconv-dir \
--with-zlib-dir \
--with-mcrypt \
--enable-soap \
--enable-gd-native-ttf \
--enable-ftp \
--enable-mbstring \
--enable-exif \
--disable-ipv6 \
--with-pear \
--with-curl \
--with-openssl \
--enable-sockets
#配置編譯參數(shù)
如有報(bào)錯(cuò)信息可以百度下error信息,一般都會(huì)有答案. 
[root@coderblog php-5.3.27]# echo $?
0
#檢測(cè)是否執(zhí)行成功 非0則不成功
[root@coderblog php-5.3.27]# make && make install
[root@coderblog php-5.3.27]# cp php.ini-production /usr/local/php/etc/php.ini
[root@coderblog php-5.3.27]# vim /usr/local/php/etc/php-fpm.conf
#修改配置文件
#把如下內(nèi)容寫(xiě)入php-fpm.conf
[global]
pid = /usr/local/php/var/run/php-fpm.pid
error_log = /usr/local/php/var/log/php-fpm.log
[www]
listen.user=php-fpm 
listen.group=php-fpm
listen.mode=0666
listen = /tmp/php-fcgi.sock
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024

保存配置文件后,檢驗(yàn)配置是否正確的方法為:

[root@coderblog php-5.3.27]# /usr/local/php/sbin/php-fpm -t

啟動(dòng)php-fpm

[root@coderblog php-5.3.27]# cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm #拷貝啟動(dòng)文件
[root@coderblog php-5.3.27]# chmod 755 /etc/init.d/php-fpm #賦予權(quán)限
[root@coderblog php-5.3.27]# service php-fpm start #啟動(dòng)php服務(wù)

如果想讓它開(kāi)機(jī)啟動(dòng),執(zhí)行:

[root@coderblog php-5.3.27]# chkconfig php-fpm on

3)nginx安裝

[root@coderblog ~]# cd /usr/local/src/nginx-1.4.4/ #切到剛剛解壓nginx之后的目錄
[root@coderblog nginx-1.4.4]# useradd -s /sbin/nologin www #創(chuàng)建相關(guān)用戶(hù)

[root@coderblog nginx-1.4.4]# ./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module  \
--with-pcre
#配置編譯參數(shù)
[root@coderblog nginx-1.4.4]# make && make install #安裝
[root@coderblog nginx-1.4.4]# vim /etc/init.d/nginx
 #自定義nginx啟動(dòng)腳本將以下內(nèi)容拷貝到文件并保存
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings

NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"

start() {
        echo -n $"Starting $prog: "
        mkdir -p /dev/shm/nginx_temp
        daemon $NGINX_SBIN -c $NGINX_CONF
        RETVAL=$?
        echo
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -TERM
        rm -rf /dev/shm/nginx_temp
        RETVAL=$?
        echo
        return $RETVAL
}

reload(){
        echo -n $"Reloading $prog: "
        killproc -p $NGINX_PID $NGINX_SBIN -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

restart(){
        stop
        start
}

configtest(){
    $NGINX_SBIN -c $NGINX_CONF -t
    return 0
}

case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  reload)
        reload
        ;;
  restart)
        restart
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $0 {start|stop|reload|restart|configtest}"
        RETVAL=1
esac

exit $RETVAL
[root@coderblog nginx-1.4.4]# chmod 755 /etc/init.d/nginx #賦予啟動(dòng)文件權(quán)限
[root@coderblog nginx-1.4.4]# chkconfig --add nginx #加入開(kāi)機(jī)啟動(dòng)項(xiàng)
[root@coderblog nginx-1.4.4]# chkconfig nginx on #設(shè)置開(kāi)機(jī)自動(dòng)啟動(dòng)
[root@coderblog nginx-1.4.4]# > /usr/local/nginx/conf/nginx.conf #清空配置文件
[root@coderblog nginx-1.4.4]# vim /usr/local/nginx/conf/nginx.conf
#編輯nginx配置文件 并把以下內(nèi)容拷貝到文件中
user www www;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
{
    use epoll;
    worker_connections 6000;
}

http
{
    include mime.types;
    default_type application/octet-stream;
    server_names_hash_bucket_size 3526;
    server_names_hash_max_size 4096;
    log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
    '$host "$request_uri" $status'
    '"$http_referer" "$http_user_agent"';
    sendfile on;
    tcp_nopush on;
    keepalive_timeout 30;
    client_header_timeout 3m;
    client_body_timeout 3m;
    send_timeout 3m;
    connection_pool_size 256;
    client_header_buffer_size 1k;
    large_client_header_buffers 8 4k;
    request_pool_size 4k;
    output_buffers 4 32k;
    postpone_output 1460;
    client_max_body_size 10m;
    client_body_buffer_size 256k;
    client_body_temp_path /usr/local/nginx/client_body_temp;
    proxy_temp_path /usr/local/nginx/proxy_temp;
    fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
    fastcgi_intercept_errors on;
    tcp_nodelay on;
    gzip on;
    gzip_min_length 1k;
    gzip_buffers 4 8k;
    gzip_comp_level 5;
    gzip_http_version 1.1;
    gzip_types text/plain application/x-javascript text/css text/htm application/xml;

server
{
    listen 80;
    server_name localhost;
    index index.html index.htm index.php;
    root /usr/local/nginx/html;

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/php-fcgi.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
    }

}

}
[root@coderblog ~]# /usr/local/nginx/sbin/nginx  -t 
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#如顯示如上,則配置文件無(wú)誤
[root@coderblog ~]# service nginx start #啟動(dòng)nginx

至此LNMP環(huán)境就安裝完成了,nginx虛擬主機(jī)位置在:/usr/local/nginx/html/

可以寫(xiě)個(gè)phpinfo.php 測(cè)試php解析情況

<?php

    phpinfo();

?>

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。

分享名稱(chēng):LNMP編譯安裝(stablerelease)-創(chuàng)新互聯(lián)
網(wǎng)頁(yè)地址:http://muchs.cn/article42/coscec.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、建站公司、網(wǎng)站營(yíng)銷(xiāo)、自適應(yīng)網(wǎng)站、服務(wù)器托管面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

小程序開(kāi)發(fā)