1. 程式人生 > 實用技巧 >Ubuntu20.04安裝apache、mysql、php、phpmyadmin、wordpress(二)

Ubuntu20.04安裝apache、mysql、php、phpmyadmin、wordpress(二)

環境

系統:Ubuntu20.04 LTS

安裝環境:apache、mysql、php、最新版phpmyadmin、wordpress

(二)

5.下載最新版的phpmyadmin

下載地址:https://www.phpmyadmin.net/

下載完成後,進入到下載目錄,解壓phpmyadmin壓縮檔案

cd /home/ubuntu20/Downloads/

unzip phpMyAdmin-5.0.4-all-languages.zip

把phpMyAdmin-5.0.4-all-languages移動到網站目錄下

sudo mvphpMyAdmin-5.0.4-all-languages/ /var/www/html/phpmyadmin

檢視資料夾是否成功移動

建立tmp目錄並設定適當的許可權。

mkdir /var/www/html/phpmyadmin/tmp

sudo chown -R www-data:www-data/var/www/html/phpmyadmin

chmod 777/var/www/html/phpmyadmin/tmp

為 phpMyAdmin 建立 Apache 配置檔案,並在文字編輯器中編輯

touch/etc/apache2/conf-enabled/phpmyadmin.conf

vim /etc/apache2/conf-enabled/phpmyadmin.conf

將以下內容新增到檔案

Alias /phpmyadmin /var/www/html/phpmyadmin
Alias /phpMyAdmin /var/www/html/phpmyadmin
<Directory /var/www/html/phpmyadmin>

AddDefaultCharset UTF-8

<IfModule mod_authz_core.c>

<RequireAny>

Require all granted

</RequireAny>

</IfModule>

</Directory>

<Directory /var/www/html/phpmyadmin/setup/>

<IfModule mod_authz_core.c>

<RequireAny>

Require all granted

</RequireAny>

</IfModule>

</Directory>

(因為我不確定是conf-enable還是conf-available資料夾,然後就在兩資料夾下都放了這個配置檔案)

儲存檔案並關閉它。重啟Apache服務

sudo a2enconf phpmyadmin

sudo systemctl restart apache2

配置phpmyadmin目錄下libraries檔案下的 config.default.php 檔案。

$cfg[‘PmaAbsoluteUri’] = ‘http://localhost/phpmyadmin’;
$cfg[‘blowfish_secret’] = ‘123456’;
$cfg[‘Servers’][$i][‘auth_type’] = ‘cookie’;


修改後,瀏覽器開啟http://localhost/phpmyadmin

=======================================================================================

問題1:配置檔案現在需要一個短語密碼

原因:新版本的PhpMyAdmin 增強了安全性,需要在配置檔案設定一個短語密碼。

解決方法:

在phpMyAdmin目錄中,開啟config.inc.php,18行

$cfg['blowfish_secret'] = ''; 改成 $cfg['blowfish_secret'] = '123456'; (注:其中的'123456′為隨意的字元)

這個密碼用於Cookies的加密,以免多個PhpMyAdmin或者和其他程式共用Cookies時搞混。

  

問題2:配置檔案中的密文(blowfish_secret)太短。

原因:

把$cfg['Servers'][$i]['auth_type'] 引數從config改為了cookie,配置檔案又要求cookie模式必須加長引數的值,32位字元的長度。

解決方法:

修改phpmyadmin配置檔案

/var/www/html/phpmyadmin/config.inc.php  //配置檔案config.inc.php預設沒有,需要把同目錄下的config.sample.inc.php配置檔案複製一份改名為config.inc.php
搜尋:$cfg[‘blowfish_secret’] = ' ' 在' ' 中加入一段長字元,32位以上。然後重啟apache服務,重新整理phpmyadmin的首頁,就能看到警告沒了。

  

問題3:phpMyAdmin-錯誤:配置檔案許可權錯誤,不應任何使用者都能修改!

原因:phpmyadmin目錄許可權過高,linux系統設定了777訪問許可權;

解決方法:給phpmyadmin許可權為755就可以了。

sduo chmod -R 755 /var/www/html/phpmyadmin

問題4:phpMyAdmin 高階功能尚未完全設定,部分功能未啟用。

原因:未建立'phpmyadmin'的資料庫,

解決方法:建立一個名為'phpmyadmin'的資料庫,並在那裡設定phpMyAdmin配置儲存。

建立資料庫如下:
mysql>create database phpmyadmin;    //建立phpmyadmin資料庫
mysql>create user 'phpmyadmin'@'%' identified by '123456';    //建立一個使用者名稱為phpmyadmin,密碼為123456的使用者
mysql>grant all privileges on phpmyadmin.* to 'phpmyadmin'@'%' with grant option;    //授予phpmyadmin使用者所有許可權
mysql> flush privileges;    //重新整理許可權

建立好資料庫後,匯入sql檔案"./phpmyadmin/sql/create_tables.sql"

匯入後會顯示一些警告資訊之類的,先不管這個。

開啟phpmyadmin目錄下config.inc.php修改配置檔案

$cfg['Servers'][$i]['pmadb'] = 'phpmyadmin';
$cfg['Servers'][$i]['bookmarktable'] = 'pma__bookmark';
$cfg['Servers'][$i]['relation'] = 'pma__relation';
$cfg['Servers'][$i]['table_info'] = 'pma__table_info';
$cfg['Servers'][$i]['table_coords'] = 'pma__table_coords';
$cfg['Servers'][$i]['pdf_pages'] = 'pma__pdf_pages';
$cfg['Servers'][$i]['column_info'] = 'pma__column_info';
$cfg['Servers'][$i]['history'] = 'pma__history';
$cfg['Servers'][$i]['table_uiprefs'] = 'pma__table_uiprefs';
$cfg['Servers'][$i]['tracking'] = 'pma__tracking';
$cfg['Servers'][$i]['userconfig'] = 'pma__userconfig';
$cfg['Servers'][$i]['recent'] = 'pma__recent';
$cfg['Servers'][$i]['favorite'] = 'pma__favorite';
$cfg['Servers'][$i]['users'] = 'pma__users';
$cfg['Servers'][$i]['usergroups'] = 'pma__usergroups';
$cfg['Servers'][$i]['navigationhiding'] = 'pma__navigationhiding';
$cfg['Servers'][$i]['savedsearches'] = 'pma__savedsearches';
$cfg['Servers'][$i]['central_columns'] = 'pma__central_columns';
$cfg['Servers'][$i]['designer_settings'] = 'pma__designer_settings';
$cfg['Servers'][$i]['export_templates'] = 'pma__export_templates';

然後登出賬戶並重新登入,就好了。

6.安裝wordpress

下載wordpress

wget https://cn.wordpress.org/latest-zh_CN.tar.gz

解壓wordpress安裝包

sudo tar zxvf latest-zh_CN.tar.gz

為 wordpress 配置一個數據庫

mysql> create database blog;  //建立一個叫blog的資料庫
mysql> create user 'blog'@'%' identified by '123456';  //為這個資料庫建立一個名為blog,密碼為123456的使用者
mysql> grant all privileges on blog.* to 'blog'@'%' with grant option;  //為這個使用者配置資料庫的訪問許可權
mysql> FLUSH PRIVILEGES;  //重新整理許可權,生效這些配置

由於PHP預設訪問 /var/www/html/ 資料夾,所以需要把 wordpress 資料夾裡的檔案都移動到 /var/www/html/ 目錄下

sudo mv wordpress/* /var/www/html/  移動wordpress目錄下檔案
sudo chmod -R 777 /var/www/html/  修改 /var/www/html/ 目錄許可權
sudo mv /var/www/html/index.html /var/www/html/index~.html  將apache指定到index.html
sudo systemctl restart apache2.service  重啟 Apache 服務7.wordpress

7.wordpress搭建完成

本地瀏覽器輸入伺服器IP地址,跳轉至wordpress安裝介面/
在安裝介面中輸入資料庫密碼即可完成安裝。
瀏覽器開啟:http:///localhost/wp-admin,進入wordpress後臺管理頁面。

問題1:wordpress更新需要ftp賬號和密碼

解決辦法:

在wp-config.php中新增以下程式碼

define("FS_METHOD","direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777); 

儲存檔案,並重新整理wordpress後臺

問題2:wordpress上傳檔案大小限制

解決辦法:

修改php.ini配置檔案

find / -name php.ini

我的在/etc/php/7.4/fpm/php.ini

開啟後,找到並設定以下選項的值:

upload_max_filesize = 128M

post_max_size = 128M

memory_limit 256M

max_execution_time 300

max_input_time 300

upload_max_filesize=2M //預設上傳檔案大小,這個就是2M的限制!
post_max_size=8M //上傳檔案大小上限(此引數應>=upload_max_filesize)  
memory_limit=128M //相當於單個指令碼可呼叫記憶體大小

max_execution_time=30 //最大執行時間,頁面等待時間
max_input_time=60 //接收資料最大時間限制

vim開啟檔案可在normal模式下直接按“/”進入查詢模式,輸入要查詢的字元並按下回車,vim會跳到第一個匹配的位置。

按n查詢下一個,按Shift+n查詢上一個。

其他命令: