LNMP環境搭建

2021-09-08 12:02:17 字數 4111 閱讀 8119

1、安裝nginx並測試正常訪問**

2、安裝mysql

1

)確認rpm mysql刪除

# rpm -qa |grep mysql

2)解壓縮mysql並配置安裝引數

# ./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312

3)編譯並安裝

# make &&make install

4)生成mysql配置檔案及啟動服務

# cp support-files/my-medium.cnf /etc/my.cnf

# cp support-files/mysql.server /etc/init.d/mysqld

# chmod a+x /etc/init.d/mysqld

# chkconfig --add mysqld

# chkconfig --list mysqld

5)初始化mysql資料庫

# useradd -m -s /sbin/nologin mysql

# /usr/local/mysql/bin/mysql_install_db --user=mysql

# chown -r root:mysql /usr/local/mysql/# chown -r mysql /usr/local/mysql/var/

6)建立mysql相應軟鏈結

# ln -s /usr/local/mysql/bin/*

/usr/local/bin/

# ln -s /usr/local/mysql/lib/mysql/* /usr/lib

# ln -s /usr/local/mysql/include/mysql/* /usr/include/

7)啟動mysqld服務,並驗證

# /etc/init.d/mysqld start

starting mysql. [確定]

# netstat -antp | grep mysqld

tcp 0 0 0.0.0.0:3306 0.0.0.0:* listen 21727/mysqld

8)為mysql使用者新增密碼

# mysqladmin -u root -p password "www.1.com"

view code

3、安裝php

1

)確認rpm php軟體解除安裝

# rpm -qa |grep php

2)解壓縮並配置安裝引數

# ./configure --prefix=/usr/local/php --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php --enable-mbstring --enable-fpm

錯誤1:

configure: error: xml2-config not found. please check your libxml2 installation.

解決辦法:

yum install libxlm2-devel

錯誤2:

configure: error: libpng.(a|so) not found.

解決辦法:

yum install -y libpng-devel

3)編譯並安裝

#make &&make install

4)生成php.ini配置檔案並建立相應的軟鏈結

# cp php.ini-development /usr/local/php/php.ini

# ln -s /usr/local/php/bin/*

/usr/local/bin/

# ln -s /usr/local/php/sbin/* /usr/local/sbin/

5)配置php使其支援zendguardloader

# cp zendguardloader.so /usr/local/php/lib/php/

# vim /usr/local/php/php.ini

zend_extension=/usr/local/php/lib/php/zendguardloader.so

zend_loader.enable=1

view code

nginx支援php有兩種方式:其一,充當中介,將訪問php頁面的請求轉交到其他的lamp伺服器進行解析;其二,通過使用php的fpm模組呼叫本機的php環境

這裡採用第二種方式

1)生成php-fpm.conf配置檔案,並啟用php-fpm程序

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

# vim /usr/local/php/etc/php-fpm.conf

pid = run/php-fpm.pid //

確認pid檔案位置

user =nginx

group =nginx

pm.start_servers = 20

//啟動時開啟的程序數

pm.min_spare_servers = 5

//最少空閒程序數

pm.max_spare_servers = 35

//最多空閒程序數

# /usr/local/sbin/php-fpm

# netstat -antp | grep php-fpm

tcp 00

127.0.0.1:9000

0.0.0.0:* listen 25063/php-fpm

2)修改nginx服務啟動指令碼,使php-fpm隨nginx自動啟動關閉;在原有指令碼基礎上新增藍色字型內容

# vim /etc/init.d/nginx

prog_fpm="

/usr/local/sbin/php-fpm

"pidf_fpm="

/usr/local/php/var/run/php-fpm.pid

"start)

$prog

$prog_fpm

;;stop)

kill -s quit $(cat $pidf)

kill -s quit $(cat $pidf_fpm)

;;

3)驗證nginx和php-fpm共同啟動

# /etc/init.d/nginx start

# netstat -atnp | grep :9000

tcp 00

127.0.0.1:9000

0.0.0.0:* listen 25152/php-fpm

# netstat -atnp | grep :80

tcp 00

0.0.0.0:80

0.0.0.0:* listen 25149/nginx

4)修改nginx配置檔案,使其支援php

# vim /usr/local/nginx/conf/nginx.conf

location ~\.php$

5)在/usr/local/nginx/html下建立test.php檔案測試lnmp是否正常工作

# vim /usr/local/nginx/html/test.php

<?php

$link=mysql_connect('

localhost

','root

','www.1.com');

if($link) echo "

連線成功";

mysql_close();

?>

6)重啟nginx服務,並測試

搭建LNMP環境

yum install nginx yserver error page 404 404.html location 40x.html error page 500 502 503 504 50x.html location 50x.html 修改完成後,啟動 nginx nginx此時,可訪問來確...

lnmp環境搭建

lnmp版本 nginx1.12.1 php7.1.8 mysql5.6.37 php和nginx包 提取碼 ggmf 安裝前先安裝依賴 已經安裝了可能會進行公升級,版本完全一致則不會進行任何操作。yum y install bzip2 devel curl devel freetype devel...

LNMP環境搭建

lnmp linux nginx mysql php 是常用的 架構組合,對於 開發以及運維人員來說,這一套環境的配置都必須要掌握,本文是站在乙個運維人員的角度通過原始碼編譯的方式來搭建這樣一套環境,所針對平台為rhel6.5,軟體版本分別為mysql boost 5.7.11 php 5.6.31...