Ubuntu 18.04上安裝LAMP完整過程圖文詳解

在這篇文章中,我將向您展示如何在Ubuntu 18.04 Server上安裝LAMP。 LAMP代表Linux,Apache Web服務器,MySQL和PHP。

目前部署的大部分Web應用程序都部署在LAMP環境上。

這意味着Linux Web服務器安裝了Apache Web Server,MySQL數據庫服務器和PHP超文本預處理器,以便爲基於Web的應用程序提供服務。

在這篇文章中,我將引導您完成整個過程。

確保安裝並完全更新了Ubuntu Server 18.04的全新副本。

安裝Apache2

首先,我們需要安裝Apache 2 Web服務器。

apt install apache2 -y

默認情況下,您的所有Web內容都位於/var/www/html中。

此外,/var/www/html目錄中的所有內容都需要由www-data用戶和www-data組擁有,以便Apache Web Server能夠讀取文件。

接下來,我們將安裝MySQL數據庫。

安裝MySQL

MySQL是一個非常強大的開源關係數據庫。

運行以下命令安裝MySQL。

apt install mysql-server -y

安裝完成後,我們需要保護它。 運行此命令以保護MySQL。

mysql_secure_installation

這個腳本會問你幾個問題。

第一個問題將要求您安裝驗證密碼插件。

VALIDATE PASSWORD PLUGIN can be used to test passwords 
and improve security. It checks the strength of password 
and allows the users to set only those passwords which are 
secure enough. Would you like to setup VALIDATE PASSWORD plugin? 
 
Press y|Y for Yes, any other key for No: N

我通常會回答“N”這個問題,因爲我知道我的密碼是安全的。 如果您願意,可以回答“Y”。

接下來,該腳本將要求您爲根MySQL用戶設置新密碼。

New password:   
Re-enter new password:

該腳本現在將要求您刪除匿名用戶。 回答“Y.”

By default, a MySQL installation has an anonymous user, 
allowing anyone to log into MySQL 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? (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 at 
the root password from the network. 
 
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y

它會要求您刪除測試數據庫並訪問它。 回答“Y.”

By default, MySQL 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? (Press y|Y for Yes, any other key for No) : Y

接下來,它會要求您重新加載權限表。 回答“Y.”

Reloading the privilege tables will ensure that all changes 
made so far will take effect immediately. 
 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y

最後,腳本完成。

MySQL現已安裝。

安裝PHP

在Ubuntu 18.04上安裝LAMP的最後一步是安裝PHP超文本預處理器。

PHP添加了支持動態網頁的服務器端網頁處理。

運行以下命令以安裝PHP。

apt install php -y

接下來,我們需要告訴Apache首先提供PHP頁面。

打開/etc/apache2/mods-enabled/dir.conf文件並將其更改爲首先列出index.php。

<IfModule mod_dir.c> 
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm 
</IfModule>

最後,我們需要重新啓動Apache Web服務器。

systemctl restart apache2

測試PHP

我們應該確保PHP工作正常。

在/var/www/html中創建一個名爲info.php的新文件。

使用以下內容調用info.php:

<?php
phpinfo();
?>

保存並退出該文件。
現在瀏覽到以下URL:http://{your_server}/info.php
您應該看到PHP信息頁面:

驗證PHP正常工作後刪除該文件。

rm /var/www/html/info.php

安裝PHP模塊

最有可能的是,當您安裝基於PHP的應用程序時,它將具有PHP模塊依賴性。

一個常見的PHP模塊是php-curl模塊。

我們可以用apt來安裝這些。 只需在您需要安裝的模塊前面添加“php-”。

apt install php-curl

如果您在查找所需的模塊時遇到問題,只需輸入apt install php(模塊的第一個字母),然後點擊TAB鍵。

Ubuntu將爲您列出所有匹配的包。

# apt install php-c 
php-cache-integration-tests  php-cgi                      php-common                  php-console-table 
php-cache-lite              php-cli                      php-composer-ca-bundle      php-constant-time 
php-cache-tag-interop        php-cli-prompt              php-composer-semver          php-curl 
php-cas                      php-codecoverage            php-composer-spdx-licenses    
php-cassandra                php-codesniffer              php-console-commandline

原文鏈接:https://www.linuxidc.com/Linux/2018-08/153739.htm

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章