将WordPress安装到Ubuntu 18.04(LTS)上(LEMP堆栈:Nginx,MariaDB,PHP)

首先

提供以下是在Ubuntu 18.04上安装最新版WordPress的方法。
我们将使用MariaDB作为数据库(因为据调查,它比MySQL更具发展潜力)。

WordPress的设置用户名为wordpressuser,密码为gorillagorilla。
数据库名设为wordpress。

假设域名为www.example.com,服务器本地IP地址为192.168.0.2,请写下以下的设置方法。

第一步:安装Nginx HTTP服务器

sudo apt install nginx

步骤2:安装MariaDB数据库服务器

sudo apt-get install mariadb-server mariadb-client

安装完成后,请运行以下命令来执行mysql的初始设置。

sudo mysql_secure_installation
    • Enter current password for root (enter for none): そのままエンターを押す

 

    • Set root password? [Y/n]: Y

 

    • New password: パスワードの入力

 

    • Re-enter new password: パスワードの入力

 

    • Remove anonymous users? [Y/n]: Y

 

    • Disallow root login remotely? [Y/n]: Y

 

    • Remove test database and access to it? [Y/n]: Y

 

    Reload privilege tables now? [Y/n]: Y

这个密码与WordPress的密码(gorillagorilla)无关。

步骤3:安装PHP 7.2及相关模块。

sudo apt install php7.2-fpm php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-zip php7.2-curl

安装完成后,建议进行以下设置编辑。
不过,不进行此设置也没有什么特别的问题。

sudo emacs /etc/php/7.2/fpm/php.ini

变更的地方如下所示

file_uploads = On
allow_url_fopen = On
memory_limit = 256M
upload_max_filesize = 100M
cgi.fix_pathinfo=0
max_execution_time = 360
date.timezone = Asia/Tokyo

第四步:创建WordPress的数据库。

密码设为gorillagorilla,用户名设为wordpressuser。

sudo mysql -u root -p

当你登录到数据库后,输入下面的指令
(在这里,数据库的名称设定为wordpress)

CREATE DATABASE wordpress;
CREATE USER 'wordpressuser'@'localhost' IDENTIFIED BY 'gorillagorilla';
GRANT ALL ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'gorillagorilla' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

密码是gorillagorilla,用户名是wordpressuser。

步骤五:安装最新版本的WordPress。

cd /tmp && wget https://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz
sudo mv wordpress /var/www/html/wordpress

权限相关的变更

sudo chown -R www-data:www-data /var/www/html/wordpress/
sudo chmod -R 755 /var/www/html/wordpress/

步骤六:更新Nginx HTTP服务器的配置

创建以下文件

sudo emacs /etc/nginx/sites-available/wordpress

内容如下。服务器名称设为www.example.com,但可根据需要进行更改。

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/wordpress;
    index  index.php index.html index.htm;
    server_name  192.168.0.2 www.example.com;

     client_max_body_size 100M;

    location / {
        try_files $uri $uri/ /index.php?$args;        
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

第七步:在Nginx上启用WordPress网站。

sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/

重新启动Nginx

sudo /etc/init.d/nginx restart

步骤8:编辑WordPress的配置文件

sudo cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php
sudo emacs /var/www/html/wordpress/wp-config.php

将更改内容如下所示。

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');

/** MySQL database username */
define('DB_USER', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'gorillagorilla');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

请将密码设置为gorillagorilla,用户名设置为wordpressuser。

第九步:访问

通过浏览器访问服务器(输入192.168.0.2)。

应该看起来正常。

附加说明:被迷住了

最开始错误地安装了Mysql,急忙删除并安装了MariaDB,但是出现了一堆错误。
如果已经安装了Mysql,也许还是直接用Mysql会更好。

广告
将在 10 秒后关闭
bannerAds