在FreeBSD 11上安裝Nginx,MariaDB和PHP(FEMP)1

FreeBSD 11上安裝NginxMariaDBPHPFEMP

在本教程中,我將介紹在FreeBSD 11.x上安裝和配置FEMP的過程。 FEMP軟體棧是縮寫,代表通常安裝在Unix / Linux操作系統中的一組程序,主要用於部署動態Web應用程序。
在這種情況下,FEMP的首字母縮寫是指FreeBSD的類Unix操作系統,在其上面安裝了這些應用程序:

    Nginx Web伺服器是一種快速發展的熱門Web伺服器,主要用於提供HTML內容,但也可以為Web伺服器或其他網路服務提供負載平衡,高可用性或反向代理。

    PHP動態編程語言解釋器,用於後端操作資料庫數據並創建可以包含在純HTML中的動態Web內容。 PHP腳本只在伺服器端執行,從不在客戶端執行(在瀏覽器中)

    Mariadb \ MySQL RDBMS這是數據存儲在支持的地方,而動態處理由PHP處理。
在本教程中,我們將安裝和使用MariaDB關係資料庫管理系統(MySQL的社區分支),以支持由Oracle現在擁有和開發的MySQL資料庫。

要求:

    最簡單的安裝FreeBSD 11.x.

    為網路介面配置的靜態IP地址。

    常規帳戶配置有root許可權或通過root帳戶直接訪問系統。

    最好是使用最小DNS記錄(ACNAME記錄)配置的公共註冊域名。

1安裝MariaDB資料庫

第一步,我們將安裝MariaDB資料庫系統,它是用於存儲和管理網站動態數據的FEMP組件。 MariaDB / MySQL是世界上與NginxApache Web伺服器結合使用的最常用的開源關係資料庫之一。
這兩款伺服器都被高度用於創建和開發複雜的Web應用程序或動態網站。 MariaDB可以直接從PORTS倉庫提供的二進位文件安裝到FreeBSD上。
但是,在FreeBSD Ports資料庫部分使用ls命令進行的簡單搜索會顯示MariaDB的多個版本,如下面的命令輸出所示。
另外,運行Package Manager pkg命令將顯示相同的結果。

ls -al /usr/ports/databases/ | grep mariadb

pkg search mariadb

  

在本指南中,我們將使用pkg命令安裝MariaDB資料庫和客戶端的最新版本,如以下摘錄所示。

pkg install mariadb102-server mariadb102-client

MariaDB在系統中完成安裝之後,請發出以下命令以啟用系統範圍內的MySQL伺服器。
另外,請確保您啟動MariaDB守護進程,如下所示。

sysrc mysql_enable=”YES”

service mysql-server start

接下來,我們需要通過運行mysql_secure_installation腳本來保護MariaDB資料庫。
在運行腳本時,我們會問一系列問題。
這些問題的目的是為MySQL引擎提供一個安全級別,比如為MySQL root用戶設置一個root密碼,刪除匿名用戶,禁止root用戶遠程登錄,刪除測試資料庫。
MySQL根用戶選擇一個強密碼後,在所有問題上回答”  “,如以下腳本示例所示。
不要將MariaDB資料庫root用戶與系統root用戶混淆。
儘管這些帳戶具有相同的名稱(root),但它們並不等同,用於不同的目的,一個用於系統管理,另一個用於資料庫管理。

/usr/local/bin/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

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

 … 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

 … 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] y

 – Dropping test database…

 … Success!

 – Removing privileges on test database…

 … Success!

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!

最後,在完成MariaDB資料庫安全保護之後,運行以下命令測試是否允許從root帳戶執行本地登錄到資料庫。
一旦連接到資料庫提示符,只需鍵入退出退出 ,以離開資料庫控制台,並返回到系統用戶控制台提示符,如下圖所示。

mysql -u root -p

MariaDB> quit

  

FreeBSD上運行sockstat命令很快就揭示了MariaDB對外部網路連接的開放性,可以通過3306 / TCP埠從任何網路遠程訪問。

sockstat -4 -6


以下文章點擊率最高

Loading…

     

如果這文章對你有幫助,請掃左上角微信支付-支付寶,給於打賞,以助博客運營