LAMP架構部署和動態網站環境的配置

PHP Apache MySQL 數據庫 ASP HTML Linux 技術 微軟 ?? 事事事難料 2019-05-03

實驗環境:

操作系統:centos 7.5

服務器IP:192.168.10.5

運行用戶:root

連接工具:xshell工具

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

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

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

單節點web服務器

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

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

1、install apache

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

LAMP架構部署和動態網站環境的配置

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

LAMP架構部署和動態網站環境的配置

# 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服務狀態

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

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

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

LAMP架構部署和動態網站環境的配置

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

LAMP架構部署和動態網站環境的配置

PHP 是一種創建動態交互性站點的強有力的服務器端腳本語言;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

LAMP架構部署和動態網站環境的配置

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

LAMP架構部署和動態網站環境的配置

# php -v //查看php版本

LAMP架構部署和動態網站環境的配置

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

LAMP架構部署和動態網站環境的配置

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

3、install mariadb

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

LAMP架構部署和動態網站環境的配置

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

LAMP架構部署和動態網站環境的配置

# systemctl start mariadb.service //啟動數據庫服務

# systemctl stop mariadb.service //停止數據庫服務

# systemctl status mariadb.service //查看數據庫服務狀態

# systemctl enable mariadb.service //設置開機自動啟動數據庫服務

mariadb安裝後啟動服務,數據庫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數據庫,根據自己需求定。

... skipping.

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

will take effect immediately.

Reload privilege tables now? [Y/n] y //刷新數據表

... 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 //連接數據庫

LAMP架構部署和動態網站環境的配置

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

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

http://192.168.10.5

LAMP架構部署和動態網站環境的配置

4.2、測試apache+php

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

<?php

phpinfo();

?>

http://192.168.10.5/index.php

LAMP架構部署和動態網站環境的配置

4.3、測試apache+php+mariadb

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

<?php

$servername = "localhost";

$username = "root";

$password = "password";

// 創建連接

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

// 檢測連接

if ($conn->connect_error) {

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

}

echo "連接成功";

?>

http://192.168.10.5/mysqld.php

LAMP架構部署和動態網站環境的配置

相關推薦

推薦中...