70

Centos下安装配置WordPress与nginx教程

 5 years ago
source link: https://www.linuxprobe.com/install-wordpress-nginx.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
导读 WordPress是一个免费和开源网站和博客工具,使用PHP和MySQL。 它创建于2003年,并扩展到管理所有新创建的网站的22%,并拥有超过20,000个插件来定制其功能。

在使用wordpress之前,您需要在您的VPS上安装LEMP。 如果你没有Linux的,Nginx的,MySQL和PHP的服务器上的,你可以找到的教程设置它在这里 。

一旦你有了用户和所需的软件,你可以开始安装wordpress!

第一步:下载WordPress

我们可以从他们的网站直接下载Wordpress:

wget http://wordpress.org/latest.tar.gz

这个命令会将压缩的wordpress包直接下载到用户的主目录。 您可以将其解压缩到下一行:

tar -xzvf latest.tar.gz 
第二步:创建WordPress数据库和用户

在我们解压缩wordpress文件后,它们将在主目录中名为wordpress的目录中。

现在我们需要切换齿轮一段时间,并为wordpress创建一个新的MySQL目录。

继续登录MySQL Shell:

mysql -u root -p

使用您的MySQL root密码登录,然后我们需要创建一个wordpress数据库,该数据库中的用户,并给该用户一个新的密码。 请记住,所有MySQL命令必须以分号结束。

首先,让我们做数据库(为了简单起见,我调用我的wordpress;随意给它选择任何名称):

CREATE DATABASE wordpress;
Query OK, 1 row affected (0.00 sec)

然后我们需要创建新用户。 您可以使用任何您喜欢的数据库,名称和密码替换:

CREATE USER wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)

设置新用户的密码:

SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password");
Query OK, 0 rows affected (0.00 sec)

完成通过授予新用户的所有权限。 没有这个命令,wordpress安装程序将无法启动:

GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

然后刷新MySQL:

FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
退出MySQL shell:

exit
第三步:设置WordPress配置

第一步是将位于WordPress目录中的示例WordPress配置文件复制到我们将要编辑的新文件中,创建一个新的可用的WordPress配置:

cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

然后打开wordpress config:

sudo nano ~/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', 'password');

保存并退出。

第四步:复制文件

我们几乎完成将Wordpress上传到服务器。 我们需要创建我们将保留wordpress文件的目录:

sudo mkdir -p /var/www/wordpress

最后一步是将解压缩的WordPress文件传输到网站的根目录。

sudo cp -r ~/wordpress/* /var/www/wordpress

我们可以修改的权限/var/www ,使未来的自动的WordPress插件和文件与SFTP编辑的更新。 如果不执行这些步骤,您可能会在尝试任一任务时收到“要执行请求的操作,需要连接信息”错误消息。

首先,切换到web目录:

cd /var/www/

将目录的所有权授予nginx用户,将“用户名”替换为服务器用户的名称。

sudo chown nginx:nginx * -R
sudo usermod -a -G nginx username
第五步:设置Nginx服务器

现在我们需要设置WordPress虚拟主机。 虽然Wordpress在安装中有一个额外的步骤,nginx网站给我们一个简单的配置文件:

打开默认的nginx默认hosts文件:

sudo vi /etc/nginx/conf.d/default.conf

配置应包括以下更改(更改的详细信息在配置信息下):

#
# The default server
#
server {
    listen       80;
    server_name  _;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        root   /var/www/wordpress;
        index index.php  index.html index.htm;
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/wordpress;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

以下是更改的详细信息 - 您可能已经有一些效果:

在索引行中添加index.php。

将根更改为/ var / www / wordpress;

取消注释以“location〜\ .php $ {”,

更改根以访问实际的文档根,/ var / www / wordpress;

更改fastcgi_param行以帮助PHP解释器找到我们存储在文档root home中的PHP脚本。

保存,退出并重新启动nginx以使更改生效:

sudo service nginx restart
第六步结果:访问WordPress安装

一旦这一切都完成,wordpress在线安装页面,并等待你:

通过访问您网站的域名或虚拟专用服务器的IP地址访问此页面(如example.com),并填写简短的在线形式(它看起来应该像这样 )。


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK