Centos下安装配置WordPress与nginx教程

导读 WordPress是一个免费和开源网站和博客工具,使用PHP和MySQL。 它建立于2003年,并扩展到管理全部新建立的网站的22%,并拥有超过20,000个插件来定制其功能。

在使用wordpress以前,您须要在您的VPS上安装LEMP。 若是你没有Linux的,Nginx的,MySQL和PHP的服务器上的,你能够找到的教程设置它在这里 。php

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

第一步:下载WordPressmysql

咱们能够从他们的网站直接下载Wordpress:linux

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

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

tar -xzvf latest.tar.gz

第二步:建立WordPress数据库和用户web

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

如今咱们须要切换齿轮一段时间,并为wordpress建立一个新的MySQL目录。shell

继续登陆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),并填写简短的在线形式(它看起来应该像这样 )。

原文来自:https://www.linuxprobe.com/install-wordpress-nginx.html

相关文章
相关标签/搜索