日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lnmp环境搭建完全手册(四)——lnmp搭建(源码安装)

發(fā)布時間:2025/3/15 编程问答 19 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lnmp环境搭建完全手册(四)——lnmp搭建(源码安装) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

首先來介紹一下Nginx.Nginx是一個高性能的 HTTP 和 反向代理 服務(wù)器,也是一個 IMAP/POP3/SMTP 代理服務(wù)器。Nginx不僅可以作為web服務(wù)器,也可以作為負(fù)載均衡器,之前也有文章介紹,大家可以看一下.

MySQL是一款開源免費(fèi)的數(shù)據(jù)軟件,MySQL是一個小型關(guān)系型數(shù)據(jù)庫管理系統(tǒng),其體積小、速度快、總體擁有成本低,尤其是開放源碼這一特點(diǎn),許多中小型網(wǎng)站為了降低網(wǎng)站總體擁有成本而選擇了MySQL作為網(wǎng)站數(shù)據(jù)庫.

PHP,是英文超級文本預(yù)處理語言Hypertext Preprocessor的縮寫。PHP 是一種 HTML 內(nèi)嵌式的語言,是一種在服務(wù)器端執(zhí)行的嵌入HTML文檔的腳本語言,語言的風(fēng)格有類似于C語言,被廣泛的運(yùn)用。


nginx當(dāng)前最新穩(wěn)定版是nginx-1.0.13
首先我們下載nginx,在Linux下執(zhí)行下面命令:

cd /usr/src # 一般軟件源碼放在這個目錄下 wget http://nginx.org/download/nginx-1.0.13.tar.gz # 下載

nginx會有幾個依賴包,我們首先安裝依賴,不要安裝過程中會報錯:

yum -y install zlib-devel pcre-devel openssl-devel

一般源代碼安裝分4個步驟(有人也會省去第一個步驟),解壓(tar命令)預(yù)編譯(執(zhí)行源碼包下的configure),編譯(make),編譯安裝(make install)
首先我們解壓源碼包:

tar -zxvf nginx-1.0.13.tar.gz

這里解釋下加壓參數(shù),z代表gzip(也就是后面的.gz文件)x代表加壓,v表示顯示詳細(xì)信息,-f使用檔案文件或設(shè)備(必選參數(shù))

然后我們進(jìn)行預(yù)編譯,一般預(yù)編譯會帶上一些參數(shù),已達(dá)到我們想要安裝的效果,比如啟用某個功能,禁用某個功能:
進(jìn)入源碼包目錄進(jìn)行預(yù)編譯:

cd nginx-1.0.13./configure --prefix=/usr/local/nginx\ # 指定安裝目錄為/usr/local/nginx --with-openssl=/usr/include/openssl\ # 啟用ssl --with-pcre\ # 啟用正規(guī)表達(dá)式 --with-http_stub_status_module # 安裝可以查看nginx狀態(tài)的程序

其中./configure指執(zhí)行當(dāng)前目錄下的configure文件

預(yù)編譯完成后我們就可以進(jìn)行編譯和安裝:

make #編譯

執(zhí)行后make后會有大量輸出,等待輸出完成后如果沒有報錯就可以進(jìn)行安裝執(zhí)行:

make install #安裝

安裝完成后我們可以到相應(yīng)的目錄查看安裝的文件:

ls /usr/local/nginx/ conf html logs sbin

好了,下面我們啟動nginx:

/usr/local/nginx/sbin/nginx

通過查看端口看nginx是否啟動成功,nginx占用TCP的80端口,執(zhí)行下面命令:

netstat -antlp | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 5946/nginx

我們查看80端口是開放的

然后打開瀏覽器訪問http://192.168.3.120,我們會看到Welcome to nginx(之前的版本是 It’s Work):


nginx安裝完畢后我們來安裝MySQL ,我們使用MySQl-5.0.95版首先下載:

wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.95.tar.gz <span style="font-family: Arial;">安裝之前我們先做一些準(zhǔn)備工作,</span>

安裝依賴:

yum -y install ncurses-devel

創(chuàng)建MySQL用戶:

useradd -M -s /sbin/nologin mysql # -M不創(chuàng)建home目錄,-s指定shell為不登錄

然后進(jìn)行安裝:

tar -zxvf mysql-5.0.95.tar.gz cd mysql-5.0.95 ./configure --prefix=/usr/local/mysql \ --without-debug \ # 取消調(diào)試模式提高性能 --with-extra-charsets=utf8,gbk \ # 僅僅指定需要的默認(rèn)字符集提高性能 --enable-assembler \ # 使用匯編模式提高性能 --with-mysqld-ldflags=-all-static \ # 以靜態(tài)方式編譯提高性能 --with-client-ldflags=-all-static \ --with-unix-socket-path=/tmp/mysql.sock \ # 使用unix socket提高性能 --with-ssl make make install

安裝完成后復(fù)制配置文件和啟動腳本:

cp support-files/my-medium.cnf /etc/my.cnf # 復(fù)制配置文件 cp support-files/mysql.server /etc/init.d/mysqld # 復(fù)制啟動腳本 chmod +x /etc/init.d/mysqld # 給啟動腳本執(zhí)行權(quán)限

為了以后方便我們?yōu)樗械亩M(jìn)制可執(zhí)行文件和動態(tài)鏈接庫文件做一個軟連接:

ln -s /usr/local/mysql/bin/* /usr/local/bin/ # 為可執(zhí)行的二進(jìn)制文件做軟連接 ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/ # 為動態(tài)鏈接庫做一個軟連接

然后我們初始化數(shù)據(jù)庫:

mysql_install_db --user=mysql # 用MySQL用戶安裝數(shù)據(jù)庫

為了MySQL能正常使用我們需要更改一下MySQL安裝目錄和MySQL的數(shù)據(jù)庫目錄的屬主和屬組:

chown -R root.mysql /usr/local/mysql/ # 更改安裝目錄屬主為root,屬組為mysql chown -R mysql.mysql /usr/local/mysql/var/ # 更改數(shù)據(jù)庫目錄屬主和屬組都為mysql

這里的-R參數(shù)用來應(yīng)用到所有子目錄和文件

配置完畢后我們啟動mysql:

service mysqld start

現(xiàn)在我們查看MySQL是否啟動成功,MySQL占用TCP的3306端口,我們查看端口是否被占用:

netstat -antlp | grep 3306 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 32143/mysqld

然后我們通過mysql命令來連接mysql:

mysql

會顯示如下內(nèi)容表示已經(jīng)成功啟動MySQL并已經(jīng)連接上

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.0.95-log Source distributionCopyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>

MySQL安裝完畢下面我們就來安裝PHP,安裝PHP前首先要安裝幾個源碼包依賴:
libmcrypt mhash mcrypt
首先來安裝幾個源碼包依賴:

wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.bz2 tar -jxvf libmcrypt-2.5.8.tar.bz2 # 這個包是bz2的 使用-j參數(shù)解壓 cd libmcrypt-2.5.8 ./configure make make install#################################################### wget http://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2 tar -jxvf mhash-0.9.9.9.tar.bz2 cd mhash-0.9.9.9 ./configure make make install # 這兩個包安裝完成后要把動態(tài)鏈接庫做一個軟連接到/usr/lib,以為接下來的mcrypt依賴于這兩個包 ln -s /usr/local/lib/libmcrypt* /usr/lib ln -s /usr/local/lib/libmhash.* /usr/lib/ ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config ########################################################### wget http://sourceforge.net/projects/mcrypt/files/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz tar -zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8 ./configure make make install 然后下載php:?wget http://am1.php.net/distributions/php-5.5.38.tar.bz2

安裝依賴:

yum install <span style="font-family: Arial, Helvetica, sans-serif;">–y</span> libxml2-devel curl-devel libpng-devel openldap-devel libxslt-devel freetype-devel </pre><pre code_snippet_id="1910093" snippet_file_name="blog_20161001_24_4125831" class="other" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);">wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz tar -zxvf libconv-1.1.14.tar.gz .configure --prefix=/usr/local/libiconv 安裝libmcrypt庫 </pre><pre> wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo yum install libmcrypt-devel -y yum install mhash -y

我們使用nginx調(diào)用php的時候使用fpm的方式,在php 5.4中加入了對php-fpm的支持,所以就不需要打補(bǔ)丁了.安裝PHP:

tar -jxvf php-5.3.28.tar.bz2 cd php-5.3.28 ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --enable-short-tags --enable-zend-multibyte --enable-static --with-xsl --with-fpm-user=nginx --with-fpm-group=nginx --enable-ftp --enable-opcache=no make make install </pre><pre code_snippet_id="1910093" snippet_file_name="blog_20161001_25_3427720" class="other" name="code" style="white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 26px; background-color: rgb(255, 255, 255);">注意加上--enable-fastcgi參數(shù)和--enable-force-cgi-redirect參數(shù)

不加上的話配置完之后解析不了php

到這里整個LNMP已經(jīng)安裝完成.下面我們就配置php和nginx能運(yùn)行php網(wǎng)站:
首先為php創(chuàng)建配置文件:

cp php.ini-production /usr/local/php/php.ini # 如果是開發(fā)就復(fù)制php.ini-development cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf ln -s /usr/local/php/bin/php /usr/bin/

配置php-fpm,編輯php-fpm.conf

vi /usr/local/php/etc/php-fpm.conf

找到listen那一行,修改成如下內(nèi)容:

listen = /var/run/php-fpm/php-fpm.sock # 使用unix socket

啟動php-fpm

mkdir /var/run/php-fpm /usr/local/php/sbin/php-fpm

然后配置nginx,編輯nginx配置文件

vi /usr/local/nginx/conf/nginx.conf

修改nginx配置文件支持php:

server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root html;index index.php index.html index.htm; # 添加index.php的首頁文件}# 添加下面內(nèi)容location ~ \.php$ {fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;include fastcgi_params;include fastcgi.conf;}

修改完畢后保存退出重啟nginx:

pkill -9 nignx /usr/local/nginx/sbin/nginx

然后在/usr/local/nginx/html下創(chuàng)建index.php,

vi /usr/local/nginx/html/index.php

添加下面內(nèi)容:

[php]?view plaincopy
  • <?php??
  • phpinfo();??
  • ?>??
  • 保存退出后訪問http://192.168.3.120/index.php,看到下面頁面表示已經(jīng)安裝配置成功:

    總結(jié)

    以上是生活随笔為你收集整理的lnmp环境搭建完全手册(四)——lnmp搭建(源码安装)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。