zoukankan      html  css  js  c++  java
  • 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 一个一个手工安装的!

     
  • 相关阅读:
    Leetcode 538. Convert BST to Greater Tree
    Leetcode 530. Minimum Absolute Difference in BST
    Leetcode 501. Find Mode in Binary Search Tree
    Leetcode 437. Path Sum III
    Leetcode 404. Sum of Left Leaves
    Leetcode 257. Binary Tree Paths
    Leetcode 235. Lowest Common Ancestor of a Binary Search Tree
    Leetcode 226. Invert Binary Tree
    Leetcode 112. Path Sum
    Leetcode 111. Minimum Depth of Binary Tree
  • 原文地址:https://www.cnblogs.com/skyhu365/p/12966562.html
Copyright © 2011-2022 走看看