如何在centos下搭建lnmp环境最后安装wordpress
2018-01-30 15:31
756 查看
实验环境:centos 6.8 32(阿里云Ecs)或者本地搭建虚拟机(需要联网)
第一步:搭建Nginx静态服务器
安装Nginx
使用yum安装Nginx:
yum install nginx -y修改 /etc/nginx/conf.d/default.conf,去除对IPv6地址的监听(centos的lnmp环境禁止ipv6访问,若不取消监听,nginx启动失败),可参考下面的代码示例:示例代码:/ETC/NGINX/CONF.D/DEFAULT.CONF
server { listen 80 default_server; # listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }修改完成后,启动Nginx:
nginx此时,可用(ip)HTTP服务来确认是否已经安装成功。将Nginx设置为开机自动启动:
chkconfig nginx on
第二部分:安装MySQL数据库服务
安装MySQL
使用yum安装MySQL:
yum install mysql-server -y安装完成后,启动MySQL服务:
service mysqld restart将MySQL设置为开机自动启动:
chkconfig mysqld on进入MySQL设置MySQL密码:
mysql -uroot -p 回车进入 set password = password('newpassword');创建一个数据库名的WordPress
create database wordpress;MySQL部分设置完了,我们退出MySQL环境:
qiut
第三步:搭建 PHP 环境
安装 PHP
yum install php php-fpm php-mysql -y安装之后,启动 PHP-FPM 进程:
service php-fpm start把 PHP-FPM 也设置成开机自动启动:
chkconfig php-fpm on
CentOS 6 默认已经安装了 PHP-FPM 及 PHP-MYSQL,下面命令执行的可能会提示已经安装。
PHP-FPM 默认监听 9000 端口
第四步:配置 Nginx 并运行 PHP 程序
配置 Nginx
在 /etc/nginx/conf.d 目录中新建一个名为 wordpress.conf 的文件,并配置 Nginx 端口 ,配置示例如下:示例代码:/ETC/NGINX/CONF.D/WORDPRESS.CONFserver { listen 80; # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { root /usr/share/php; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }修改配置完成后,重启 nginx 服务
service nginx restart安装并配置 WordPress[/code]
第五步:安装 WordPress
配置好 LNMP 环境后,继续使用yum来安装 WordPress:
yum install wordpress -y安装完成后,就可以在 /usr / share / wordpress 看到WordPress的源代码了。配置数据库配置NginxWordPress已经安装完毕,我们配置Nginx把请求转发给PHP-FPM来处理首先,重命名默认的配置文件:
cd /etc/nginx/conf.d/ mv default.conf defaut.conf.bak在
/etc/nginx/conf.d创建wordpress.conf配置时,参考下面的内容:
server { listen 80; root /usr/share/wordpress; location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php index.php; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }把上述的DB配置同步到WordPress的配置文件中,可参考下面的配置:
WP-config.php文件
vim /etc/wordpress/wp-config.php
示例代码:<?php/*** The base configuration for WordPress** The wp-config.php creation script uses this file during the* installation. You don’t have to use the web site, you can* copy this file to “wp-config.php” and fill in the values.** This file contains the following configurations:** * MySQL settings* * Secret keys* * Database table prefix* * ABSPATH** @link https://codex.wordpress.org/Editing_wp-config.php ** @package WordPress*/// ** 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’, ‘root’);/** MySQL database password */define(‘DB_PASSWORD’, ‘MyPas$word4Word_Press’);/** 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’, ”);/**#@+* Authentication Unique Keys and Salts.** Change these to different unique phrases!* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.** @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 Database Table prefix.** You can have multiple installations in one database if you give each* a unique prefix. Only numbers, letters, and underscores please!*/$table_prefix = ‘wp_’;/*** See http://make.wordpress.org/core/2013/10/25/the-definitive-guide-to-disabling-auto-updates-in-wordpress-3-7 *//* Disable all file change, as RPM base installation are read-only */define(‘DISALLOW_FILE_MODS’, true);/* Disable automatic updater, in case you want to allowabove FILE_MODS for plugins, themes, … */define(‘AUTOMATIC_UPDATER_DISABLED’, true);/* Core update is always disabled, WP_AUTO_UPDATE_CORE value is ignore *//*** For developers: WordPress debugging mode.** Change this to true to enable the display of notices during development.* It is strongly recommended that plugin and theme developers use WP_DEBUG* in their development environments.** For information on other constants that can be used for debugging,* visit the Codex.** @link https://codex.wordpress.org/Debugging_in_WordPress */define(‘WP_DEBUG’, false);/* That’s all, stop editing! Happy blogging. *//** Absolute path to the WordPress directory. */if ( !defined(‘ABSPATH’) )define(‘ABSPATH’, ‘/usr/share/wordpress’);/** Sets up WordPress vars and included files. */require_once(ABSPATH . ‘wp-settings.php’);配置后,通知Nginx进程重新加载9cef:nginx -s重新加载相关文章推荐
- CentOS 5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装Wordpress
- CentOS5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装wordpress
- CentOS 5.5安装Nginx、PHP(FastCGI)、MySQL --搭建LNMP环境安装Wordpress、Discuz
- CentOS-6 yum安装nginx php53 mysql55 搭建LNMP环境
- CentOS---lnmp环境搭建---yum傻瓜式安装
- 基于CentOS 6.8平台最新源代码包编译安装LNMP环境搭建(Nginx+MySQL+PHP)
- CentOS下Web服务器环境搭建LNMP一键安装包
- centos 6.4 下的lnmp 生产环境搭建及安装脚本
- 总结CentOS 6.0下搭建LNMP环境(源码安装)
- CentOs lnmp环境搭建wordpress博客
- centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课
- CentOS 6.5 LNMP环境搭建 编译安装Nginx
- 手动编译安装LNMP环境,搭建wordpress博客
- CentOS 6.5 LNMP环境搭建 编译安装Mysql
- 编译安装LNMP环境,搭建wordpress博客
- CentOS 7源码编译安装PHP5.6和Nginx1.7.9及MySQL(搭建LNMP环境)
- CentOS 6.4 安装配置LNMP服务器(Nginx+PHP+MySQL) 及搭建Wordpress
- CentOS 6.5 LNMP环境搭建 编译安装PHP
- centos 6.4 下的lnmp 生产环境搭建及安装脚本