LAMP是一種常用的Web應用程序開發(fā)平臺,它由以下四個組件組成:
Linux:作為操作系統(tǒng)贫橙,提供了穩(wěn)定和安全的基礎强衡。
Apache:作為Web服務器集漾,處理HTTP請求并將網(wǎng)頁發(fā)送給客戶端竖幔。
MySQL:作為關系型數(shù)據(jù)庫管理系統(tǒng)板乙,用于存儲和管理數(shù)據(jù)是偷。
PHP:作為服務器端腳本語言拳氢,用于處理動態(tài)內容和與數(shù)據(jù)庫交互。
這些組件的結合形成了LAMP技術棧蛋铆,你可以利用它開發(fā)很多Web應用程序馋评,比如WordPress。如果你想手工搭建WordPress的話刺啦,那么你就需要先搭建LAMP環(huán)境留特。
搭建LAMP環(huán)境的前期準備
在開始搭建LAMP環(huán)境之前,你需要先做好以下前期工作:
準備好一臺VPS玛瘸,可以參考我的博文《快速搭建VPS教程|Vultr》蜕青。
已通過SSH連接VPS,后續(xù)所有的搭建操作都是在VPS上完成的糊渊。
第一步:安裝Apache
Apache是一款功能強大的開源Web服務器軟件右核,很多網(wǎng)站和Web應用程序都運行在Apache上,因此我們需要先安裝Apache渺绒。
sudo apt update && sudo apt install apache2 --yes && sudo ufw allow in "Apache"
上面的命令完成了三件事情:
更新Linux系統(tǒng)軟件包索引
安裝Apache
設置系統(tǒng)防火墻贺喝,允許進入的流量通過Apache
接下來,你可以在瀏覽器中測試Apache是否正常運行宗兼,輸入以下地址:
http://VPS_IP
需要注意的是這里應使用http協(xié)議躏鱼,而不是https,因為我們在上面的命令中只放行了80端口殷绍。比如我這里訪問的是:
http://20.243.21.117
如果你能打開染苛,表明你已經配置成功了。
第二步:安裝MySQL
MySQL是一種廣受歡迎的關系型數(shù)據(jù)庫主到,我們WordPress網(wǎng)站的各種數(shù)據(jù)都存儲在MySQL中茶行。
sudo apt install mysql-server -y && sudo mysql
執(zhí)行完上面的命令,你就進入MySQL數(shù)據(jù)庫了镰烧。
接下來我們需要設置MySQL數(shù)據(jù)庫的密碼拢军,在MySQL中輸入以下代碼,其中PASSWORD必須替換成你自己的密碼怔鳖。請牢記這個密碼茉唉,后面會用到。
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password by 'PASSWORD';
然后輸入exit退出MySQL數(shù)據(jù)庫。
執(zhí)行成功后度陆,你將返回到原來的VPS終端界面艾凯。
接下來初始化MySQL,輸入以下命令:
sudo mysql_secure_installation
在運行該命令后懂傀,會要求你輸入密碼趾诗,直接輸入上面設置的密碼即可。然后蹬蚁,按照以下提示進行選擇:
是否啟用密碼強度檢查:選擇Y恃泪。
VALIDATE PASSWORD COMPONENT can be used to test passwordsand improve security. It checks the strength of passwordand allows the users to set only those passwords which aresecure enough. Would you like to setup VALIDATE PASSWORD component?Press y|Y for Yes, any other key for No: Y
密碼強度要求:選擇 0(代表最低強度,適合初學者犀斋;如果你有經驗贝乎,可以選擇 1 或 2)。
There are three levels of password validation policy:LOW? ? Length >= 8MEDIUM Length >= 8, numeric, mixed case, and special charactersSTRONG Length >= 8, numeric, mixed case, special characters and dictionary? ? ? ? ? ? ? ? ? filePlease enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
是否要重新設置root用戶密碼:選擇N叽粹。
Estimated strength of the password: 100Change the password for root ? ((Press y|Y for Yes, any other key for No) : N
是否刪除匿名用戶:選擇Y览效。
By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a productionenvironment.Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
是否禁止root用戶遠程登錄:選擇Y。
Normally, root should only be allowed to connect from'localhost'. This ensures that someone cannot guess atthe root password from the network.Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
是否刪除測試數(shù)據(jù)庫:選擇Y虫几。
By default, MySQL comes with a database named 'test' thatanyone can access. This is also intended only for testing,and should be removed before moving into a productionenvironment.Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
是否刷新權限表:選擇Y锤灿。
Reloading the privilege tables will ensure that all changesmade so far will take effect immediately.Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
這些步驟完成后,MySQL就安裝并進行了基本配置辆脸。你將看到屏幕上顯示 “All done” 字樣但校。
第三步:安裝PHP
首先,運行以下命令來安裝PHP及相關模塊:
sudo apt install php libapache2-mod-php php-mysql -y
安裝完成后每强,你可以使用以下命令檢查PHP版本:
php -v
你應該會看到類似于下面的輸出始腾,顯示你的PHP版本(例如8.1.2)。
最后
到這里空执,你已經成功安裝了LAMP環(huán)境浪箭,可以準備運行或安裝其他程序了。你可以繼續(xù)按照我的教程《最新VPS搭建WordPress教程》安裝WordPress辨绊,利用這個搭建出來的WordPress來創(chuàng)造更多的價值奶栖。