Linux系统下通过nginx运行WordPress
来源:互联网 发布:淘宝网站首页源代码 编辑:程序博客网 时间:2024/06/08 03:36
声明:本文是基于nginx来运行WordPress的,所以需要先安装nginx,至于nginx的安装教程本文将不做详细叙述,请自行百度了解。
一、下载和解压缩
下载并解压在http://wordpress.org/download/ 处下载的安装包。
如果你要上传WordPress到一个远程主机,则要用浏览器下载WordPress软件包到你的计算机上,然后解压缩。
如果你可以用shell访问主机,并可以使用基于控制台的工具,如果你不想用FTP,你可以用
wget http://wordpress.org/latest.tar.gz(或者lynx或者其它的基于控制台的浏览器)将WordPress直接下载到你的网站服务器上。
然后解压缩包:
tar -xzvf latest.tar.gz
WordPress软件包会解压到一个叫做wordpress的文件夹中,这个文件夹和你下载的latest.tar.gz在同一个目录中。
二、创建数据库和用户
使用 MySQL客户端,如果你可以访问你的服务器的shell,你又愿意使用命令行,并且你的MySQL用户有权限创建MySQL用户和数据库,你可以按如下例子创建WordPress用户名和数据库。
$ mysql -u ''adminusername'' -pEnter password:Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5340 to server version: 3.23.54Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> CREATE DATABASE ''databasename'';Query OK, 1 row affected (0.00 sec)mysql> GRANT ALL PRIVILEGES ON ''databasename''.* TO "''wordpressusername''"@"''hostname''" -> IDENTIFIED BY "''password''";Query OK, 0 rows affected (0.00 sec)mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec)mysql> EXITBye$
在上面:
adminusername通常是root,除非设置过拥有高级权限的帐号。
databasename的值用wordpress或blog比较好。
wordpressusername的值用wordpress比较好。
hostname通常是localhost。如果你不知道这个值是什么,请你和你的系统管理员联系。如果你是系统管理员,请指出这个值应该是什么。
password应该是不容易猜测的密码,最好同时包含大写字母、小写字母、数字和符号。
把databasename, wordpressusername, hostname, 和 password写下来
三、设置 wp-config.php
为了继续进行以下环节,请你找到以下代码并进行修改:
// ** MySQL settings ** //define('DB_NAME', 'wordpress'); // The name of the databasedefine('DB_USER', 'username'); // Your MySQL usernamedefine('DB_PASSWORD', 'password'); // ...and passworddefine('DB_HOST', 'localhost'); // 99% chance you won't need to change this value
返回到你在第一步时解压WordPress包的地方, 重命名wp-config-sample.php文件为wp-config.php.
用你喜欢的编辑器打开已经重命名的wp-config.php并且填写好以下信息,例如:
DB_NAME
你在第二步时为WordPress建立的数据库名称。
DB_USER
你在第二步建立WordPress数据库时创建的用户名。
DB_PASSWORD
你在第二步时为你数据库用户所创建的密码。
DB_HOST
你在第二步时决定的主机名 (通常时localhost,但也不是绝对,请根据实际情况填写)。
保存文件。
若想知道关于创建配置文件的更多细节和配置指南,请察看Editing wp-config.php。
下面给出可用的wp-config.php参考文件实例
<?php/** * WordPress基础配置文件。 * * 这个文件被安装程序用于自动生成wp-config.php配置文件, * 您可以不使用网站,您需要手动复制这个文件, * 并重命名为“wp-config.php”,然后填入相关信息。 * * 本文件包含以下配置选项: * * * MySQL设置 * * 密钥 * * 数据库表名前缀 * * ABSPATH * * @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php * * @package WordPress */// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** ///** WordPress数据库的名称 */define('DB_NAME', 'wordpress');/** MySQL数据库用户名 */define('DB_USER', 'root');/** MySQL数据库密码 */define('DB_PASSWORD', 'root');/** MySQL主机 */define('DB_HOST', 'localhost');/** 创建数据表时默认的文字编码 */define('DB_CHARSET', 'utf8');/** 数据库整理类型。如不确定请勿更改 */define('DB_COLLATE', '');/**#@+ * 身份认证密钥与盐。 * * 修改为任意独一无二的字串! * 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/ * WordPress.org密钥生成服务} * 任何修改都会导致所有cookies失效,所有用户将必须重新登录。 * * @since 2.6.0 */define('AUTH_KEY', 'put your unique phrase here');define('SECURE_AUTH_KEY', 'put your unique phrase here');define('LOGGED_IN_KEY', 'put your unique phrase here');define('NONCE_KEY', 'put your unique phrase here');define('AUTH_SALT', 'put your unique phrase here');define('SECURE_AUTH_SALT', 'put your unique phrase here');define('LOGGED_IN_SALT', 'put your unique phrase here');define('NONCE_SALT', 'put your unique phrase here');/**#@-*//** * WordPress数据表前缀。 * * 如果您有在同一数据库内安装多个WordPress的需求,请为每个WordPress设置 * 不同的数据表前缀。前缀名只能为数字、字母加下划线。 */$table_prefix = 'wp_';/** * 开发者专用:WordPress调试模式。 * * 将这个值改为true,WordPress将显示所有用于开发的提示。 * 强烈建议插件开发者在开发环境中启用WP_DEBUG。 * * 要获取其他能用于调试的信息,请访问Codex。 * * @link https://codex.wordpress.org/Debugging_in_WordPress */define('WP_DEBUG', false);/** * zh_CN本地化设置:启用ICP备案号显示 * * 可在设置→常规中修改。 * 如需禁用,请移除或注释掉本行。 */define('WP_ZH_CN_ICP_NUM', true);/* 好了!请不要再继续编辑。请保存本文件。使用愉快! *//** WordPress目录的绝对路径。 */if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/');/** 设置WordPress变量和包含文件。 */require_once(ABSPATH . 'wp-settings.php');if(is_admin()) { add_filter('filesystem_method', create_function('$a','return "direct";' )); define('FS_CHMOD_DIR', 0751);}
如果想将英文版的界面改为中文版,可以下载中文版的WordPress源码包(下载链接:https://yunpan.cn/cqzgxnknQWMNr 访问密码 382a),然后替换原英文版的WordPress源码中除wp-config.php之外的所有文件,然后重新打开界面即可。
四、放置文件
如果你需要上传文件到服务器,用你喜欢的FTP客户端上传WordPress目录中的所有内容(不包含WordPress目录本身)到网站的根目录。
如果文件已经在服务器上了,你可以用shell访问来安装WordPress,移动所有wordpress目录内的内容(不包含WordPress目录本身)到网站的根目录。
五、修改nginx配置文件
假设为WordPress分配的端口为94,nginx配置文件内容如下:
user apache;worker_processes 2;error_log /var/log/nginx/error-94.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid /var/log/nginx/nginx-94.pid;events { worker_connections 1024;}http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; client_max_body_size 100m; gzip on; server { listen 94; server_name localhost; #set $root_path 'G:/WWW/lumen/public'; set $root_path '/Blog'; root $root_path; index index.php index.html index.htm; try_files $uri $uri/ @rewrite; # This order might seem weird - this is attempted to match last if rules below fail.# http://wiki.nginx.org/HttpCoreModulelocation / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args;}# Add trailing slash to */wp-admin requests.rewrite /wp-admin$ $scheme://$host$uri/ permanent;# Directives to send expires headers and turn off 404 error logging.location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ { access_log off; log_not_found off; expires max;}# Uncomment one of the lines below for the appropriate caching plugin (if used).#include global/wordpress-wp-super-cache.conf;#include global/wordpress-w3-total-cache.conf;# Pass all .php files onto a php-fpm/php-fcgi server. location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index /index.php; include fastcgi_params; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; } } #server { # listen 88; # server_name localhost; # set $root_path '/srv/www/maxuejie/public'; # root $root_path; # index index.php index.html index.htm; # #try_files $uri $uri/ @rewrite; # location / { # try_files $uri $uri/ /index.php?$query_string; # } # location @rewrite { # rewrite ^/(.*)$ /index.php?_url=/$1; # } # location ~ \.php { # fastcgi_pass 127.0.0.1:9000; # fastcgi_index /index.php; # include /usr/local/nginx/conf/fastcgi_params; # fastcgi_split_path_info ^(.+\.php)(/.+)$; # fastcgi_param PATH_INFO $fastcgi_path_info; # fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; # } # location ~* ^/(css|img|js|flv|swf|download)/(.+)$ { # root $root_path; # } # location ~ /\.ht { # deny all; # } #} # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #}}
将该配置文件放到/etc/nginx/目录下,然后执行如下指令启动该端口服务
sudo /usr/sbin/nginx -c /etc/nginx/wp-94.conf -s reload
用你喜欢的浏览器,访问你刚刚安装在网站上的WordPress目录里面的wp-admin/install.php,
如果你安装在了网站的根目录,你应该访问:
http://example.com/wp-admin/install.php (example.com即为你服务器的IP),然后WordPress的界面就会呈现在你的眼前!
- Linux系统下通过nginx运行WordPress
- Nginx下搭建wordpress
- ubuntu14.04系统下在Nginx中安装wordpress
- linux系统通过nginx实现tomcat集群
- linux系统通过nginx实现tomcat集群
- linux系统通过Nginx部署Django
- linux下通过源码编译安装Nginx
- linux下通过Nginx部署django项目
- Nginx 下 WordPress rewrite 规则
- linux系统下运行aapt
- linux下通过脚本监控程序运行
- linux下通过脚本监控程序运行
- 如何搭建LNMP环境(Linux+Nginx+MySql+Php)来运行wordpress
- linux下安装wordpress
- linux下搭建wordpress
- linux下配置wordpress
- Linux下安装Wordpress
- linux下制作系统命令 nginx启动
- vb
- 问题:willDisplayHeaderView在 iOS7下不被调用
- 乐观锁和悲观锁
- Android Studio多渠道签名打包
- iOS导入cocos2d游戏
- Linux系统下通过nginx运行WordPress
- js中top、clientTop、scrollTop、offsetTop的区别 文字详细说明版
- Asp.net mvc 提交列表(一)
- 水晶报表字段字体自适应方法
- 1到100 的和
- 利用vb设计乘法运算
- Python_学习笔记
- LeetCode——004
- iOS内购