ubuntu安裝wordpress


Ubuntu 18.04 安裝wordpress

查看系統版本

lsb_release -a

Distributor ID: Ubuntu Description: Ubuntu 18.04.2 LTS Release: 18.04 Codename: bionic 

下載並解壓

https://wordpress.org/download/releases/

wget https://wordpress.org/wordpress-5.2.2.zip #下載源碼 sudo apt install unzip #安裝 unzip unzip wordpress-5.2.2.zip # 解壓 

PHP

sudo apt install -y php php-fpm php-mysql

php -v
# PHP 7.2.19-0ubuntu0.18.04.1 (cli) 

MariaDB

sudo apt install -y mariadb-server mariadb-client
mysql -V

# mysql  Ver 15.1 Distrib 10.1.40-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2 

Nginx

sudo apt install -y nginx

nginx -v
# nginx version: nginx/1.14.0 (Ubuntu)
server { listen 80; server_name codingday.network; root <目錄>; index index.php index.html index.htm index.nginx-debian.html; location / { try_files $uri $uri/ =404; } location ~ \.php$ { fastcgi_pass unix:/run/php/php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } # /etc/nginx/sites-enabled 

數據庫

CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; GRANT ALL ON wordpress.* TO ' wordpress '@'localhost' IDENTIFIED BY 'wordpress'; FLUSH PRIVILEGES; 

cp wp-config-sample.php wp-config.php

/** The name of the database for WordPress */ define( 'DB_NAME', 'wordpress' ); /** MySQL database username */ define( 'DB_USER', 'wordpress' ); /** MySQL database password */ define( 'DB_PASSWORD', 'wordpress' ); /** MySQL hostname */ define( 'DB_HOST', 'localhost' );

sudo chown -R www-data:www-data wordpress


sudo lsof -Pn -iTCP:3306

 

WordPress 安裝插件時無法創建目錄解決方案


sudo chown -R www-data:www-data wordpress



參考:

1、安裝 nginx
sudo apt install nginx

確認:查看端口
netstat -anp |grep 80
或者
sudo lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1750 root 6u IPv4 22825 0t0 TCP *:http (LISTEN)
nginx 1750 root 7u IPv6 22826 0t0 TCP *:http (LISTEN)
nginx 1752 www-data 6u IPv4 22825 0t0 TCP *:http (LISTEN)
nginx 1752 www-data 7u IPv6 22826 0t0 TCP *:http (LISTEN)

確認:cha查看 nginx 服務
sudo systemctl status nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2 、安裝 php
sudo apt install php php-fpm
sudo apt-get install php7.2 php7.2-fpm
確認:查看版本
php -v
PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

確認:查看進程
ps -ef |grep php
root 10848 1 0 12:41 ? 00:00:00 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)
www-data 10862 10848 0 12:41 ? 00:00:00 php-fpm: pool www
www-data 10863 10848 0 12:41 ? 00:00:00 php-fpm: pool www
dhbm 10983 1232 0 12:48 pts/0 00:00:00 grep --color=auto php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
3 、修改站點配置,測試 php 文件解析
1)、新建一個 php 文件
cd /var/www/html
sudo vim info.php
加入以下 3 行
<?php
phpinfo();
?>
2)、修改站點配置
cd /etc/nginx/sites-available/
** a. 去掉 location ~ \.php$ { 這行的注釋,同時去掉配對的 } 這行的注釋
** b. 去掉 fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; 這行的注釋
** c. 同時,修改成對應的 php-fpm 版本號的文件名(我安裝的是 php7.2)
3)、測試 nginx,重啟 nginx 服務
nginx -t
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
...

需要 sudo

sudo nginx -t
nginx: [emerg] "fastcgi_pass" directive is not allowed here in /etc/nginx/sites-enabled/default:62
nginx: configuration file /etc/nginx/nginx.conf test failed
按照錯誤提示的行號(我的錯誤在 62 行),檢查以上 a,b,c 處修改正確否!

4)、紀錄一下修改的結果
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
}

5)、正確測試結果
sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
6)、正確之后再重啟 nginx 服務
sudo systemctl restart nginx

** 不確認的話,可以查看 nginx 服務狀態!
sudo systemctl status nginx
**中途總是折騰不對時,多次 reboot ,實踐證明:必須 nginx 測試正確后,重啟服務才會正常!
7)、測試結果
本地測試:
curl 127.0.0.1
curl 127.0.0.1/info.php
瀏覽器測試:
http://192.168.1.191/
http://192.168.1.191/info.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
4、錯誤處理:nginx打開php文件總是顯示下載,並開始下載我的 info.php 文件
這是之前學習時遇到的問題(另一個虛擬機)
原因同上!
1
2
5、錯誤處理:nginx打開php文件,顯示 502 Bad Gateway
回頭處理之前學習時遇到的問題(另一個虛擬機)
不出現下載了,但是,出來 502 Bad Gateway 錯誤

檢查 /etc/nginx/sites-available/default 配置中 php部分
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;

cd /var/run/php/
ls
php7.2-fpm.pid

只有一個 pid 文件!沒有發現存在這個文件 php7.2-fpm.sock ?
怎么安裝的 php-fpm?

sudo vim /etc/nginx/sites-available/default
先改用 php-cgi 方式
fastcgi_pass 127.0.0.1:9000;

重啟 php7.2-fpm 服務
sudo systemctl restart php7.2-fpm.service
重啟 nginx
sudo systemctl restart nginx

再次測試
http://192.168.1.192/info.php
可以看到正確信息了
PHP Version 7.2.10-0ubuntu0.18.04.1
..
*** php-cgi 方式 和 php-fpm 方式差別在哪里來着?需要再次學習去!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28


***經過回憶:
之前的虛擬機上的 php 是直接按照ubuntu 18.04 官網介紹一次整體安裝了 LAMP
之后是自己從頭 LNMP 一個一個手工安裝的!

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM