创建CentOS 7 VM& Update

sudo -i

yum update -y
yum安装epel-release yum-utils -y
百胜清洁安装

Install Nginx

百胜安装nginx -y
服务nginx启动
*浏览器可访问VM的公共IP 
sudo systemctl启用nginx
sudo systemctl启动nginx

安装MariaDB

yum安装mariadb-server -y
服务mariadb启动
mysql_secure_installation

MariaDB会要求您提供root密码,但是,由于这是初始安装,因此您没有任何密码,因此只需按Enter。下一个提示符将询问您是否要设置root密码,输入Y并按照说明进行操作:

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorization.

New password: password
Re-enter new password: password
Password updated successfully!
Reloading privilege tables..
 ... Success!

您可以安全地单击ENTER键,并接受所有其他问题的默认设置。完成安装后,继续进行PHP安装。

创建WordPress数据库

mysql -u root -p
CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
exit

Install PHP7.2

sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm


rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
须藤yum install yum-utils -y

sudo yum-config-manager –启用remi-php72
须藤百胜安装php-cli php-fpm php-mysql php-json php-opcache php-mbstring php-xml php-gd php-curl
Configure PHP 7 通过修改php的配置文件。确保取消评论&将; cgi.fix_pathinfo = 1更改为cgi.fix_pathinfo = 0。
# vi /etc/php.ini
cgi.fix_pathinfo=0
Open php-fpm 配置文件和 modify 行如下。
# vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx

listen = /var/run/php-fpm/php-fpm.sock
 
listen.owner = nginx
listen.group = nginx

服务php-fpm重新启动

sudo systemctl启用php-fpm
sudo systemctl启动php-fpm

回声“<?php phpinfo(); ?>” > phpversion.php

注意:PHP 7.1安装  – verified:

PHP7.3安装(未验证):

#先把php版本升级为7
百胜安装php73-php-fpm php73-php-mysql

#安装nginx和mysql

# 启动PHP-FPM 

systemctl启动php73-php-fpm 
# 开机启动 
systemctl启用php73-php-fpm 
# 启动mysql 
systemctl启动mysqld

# 回车输入密码即可
mysql -u root -p
#创建名字为wordpress的数据库
创建数据库wordpress;

#创建数据库用户,用户名wordpress,密码[电子邮件 protected]
将wp。*上的所有权限授予“ wordpress” @@%[电子邮件 protected]’;

# 刷新授权
同花顺特权;

#下载最新版本的wordpress
#目录为/ opt / application
wget //cn.wordpress.org/latest-zh_CN.tar.gz
tar -xvf Latest-zh_CN.tar.gz

# 用模板复制修改配置文件
cp wp-config-sample.php wp-config.php
#修改wp-config.php为如下
// ** MySQL设置–具体信息来自您正在使用的主机** //
/ ** WordPress数据库的名称* /
define('DB_NAME','wordpress');
/ ** MySQL数据库用户名* /
define('DB_USER','wordpress');
/ ** MySQL数据库密码* /
定义(“ DB_PASSWORD”,“[电子邮件 protected]’ );
/ ** MySQL主机* /
define('DB_HOST','localhost');
/ **创建数据表时默认的文字编码* /
define('DB_CHARSET','utf8');
/ **数据库整理类型。如不确定无法更改* /
define('DB_COLLATE','');

#配置文件默认在/usr/local/nginx/conf/nginx.conf

server {
  # 监听的端口
  listen 80;
  # 域名
 server_name www.javashitang.com;
 index index.html index.php;
  # 访问日志目录
 access_log /var/log/nginx/blog_access.log main;
  # 网站根目录
 根/ opt / application / wordpress;

  location / {
    root /data/www;
  }

  location ~ \.php$ {
  # 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 

Php7.2

在/ etc / nginx / sites-available文件夹下创建一个名为wordpress的新配置文件

sudo nano /etc/nginx/sites-available/wordpress



然后将下面的内容复制并粘贴到文件中并保存。更换 example.com 用您自己的域名。在切换到域之前,您可能还希望将wordpress网站的公共IP添加到服务器名称列表中以进行测试。

server {
   listen 80;
    listen [::]:80;
    root /var/www/html/wordpress;
    index  index.php index.html index.htm;
    server_name  54.32.104.91 51sec.org www.51sec.org;

     client_max_body_size 100M;

   location / {
        try_files $uri $uri/ /index.php?$args;        
    }

   位置〜\ .php $ {
   包括 snippets/fastcgi-php.conf;
   fastcgi_pass             unix:/var/run/php/php7.2-fpm.sock;
   fastcgi_param  SCRIPT_FILENAME$ document_root $ fastcgi_script_name;
    }
}

Php7.1

须藤vi /etc/nginx/conf.d/wordpress.conf

server {
    listen   80;
    server_name  140.238.157.42 www.51sec.org 51sec.org;

    # note that these lines are originally from the "location /" block
    root   /var/www/html/wordpress;
    index index.php index.html index.htm;

   location / {
        try_files $uri $uri/ /index.php?$args;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

   位置〜\ .php $ {
        try_files $uri =404;
       fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME$ document_root $ fastcgi_script_name;
       包括 fastcgi_params;
    }
}

安装WordPress

百胜安装wget
cd /tmp && wget //wordpress.org/latest.tar.gz
tar -zxvf Latest.tar.gz

须藤MV wordpress / var / www / html / wordpress

须藤chown -R nginx:/ var / www / html / wordpress
须藤chmod -R 755 / var / www / html / wordpress /
须藤MV /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

配置WordPress

更改配置以连接到本地新的MariaDB服务器:

sudo nano /var/www/html/wordpress/wp-config.php


// ** 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', 'wordpressuser');

/** MySQL database password */
define('DB_PASSWORD', 'password1234');

/** 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', '');

References

By johnyan

Leave a Reply