笔者一直很羡慕那些搭建了个人博客的大牛,在最近工作之余也尝试着搭建了自己的博客,历时1周,这篇文章就将踩过的坑记录下来,先看下成果,链接在此
1- 购买腾讯云主机
腾讯云官网,我选了79元/月的最便宜的主机(1核1G),但还是有点贵。这里遇到的坑主要是有,假如想用xshell等软件远程登陆主机,需要设置安全组。因为开始怕麻烦,我直接设置了放通全部端口。
2- Linux
腾讯云直接选择CentOS 7.3主机(老司机推荐)
3- Nginx
- wget http: //nginx.org/download/nginx-1.8.0.tar.gz
- tar - zxvf nginx - 1.8.0.tar.gzcd nginx - 1.8.0. / configure--prefix = /usr/local / nginx
- // 注意,我安装在了/usr/local/nginx这个目录下
- // 给几个重要的指令
- // vim /usr/local/nginx/conf/nginx.conf
- // 配置Nginx
- // /usr/local/nginx/sbin/nginx -s reload
- // 重启Nginx,如果第一次运行把-s reload都去掉
- // ps -ef | grep nginx //查看Nginx进程是否运行
4- PHP
这部分是最需要当心的,因为wordpress需要PHP安装好Mysql等配置,我这次安装的是php7,我主要参考了这篇博客。编译安装PHP7
- wget http://php.net/distributions/php-7.0.0.tar.gz
- tar -zxvf php-7.0.0.tar.gz
- cd php-7.0.0
- sudo yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng
- libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2
- bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel
- openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
- php-mysqlnd libmcrypt-devel libtidy libtidy-devel recode recode-devel libxpm-devel
- ./configure --prefix=/data/php7 --with-config-file-path=/data/php7/etc --enable-mbstring
- --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-exif --enable-calendar
- --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-opcache --enable-fpm
- --enable-session --enable-sockets --enable-mbregex --with-fpm-user=vagrant
- --with-fpm-group=nogroup --enable-wddx --with-curl --with-mcrypt --with-iconv
- --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr
- --enable-gd-native-ttf --enable-gd-jis-conv --with-openssl --with-pdo-mysql=mysqlnd
- --with-gettext=/usr --with-zlib=/usr --with-bz2=/usr --with-recode=/usr --with-xmlrpc
- --with-mysqli=mysqlnd
- sudo yum install -y autoconf
- ./buildconf
- make -j 4
- make test
- make install
- // 给大家一些指令
- // pkill php-fpm //杀死fpm进程
- // /data/php7/sbin/php-fpm //启动,先杀死再启动
- // vim /data/php7/etc/php.ini //php.ini文件
5- MySQL
这里我也参考了这篇博客中关于MySQL的安装,CentOS 7 下 PHP 7,MySQL 5.7 和 Nginx 1.8 的安装与配置
务必要注意的是这句修改php.ini文件,不然PHP会连不上MySQL的
- mysqli.default_socket = /var/lib / mysql / mysql.sock
6- WordPress
参考这篇文章搭建WordPress个人站点
- 需要注意的是其中一步
- 教程中是—— mv * /usr/share/nginx/html/
- 我的设置—— mv * /usr/local/nginx/html/
7- 修改Nginx配置
vim /usr/local/nginx/conf/nginx.conf,配置如下~
修改后记得要重启Nginx,ps -ef | grep nginx,ps -ef | grep fpm都要有进程才行。
- worker_processes 1;
- error_log logs / error.log;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application / octet - stream;
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 80;
- server_name localhost;
- location / {
- try_files $uri $uri / /usr/local / nginx / html / wp - admin / index.php ? p = $uri & $args;
- index index.php;
- }
- error_page 500 502 503 504 / 50x.html;
- location = /50x.html {
- root html;
- }
- location ~ \.php$ {
- root html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- }
- }
- }/
8- WordPress工作台
这个很简单,看这个WordPress使用教程就知道怎么使用了。
9- FTP
使用wordpress需要经常使用插件,而更新插件需要建立FTP连接,于是开始设置FTP。参考Linux 搭建FTP服务器,不需要了解原理的可以直接照着我这个操作。
- yum -y install vsftpd
- // 创建FTP用户
- useradd ftpusr
- usermod -s /sbin/nologin ftpusr
- passwd ftpusr
- // 在wp-config.php文件中添加脚本方式。
- vim /usr/local/nginx/html/wp-config.php
- // 添加下面三行
- define("FS_METHOD","direct");
- define("FS_CHMOD_DIR", 0777);
- define("FS_CHMOD_FILE", 0777);
- // 网页端输入
- FTP:xx.xx.xx.xx:20 (前面是你的IP地址)
- 用户:ftpusr
- 密码:ftpusr
- done!
最后,由于时间仓促,大部分时间都花在了踩坑上,还有一些小的坑大家也会碰到。大家千万别放弃,有问题谷歌一下,如果实在解决不了或者我的教程有什么错误,也可以留言,笔者水平有限,但是肯定会知无不言。