溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

LAMP架構部署以及動態(tài)網站環(huán)境的配置

發(fā)布時間:2021-09-01 17:51:42 來源:億速云 閱讀:114 作者:chen 欄目:數(shù)據(jù)庫

這篇文章主要介紹“LAMP架構部署以及動態(tài)網站環(huán)境的配置”,在日常操作中,相信很多人在LAMP架構部署以及動態(tài)網站環(huán)境的配置問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”LAMP架構部署以及動態(tài)網站環(huán)境的配置”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

實驗環(huán)境:

操作系統(tǒng):centos 7.5

服務器IP:192.168.10.5

運行用戶:root

連接工具:xshell工具

web環(huán)境:Linux+apache+php+mariadb(LAMP架構)

大型動態(tài)應用系統(tǒng)平臺主要是針對于大流量、高并發(fā)網站建立的底層系統(tǒng)架構。大型網站的運行需要一個可靠、安全、可擴展、易維護的應用系統(tǒng)平臺做為支撐,以保證網站應用的平穩(wěn)運行。這些東西都需要依靠web服務器來支撐,里面應用到的技術有單節(jié)點web服務器系統(tǒng)、負載均衡系統(tǒng)、數(shù)據(jù)集群系統(tǒng)、緩存系統(tǒng)、分布式存儲系統(tǒng)、分布式服務器管理系統(tǒng)、代碼發(fā)布系統(tǒng)等,現(xiàn)在企業(yè)一般都流行使用自動化系統(tǒng)部署,可以把web業(yè)務全部跑在docker容器中,簡化了運維配置流程,下面我們簡單的介紹下web服務器單節(jié)點的部署及使用。

本文屬于原創(chuàng),比較適合企業(yè)應用,具體詳細的介紹可以參考 《Linux就該這么學》 里邊教程的第20章,里面詳細的介紹了LNMP架構,而我這里是介紹LAMP架構,LAMP、LNMP在企業(yè)都應用比較廣泛,一般大型企業(yè)網站都會在Linux服務器上面跑,節(jié)約資源、提高web服務器性能及安全性。

單節(jié)點web服務器

通過系統(tǒng)自帶的yum源安裝,也可以通過本地鏡像配置本地yum源,還可以通過rpm包或者tar.gz源碼包編譯后再安裝;通過yum安裝是比較方便的,安裝過程會自動把依賴包自動安裝上去;通過rpm包安裝過程中需要根據(jù)提示尋找依賴包,這種安裝方式比較麻煩;下面我們來通過yum源安裝方式來演示給大家看。

apache是一款開源的web服務器,它可以運行在幾乎所有廣泛使用的計算機平臺上,由于其跨平臺和安全性被廣泛使用,是最流行的Web服務器端軟件之最,apache在企業(yè)應用也是比較廣泛的。特別是結合Linux操作系統(tǒng)發(fā)揮最優(yōu)的性能。

1、install apache

# yum install httpd.x86_64 httpd-devel.x86_64 -y  //安裝apache

# rpm -qa httpd   //查看apache是否安裝成功

# httpd -v    //查看apache版本

Server version: Apache/2.4.6 (CentOS)

Server built:   Jun 27 2018 13:48:59

# systemctl start httpd.service    //啟動apache服務

# systemctl status httpd.service   //查看apache服務狀態(tài)

# systemctl stop httpd.service    //停止apache服務

# systemctl enable httpd.service   //設置開機自動啟動apache服務

apache默認配置文件路徑:/etc/httpd/

apache默認web路徑:/var/www/html ,默認里面是空目錄

PHP 是一種創(chuàng)建動態(tài)交互性站點的強有力的服務器端腳本語言;PHP 是開源的,并且使用非常廣泛;同時,對于像微軟 asp、asp.net服務器腳本語言競爭者來說,PHP 無疑是另一種高效率的選項,PHP有點:開源性、處理快、易上手、跨平臺,效率高、適用于大型網站架構,一般PHP都是結合 Linux apache nginx mysql;iis+php極少,配置復雜、性能差。下面就簡單介紹下php的安裝及配置。

2、install php

# yum install php php-common php-fpm php-gd php-soap php-json php-ldap php-mbstring php-mysqlnd php-mysqld php-xml php-xmlrpc php-opcache php-simplexml php-bcmath -y

# rpm -qa php*  //查看安裝的PHP模塊

# php -v   //查看php版本

# ll /etc/php.ini    //php默認配置文件,配置文件里面詳細參數(shù)這里就不一一介紹了。

MySQL最初也是開源的,后來被Oracle公司收購后5.5后的版本開始收費了,后來又有了MariaDB數(shù)據(jù)庫,MariaDB數(shù)據(jù)庫管理系統(tǒng)是MySQL的一個分支,主要由開源社區(qū)在維護,采用GPL授權許可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕松成為MySQL的代替品,MariaDB開源、跨平臺、性能強、易擴展、應用廣。

3、install mariadb

# yum install mariadb.x86_64 mariadb-server.x86_64 mariadb-devel.x86_64 -y

# rpm -qa mariadb  //查看mariadb是否安裝成功

# systemctl start mariadb.service   //啟動數(shù)據(jù)庫服務

# systemctl stop mariadb.service   //停止數(shù)據(jù)庫服務

# systemctl status mariadb.service   //查看數(shù)據(jù)庫服務狀態(tài)

# systemctl enable mariadb.service  //設置開機自動啟動數(shù)據(jù)庫服務

mariadb安裝后啟動服務,數(shù)據(jù)庫root用戶是沒有密碼的,需要進行初始化并設置密碼,配置如下:

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none):   //直接回車

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

Set root password? [Y/n] y   //y設置root用戶密碼

New password:      //輸入密碼

Re-enter new password:    //確定密碼

Password updated successfully!

Reloading privilege tables..

 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] y    //y刪除匿名用戶

 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y   //y禁止root遠程登錄

 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] n  //n不刪除test數(shù)據(jù)庫,根據(jù)自己需求定。

 ... skipping.

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] y   //刷新數(shù)據(jù)表

 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

Thanks for using MariaDB!

# mysql -h 127.0.0.1 -u root -p   //連接數(shù)據(jù)庫

4、test web service,apache + php +mariadb安裝啟動服務后就開始測試。

4.1、通過瀏覽器訪問web服務器出現(xiàn)如下解密說明apache安裝成功。

http://192.168.10.5

4.2、測試apache+php

# vim /var/www/html/index.php

<?php

        phpinfo();

?>

http://192.168.10.5/index.php

4.3、測試apache+php+mariadb

# vim /var/www/html/mysqld.php

<?php

$servername = "localhost";

$username = "root";

$password = "password";

// 創(chuàng)建連接

$conn = new mysqli($servername, $username, $password);

// 檢測連接

if ($conn->connect_error) {

die("連接失敗: " . $conn->connect_error);

}

echo "連接成功";

?>

http://192.168.10.5/mysqld.php

到此,關于“LAMP架構部署以及動態(tài)網站環(huán)境的配置”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關知識,請繼續(xù)關注億速云網站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經查實,將立刻刪除涉嫌侵權內容。

AI