2)安裝nginx1.4

3)安裝php7.2

4)安裝mariadb10.2

5)總結(jié)

一、LNMP簡(jiǎn)介L(zhǎng):linux,是目前最流行的免費(fèi)操作系統(tǒng),版本有很多,rehat,debian,ubuntu,centos等等,我用" />

国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

15158846557 在線咨詢 在線咨詢
15158846557 在線咨詢
所在位置: 首頁(yè) > 營(yíng)銷資訊 > 網(wǎng)站運(yùn)營(yíng) > 網(wǎng)站服務(wù)器怎么搭建?centos7.5搭建LNMP (詳細(xì)+實(shí)戰(zhàn))

網(wǎng)站服務(wù)器怎么搭建?centos7.5搭建LNMP (詳細(xì)+實(shí)戰(zhàn))

時(shí)間:2023-07-11 11:42:01 | 來(lái)源:網(wǎng)站運(yùn)營(yíng)

時(shí)間:2023-07-11 11:42:01 來(lái)源:網(wǎng)站運(yùn)營(yíng)

網(wǎng)站服務(wù)器怎么搭建?centos7.5搭建LNMP (詳細(xì)+實(shí)戰(zhàn)):

目錄:

1)LNMP簡(jiǎn)介

2)安裝nginx1.4

3)安裝php7.2

4)安裝mariadb10.2

5)總結(jié)

一、LNMP簡(jiǎn)介

L:linux,是目前最流行的免費(fèi)操作系統(tǒng),版本有很多,rehat,debian,ubuntu,centos等等,我用的是centos7.5。

N:nginx,是一個(gè)高性能的HTTP和反向代理服務(wù)器,也是一個(gè)IMAP/POP3/SMTP代理服務(wù)器。nginx市場(chǎng)份額越來(lái)越大,這里也可以選擇Apache,老大哥,寶刀未老。

M:Mysql是一個(gè)小型關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),我覺得已經(jīng)不小了,對(duì)于絕大多數(shù)的情況,夠用了,這里我用的mariadb10.2,mariadb和mysql都是出自同個(gè)作者,這里不講它們的故事。

P:世界上最好的編程語(yǔ)言,一種在服務(wù)器端執(zhí)行的嵌入HTML文檔的腳本語(yǔ)言。

linux+nginx+mysql/mariadb+php,這四個(gè)開源項(xiàng)目組在一起,成為一個(gè)免費(fèi)、高效、擴(kuò)展性強(qiáng)的網(wǎng)站服務(wù)系統(tǒng),這是一個(gè)網(wǎng)站服務(wù)器架構(gòu),學(xué)會(huì)它就能打通任督二脈,無(wú)忌,跟著為師走。

二、安裝nginx

1. 防火墻設(shè)置,允許http,https通信。

firewall-cmd --zone=public --add-service=http --permanent //允許http通信

firewall-cmd --zone=public --add-service=https --permanent  //允許https通信

firewall-cmd --zone=public --add-port=80/tcp --permanent //打開80端口

firewall-cmd --zone=public --add-port=443/tcp --permanent //打開443端口

firewall-cmd --zone=public --add-port=8080/tcp --permanent //打開8080端口

firewall-cmd --reload //重新加載配置

2. 下載基本的庫(kù)文件

yum intall pcre pcre-devel yum install zlib zlib-devel yum install openssl; openssl-devel

3. 配置nginx官方源,下載和安裝

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

yum install nginx //安裝nginx

4. 了解基本配置文件

主配置文件:/etc/nginx/nginx.conf

默認(rèn)配置文件:/etc/nginx/conf.d/default.conf

我們編輯一下default.conf這個(gè)文件。

注意,這里server_name 我寫的是我這臺(tái)電腦的局域網(wǎng)地址及訪問端口,你可以設(shè)置其它或者默認(rèn)不變,如果是默認(rèn)的話瀏覽器那里不需要輸入端口號(hào)。

nginx
5. 局域網(wǎng)訪問測(cè)試一下。

nginx運(yùn)行成功
到這里nginx安裝使用成功,如果你這里無(wú)法訪問,絕大多數(shù)情況下是SELINUX和防火墻的問題。注意,如果你是云服務(wù)器的話是需要在服務(wù)商后臺(tái)那里添加安全組策略的。

三、安裝php7.2

1. 配置php7.2yum源

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2. 安裝php7.2及一些擴(kuò)展工具

yum install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml

3. 啟動(dòng)php-fpm

systemctl php-fpm //啟動(dòng)

systemctl enable php-fpm //設(shè)置開機(jī)啟動(dòng)

注意,nginx是通過php-fpm處理php文件的。

4. 讓nginx支持php,紅色方框就是改的地方。

vim /etc/nginx/conf.d/default.conf

nginx支持php
運(yùn)行一個(gè)php文件

vim /usr/share/nginx/html/index.php //編輯文件

<?php phpinfo();?>

保存,在瀏覽器訪問試一下。

phpinfo()

四、安裝數(shù)據(jù)庫(kù)mariadb10.2

1. 卸載系統(tǒng)自帶的數(shù)據(jù)庫(kù)

首先,centos7.5里面自帶的mariadb5.5版本的,所以第一步,我先卸載掉很老老老老老老的版本。

rpm -qa|grep mariadb

yum remove mariadb-*文件

它會(huì)刪除一些依賴文件,不用擔(dān)心。

2. 配置mariadb10.2yum源

vim /etc/yum.d.repos.d/MariaDB.repo

# MariaDB 10.2 CentOS repository list - created 2019-01-08 08:30 UTC

# http://downloads.mariadb.org/mariadb/repositories/

[mariadb] name = MariaDB

baseurl = http://yum.mariadb.org/10.2/centos7-amd64

gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

gpgcheck=1

以上配置的源是mariadb官方源,下載速度,一個(gè)星期的時(shí)間是完全可以下載下來(lái)的。

如果你想一根煙的時(shí)間就能完成下載,替換為國(guó)內(nèi)源:

[mariadb] name = MariaDB

baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.2/centos7-amd64

gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB

gpgcheck=1

保存退出。

yum clean&&yum update //更新一下yum源

yum install MariaDB-client MariaDB-server //安裝

systemctl start mariadb

systemctl enable mariadb //設(shè)置開機(jī)啟動(dòng)

OK,mariadb安裝完成。

3. 初始化mariadb

首先使用mysql_secure_installation命令進(jìn)行配置。

根據(jù)自己的要求配置,可以按照我的圖片走。

Set root password? [Y/n]

New password:

Re-enter new password:

其他配置

Remove anonymous users? [Y/n]

Disallow root login remotely? [Y/n]

Remove test database and access to it? [Y/n]

Reload privilege tables now? [Y/n]

mariadb初始化
登錄

mysql -uroot -p //本地登錄

mariadb登錄成功
登錄成功

4. 簡(jiǎn)單配置mariadb

先配置服務(wù)端,配置文件:/etc/my.cnf.d/server.cnf

vim /etc/my.cnf.d/server.cnf

在[mysqld]標(biāo)簽下添加以下內(nèi)容

init_connect='SET collation_connection = utf8_unicode_ci'

init_connect='SET NAMES utf8'

character-set-server=utf8

collation-server=utf8_unicode_ci

skip-character-set-client-handshake

保存退出

再配置客戶端,配置文件:/etc/my.cnf.d/mysql-clients.cnf

vim /etc/my.cnf.d/mysql-clients.cnf

在[mysql]中添加

default-character-set=utf8 保存退出

重啟mariadb服務(wù)

systemctl restart mariadb

之后登錄mariadb,輸入下面代碼,查看一下我們的設(shè)置有沒有成功。

show variables like "%character%";show variables like "%collation%";

mariadb字符配置
5. 測(cè)試mariadb

現(xiàn)在nginx,php,mariadb都有了,我們來(lái)做個(gè)簡(jiǎn)單的測(cè)試,寫個(gè)簡(jiǎn)單的代碼,訪問數(shù)據(jù)庫(kù)。

vim /usr/share/nginx/html/index.php

代碼:

if(!$link){ e

cho "Game Over." .PHP_EOL;

echo "Debugging errno:" .mysqli_connect_errno() .PHP_EOL;

echo "Debugging error:" .mysqli_connect_error() .PHP_EOL;

exit;

}

else{

echo "Very Good" .PHP_EOL;

echo "Host information:" .mysqli_get_host_info($link) .PHP_EOL;

}

mysqli_close($link);

我們?cè)跒g覽器訪問看看。

php connect mariadb
有些朋友寫的不是localhost,而是127.0.0.1,可能會(huì)出現(xiàn)Permission denied權(quán)限問題,如下圖。

permission denied
這是因?yàn)閟elinux攔截了,我們?cè)O(shè)置以下就可以。

setsebool httpd_can_network_connect_db = on

用localhost比127.0.0.1在安全及性能上都要好,感興趣的朋友可以閱讀相關(guān)文檔。

五、總結(jié)

到這里,LNMP就搭建成功了,我第一次配置的時(shí)候遇到很多權(quán)限問題,其實(shí)也是好事。從問題出現(xiàn),到分析問題,再到解決問題,你會(huì)收獲很多知識(shí),那些問題讓你的腦袋不斷的思考,最后,任督二脈打通了。

喜歡的話就關(guān)注我吧。

關(guān)鍵詞:詳細(xì),實(shí)戰(zhàn),服務(wù)

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點(diǎn)擊下載Chrome瀏覽器
關(guān)閉