分享一下我搭建博客的过程
(第一次尝试,如有错误,还望指出,谢谢!)
准备工作:
- 一个服务器(阿里云,腾讯云都可以)
- 一个域名
- xshell (一个远程终端)
- xftp5(方便对服务器文件操作)(协议选sftp)
- 一个文本编辑器(设置成xftp默认编辑器的方法工具->选项->高级)
1.centos6.7 搭建lnmp
常识及注意:
1. CentOS登陆的用户名是root
2. 键入命令时不要带上#
3. 大写 I 进入插入模式、ESC退出插入模式、:wq 退出并保存
4. DNSPOD对应的DNS服务器为f1g1ns1.dnspod.net
f1g1ns2.dnspod.netclooudxns对应的DNS服务器为
lv3ns1.ffdns.net
lv3ns2.ffdns.net
lv3ns3.ffdns.net
lv3ns4.ffdns.net5.301跳转从一个地址301重定向到另一个地址。注:仅已备案域名可使用。
6.A、@记录以及CNAME参考具体域名服务商
1.先做配置环境
#yum install epel-release
#yum -y groupinstall "Development Tools"
#yum update //安装第三方Yum库(库里有很多安装包而openssl是其中一个)
#yum install openssl-devel openssl-perl openssl-static//安装Openssl
2.安装nginx
#rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
#yum install nginx
#vi /etc/nginx/nginx.conf
在http { 内加入 server_tokens off;关闭显示版本号提升安全
#iptables -I INPUT -p tcp --dport 80 -j ACCEPT
#service iptables save
#service iptables restart
#service nginx start
#chkconfig nginx on
3.安装mysql5.7
#rpm -ivh http://repo.mysql.com/mysql57-community-release-el6-8.noarch.rpm
#yum install mysql-community-server.x86_64
#service mysqld start
#chkconfig mysqld on
查看密码:**(要记住的)**
#grep "password" /var/log/mysqld.log
找到[Note] A temporary password is generated for root@localhost: xxxxxxxx
#mysql_secure_installation 输入刚才的密码进入
包括重置数据库root密码,删除匿名帐户,禁止root账户远程登录,删除测试数据库,重新载入数据表,都选“是”
创建博客数据库
# mysql -u root -p
然后输入上面的密码
# create database recclay;
(分号不要忘)
4.安装PHP7.0
#yum install libxml2-devel freetype curl curl-devel libpng-devel libjpeg libjpeg-devel libmcrypt freetype-devel libmcrypt-devel libxslt libxslt-devel
#wget http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
#mv mirror php.tar.gz
#tar zxvf php.tar.gz
#cd php-7.1.1
#./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-curl --with-freetype-dir --with-gd --with-
gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --
with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --with-zlib-dir --with-mhash --with-mcrypt --with-openssl-dir --with-jpeg-dir --enable-gd-jis-conv --
enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-gd-native-ttf --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --
enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --disable-fileinfo
#make && make install
然后添加php环境
#vim /etc/profile 最后加入
export PATH="/usr/local/php7/bin:$PATH"
#source /etc/profile
#php -v 反馈php7.0
复制一些配置文件
#cp php.ini-production /usr/local/php7/etc/php.ini
#cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
#cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
#cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
#chmod +x /etc/init.d/php-fpm
#service php-fpm start
#chkconfig php-fpm on
链接php与nginx
#vi /etc/nginx/conf.d/default.conf
将其中pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000改成下面这样
#pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000`
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
#service nginx restart
#iptables -I INPUT -p tcp --dport 9000 -j ACCEPT
#service iptables save
#service iptables restart
链接mysql与php
编辑/usr/local/php7/etc/php.ini
找到pdo_mysql.default_socket= 和mysqli.default_socket = 后面加上 /var/lib/mysql/mysql.sock
即pdo_mysql.default_socket= /var/lib/mysql/mysql.sock和mysqli.default_socket= /var/lib/mysql/mysql.sock
下面我们在/usr/share/nginx/html下新建个php文件试试
#vi /usr/share/nginx/html/cs.php插入
<?php phpinfo();?>
会显示php版本
为了安全我们需要关闭网页头部php版本信息,编辑/usr/local/php7/etc/php.ini将expose_php = On改成Off重启即可。
> 重启命令:`# service php-fpm restart`
配置是否成功呢?先进入在web浏览器上输入:“**你的主机ip/cs.php**”
(cs.php位于 /usr/share/nginx/html)
这是我的/etc/nginx/conf.d/default.conf供参考用,已经开启过伪静态和地址重写。请灵活参考。
此处为网站配置
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.php;
if (-f $request_filename/index.html) {
rewrite (.*) $1/index.html break;
}
if (-f $request_filename/index.php) {
rewrite (.*) $1/index.php;
}
if (!-f $request_filename) {
rewrite (.*) /index.php;
}
}
#error_page 404 /404.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 html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$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;
#}
}
2.进入服务器供应商管理界面做配置
1.打开需要端口
打开端口前需要添加安全组。(随意命名)
22 ———ssh
80 ———nginx
9000——-PHP
443——–SSL
2.申请SSL证书
云产品 ->SSL证书管理->申请证书
待证书审批下来以后进入终端键入:
#cd /etc/ssl/certs/
# openssl genrsa -des3 -out privkey.pem 2048//设置一个证书密码记住它
创建pem证书
先进入
# cd /etc/ssl/certs/
然后
# openssl dhparam -out dhparam.pem 4096
相关链接:http://www.open-open.com/lib/view/open1430794673710.html
3.文件配置
1.网站配置
为方便新手,我直接做了一份网站配置模板。你直接把里面的×××改成对应你的域名即可。
提取码3edy
改完之后,上传到 /etc/nginx/conf.d 并把原来的给全删了
2.下载wordpress
下载完以后到子文件夹下选中打包,然后上传到:
/usr/share/nginx/html
(原来的可以删了)
到终端安装解压包
#yum install zip unzip
然后解压wordpress压缩包
# cd /usr/share/nginx/html
# unzip wordpress.zip
退到根目录用:
# cd
3.SSL证书配置
从服务器商那里把证书下载到本地,进入nginx文件夹 把安全证书命名为
www.×××.×××.crt
把KEY文件命名为:
www.×××.×××.key
而后上传到
/etc/nginx
4.nginx配置
直接在
/etc/nginx
中,上传覆盖我这个文件,开启gzip(压缩传输)
而后提取码fvrj
> nginx -t
查看是否有语法错误
重载nginx
# nginx -s reload
修改nginx配置文件(nginx把这个文件夹映射到网站上),所在目录
/etc/nginx/conf.d
查看带root 那一行对应文件名字 我的是wwwroot
然后在xftp中进入
/usr/share/nginx
html那个名字改成wwwroot
5.安装wordpress
在shell里面
# chmod 777 -R /usr/share/nginx/wwwroot
给文件夹权限,参考链接:http://m.blog.csdn.net/article/details?id=8103264
3.进入网页装博客系统
可以直接用你的主机Ip登陆,会自动跳转到wordpress安装导引界面。或者用域名登陆(如果你解析过的话)
-数据库名:你创建的数据库名字
-用户名: 对应服务器 centos 默认 root ubuntu默认 ubuntu
-密码:你的数据库密码
-数据库主机: 127.0.0.1
-表前缀:原则上为wp_