腾讯云主机安装LNMP环境及wordpress教程

2019-10-13 22:40:48王旭

许多云主机都有学生优惠,于是我趁着现在大一买了个腾讯1元云主机+免费cn域名(高中生的话就别想了)。鉴于我只知道用服务器安装博客,别的用途不了解,所以我就去安装wordpress。

而由于我看的教程有点问题,有的问题搜索引擎解决不了,我要么瞎折腾整好了,要么重装系统,最后一次挺顺利,半小时左右装好,但后续还有各种问题,一个个解决掉了。于是记录下来方便后(面要搭博客的)人。我参考的教程阿里云Centos7安装LNMP环境和wordpress(有点坑,但还是不错的)。

    LNMP=Linux+Nginx+MySQL+PHP 安装过程要选择y/n的都选y 忘记上一步输过什么可以用键盘的↑↓进行查看 句子后面的#表示注释

1.安装Nginx

#yum install nginx #配置文件处于/etc/nginx
#systemctl start nginx #启动nginx
#systemctl enable nginx.service # 设置为开机启动

测试:123.206.57.252 打开公网IP可看到nginx的页面。

2.安装MySQL

#rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
#yum repolist enabled | grep “mysql.-community.”
#yum -y install mysql-community-server #安装社区版,快可3分钟,慢或40分钟

#systemctl start mysqld # 启动mysql
#mysql_secure_installation # mysql安全安装,root密码初始为空,自己设置

#mysql -uroot -p
mysql>create database wordpress; #创建wordpress数据库
mysql>use wordpress;
mysql>quit #或者exit

3.安装PHP

3.1安装php-fpm

#yum install php-fpm php-mysql
#systemctl start php-fpm # 启动php-fpm
#systemctl enable php-fpm # 设置开机启动

#mkdir /usr/www
#chown -R apache:apache /usr/www

3.2在Winscp登录主机

winscp菜单-选项-编辑器-默认编码,选择UTF-8。
设置好ssh:高级-ssh-验证-密钥文件。
密码是云主机的密码,修改密码要先关机。

3.3修改Nginx配置文件

打开/etc/nginx下的nginx.conf,其中server部分修改如下:

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  ffflipped.cn;
    root         /usr/www;
  
    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;
  
    location / {
        index index.php;
        try_files $uri $uri/ /index.php?$args;
    }
  
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;
  
    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;
    }
  
    location ~ .php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+.php)(/.+)$;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
  
}