基础介绍,腾讯云1核1G1M主机,系统Ubuntu16.04 LTS

安装Nginx

sudo apt-get install nginx

安装Nginx,nginx -v可以查看安装的版本。

sudo server nginx start
sudo /etc/init.d/nginx start

通过上面两条指令(任选一条)重启 Nginx。这个时候在你的浏览器里面输入的服务器的外网IP就可以看见 Welcome to Nginx了。这一步OK,下面继续。

如果不OK请检查问题:

  1. nginx是否正确安装
  2. 端口是否开放(防火墙,或者安全策略等一些列东西,例如阿里云要在控制台添加安全规则,不然是出不来的)

安装PHP7.1

sudo apt-add-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.1 php7.1-fpm

先添加一个ppa的库,因为默认软件列表里面没有PHP7.1,然后再更新一个软件列表,接下来就可以安装PHP7.1了。

php -v查看PHP版本。

接下来修改Nginx配置文件测试PHP是否OK。Nginx的配置文件路径为/etc/nginx/sites-available

进入目录后,建议先备份再进行修改。

sudo cp default default.back
sudo vi default

配置文件为:

server {
listen 80 default_server;
listen [::]:80 default_server;


root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name blog.yelvlab.cn;

if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .*\.php(\/.*)*$ {
    fastcgi_index     index.php; 
fastcgi_pass      unix:/run/php/php7.1-fpm.sock; 
include           fastcgi_params; 
fastcgi_param     SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param     SCRIPT_NAME        $fastcgi_script_name;
}
}

nginx-t可以验证配置文件正确性。

然后进入网站默认路径/var/www/html添加测试界面。

sudo vi info.php

里面内容为:

<?php  
phpinfo();  
?>  

在浏览器输入IP Address/info.php就能看到PHP的信息了。

安装MySQL

sudo apt-get –y install mysql-server mysql-client php7.1-mysql

安装phpmyadmin

因为不会操作MySQL,所以顺手装一个phpmyadmin图形化操作。

sudo apt-get install phpmyadmin

安装完成之后

sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin

如果这个时候The mbstring extension is missing. Please check your PHP configuration.错误,那么安装

sudo apt-get install php7.1-mbstring

重启服务,刷新页面即可。

安装Typecho

sudo wget http://typecho.org/downloads/1.1-17.10.30-release.tar.gz
sudo tar -xzvf 1.1-17.10.30-release.tar.gz

接下来访问页面就可以了。

BUG记录:

  • 安装typecho后,登录,内页全为404

修改Nginx的配置文件(全局或者vhost)添加,如下配置:

    if (!-e $request_filename) {
        rewrite ^(.*)$ /index.php$1 last;
    }

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .*\.php(\/.*)*$ {
    fastcgi_index     index.php; 
    fastcgi_pass      unix:/run/php/php7.1-fpm.sock; 
include           fastcgi_params; 
fastcgi_param     SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param     SCRIPT_NAME        $fastcgi_script_name;
}

注意location一行location ~ .*\.php(\/.*)*$还有fastcgi_pass一行根据自己安装的PHP版本填写php7.1-fpm.sock


  • phpmyadmin提示缺少mbstring组件

安装组件,重启web服务。

sudo apt-get install php7.1-mbstring

根据版本安装组件,一定要写版本,不然会提示已经安装,但是还会出现错误。


  • wordpress to typecho相关问题

  1. 在原博客后台的phpmyadmin中直接导出XML格式或者SQL格式的数据库文件,出现问题,下载的是html文件,在高级设置里面启用压缩然后再导出。
  2. 在新数据库里面导入数据出现问题,择更换另外一种数据格式尝试。
  3. wordpress to typecho进行转换,需要在本地数据库进行。

4.wordpress to typecho转换后的帖子,查看效果OK,但是编辑体验极差。


  • 数据转换后内页或者其他页面显示404

在后台设置里面开启地址重写,因为之前配置里面写好了,提示有问题,只需要强制开启就OK。

最后再说一句,HTTPS访问的方式可以暂时先不用备案,我是因为备案过程出了很多问题,所以备案可能要拖延,然后就。。。

下面我附上我最新的配置文件的代码,只提供思路,具体根据实际情况自行修改:

# Port 80 Config   Redirect port 80 to 443
server {
    listen 80;
    server_name domain.cn;
    rewrite ^(.*) https://$server_name$1 permanent;
}

# Port 443 Config
server {
    # Server_name Config
    server_name domain.cn;

    # Enable HTTP/2.0
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;

    # SSL Config
    ssl_certificate /home/user/1_domain.cn_bundle.crt;
    ssl_certificate_key /home/user/2_domain.cn.key;
    ssl_prefer_server_ciphers on;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;

    # Website directory
    root /var/nginx/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    # Config URL rewrite
    if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php$1 last;
        }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    # pass the PHP scripts to FastCGI server listening on /run/php/php7.0-fpm.sock
    location ~ .*\.php(\/.*)*$ {
    fastcgi_index     index.php; 
    fastcgi_pass      unix:/run/php/php7.1-fpm.sock; 
    include           fastcgi_params; 
    fastcgi_param     SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param     SCRIPT_NAME        $fastcgi_script_name;
    }
}
最后修改:2018 年 03 月 15 日
如果觉得我的文章对你有用,请随意赞赏