nginx+php7+mysql 搭建wordpress

nginx+php7+mysql 搭建wordpress

下载链接

https://wordpress.org/download/releases/  

安装编译所需的环境

yum -y install gcc gcc-c++ cmake openssl-devel pcre-devel wget		

下载链接

wget http://nginx.org/download/nginx-1.18.0.tar.gz

解压 nginx-1.18.0.tar.gz 到/usr/local/src/

tar xvf nginx-1.18.0.tar.gz -C /usr/local/src/

进入nginx-1.18.0

cd /usr/local/src/nginx-1.18.0

增加以下内容:

./configure --prefix=/usr/local/nginx --with-pcre --user=daemon --group=daemon --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module

编译:

make -j8 && make install 

建立软连接(快捷方式)

ln -s /usr/local/nginx/sbin/nginx /usr/sbin/

语法测试

[root@abc nginx-1.18.0]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
nginx  启动nginx

nginx -s reload 重置

cd /usr/local/nginx/conf/ng

-查看80端口当时是被谁监听


[root@abc nginx]# lsof -i:80
COMMAND  PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   8673   root    6u  IPv4  30064      0t0  TCP *:http (LISTEN)
nginx   8718 daemon    6u  IPv4  30064      0t0  TCP *:http (LISTEN)
nginx   8719 daemon    6u  IPv4  30064      0t0  TCP *:http (LISTEN)

防火墙放行80端口

[root@abc nginx]# firewall-cmd --permanent --add-port=80/tcp
success
[root@abc nginx]# firewall-cmd --reload 
success

日志目录

/usr/local/nginx/logs

#################################################################################

php安装

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

清空缓存

[root@abc nginx]# yum clean all
已加载插件:fastestmirror
正在清理软件源: base epel extras remi-safe updates
Cleaning up list of fastest mirrors

安装php74

yum install php74 php74-php-fpm php74-php-gd php74-php-json php74-php-mbstring php74-php-mysqlnd php74-php-xml php74-php-xmlrpc php74-php-opcache php74-php-devel -y

nginx+php74配置

[root@abc nginx]# egrep -v "#|^$" conf/nginx.conf
user  daemon;
worker_processes  2;
error_log  logs/error.log  info;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page  404              /404.html;
        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;
        }
    }

启动php74

[root@abc nginx]# systemctl start php74-php-fpm.service 

查看启动php74 是否成功

[root@abc nginx]# systemctl status php74-php-fpm.servic
● php74-php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php74-php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since 六 2020-06-06 18:07:40 CST; 3s ago
 Main PID: 9078 (php-fpm)
   Status: "Ready to handle connections"
   CGroup: /system.slice/php74-php-fpm.service
           ├─9078 php-fpm: master process (/etc/opt/remi/php74/php-fpm.conf)
           ├─9079 php-fpm: pool www
           ├─9080 php-fpm: pool www
           ├─9081 php-fpm: pool www
           ├─9082 php-fpm: pool www
           └─9083 php-fpm: pool www

6月 06 18:07:40 abc.com systemd[1]: Starting The PHP FastCGI Process Manager...
6月 06 18:07:40 abc.com systemd[1]: Started The PHP FastCGI Process Manager.

测试
我们可以通过下面的方法判断Nginx配置是否成功。
在Nginx的网站根目录(/var/www/)下创建一个php文件,随便起名我的是php_info.php

内容如下:

<?php

    // 顺便可以看一下php的扩展全不全
    phpinfo();
    ?>

访问

http://2.1.1.121/index.php

显示以下为成功
在这里插入图片描述
#################################################################################

安装mariadb(mysql)数据库

yum install mariadb mariadb-server mariadb-devel -y

开启mysql

[root@abc nginx]# systemctl start mariadb.service  

查看MySQL是否开启成功

[root@abc nginx]# systemctl status mariadb.service  
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since 六 2020-06-06 18:16:20 CST; 6s ago
  Process: 9620 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 9534 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 9618 (mysqld_safe)

设置开机重启

[root@abc nginx]# systemctl enable mariadb.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/maria

安装完mysql-server 会提示可以运行mysql_secure_installation。运行mysql_secure_installation会执行几个设置:

--为root用户设置密码
--删除匿名账号
--取消root用户远程登录
--删除test库和对test库的访问权限
--刷新授权表使修改生效

通过这几项的设置能够提高mysql库的安全。
建议生产环境中mysql安装这完成后一定要运行一次mysql_secure_installation,相关操作如下:

[root@abc nginx]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

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 authorisation.

Set root password? [Y/n] y  #是否设置root用户密码,输入y并回车或直接回车
New password:    <<<-----设置root密码
Re-enter new password:  <<<-----确认密码
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y #是否删除匿名用户,生产环境建议删除
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y #是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y  #是否删除test数据库,直接回车
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y #是否重新加载权限表,直接回车
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

登录mysql

[root@abc nginx]# mysql -uroot -p123qwe
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.65-MariaDB MariaDB Server

创建库

MariaDB [(none)]> create database word default charset utf8;
Query OK, 1 row affected (0.00 sec)

授权库和用户

MariaDB [(none)]> grant all on word.* to user_0@'localhost' identified by '1230123';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>grant all on word.* to user_0@'127.0.0.1' identified by '1230123;
Query OK, 0 rows affected (0.00 sec)

刷新生效

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

查看库

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| word               |
+--------------------+
4 rows in set (0.00 sec)

#################################################################################

进入wordpress官网下载

https://wordpress.org/download/

wget  https://wordpress.org/wordpress-5.4.1.tar.gz

解压

tar xvf wordpress-5.4.1.tar.gz

创建新目录

mkdir /data/abc/ -p

拷贝wordpress到 /data/abc/

cp -a wordpress/* /data/abc/

给/data/abc/授权用户组的权限

chown -R daemon:daemon /data/abc/

word博客完整配置

[root@abc abc]# egrep -v "#|^$" /usr/local/nginx/conf/nginx.conf
user  daemon;
worker_processes  2;
error_log  logs/error.log  info;
pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    gzip  on;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /data/abc;  <<<---网站目录
            index  index.php index.html index.htm;
        }
        error_page  404              /404.html;
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        location ~ \.php$ {
            root           /data/abc;  <<<---网站目录
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

配置完之后,访问 http://2.1.1.120 登录到WordPress

输入数据库创建的用户名 密码在这里插入图片描述

安装过程如需要添加内容,去/data/abc/下创建wp-config.php 文件
vim wp-config.php 添加一下内容

<?php
/**
* The base configuration for WordPress
*
* The wp-config.php creation script uses this file during the
* installation. You don't have to use the web site, you can
* copy this file to "wp-config.php" and fill in the values.
*
* This file contains the following configurations:
*
* * MySQL settings
* * Secret keys
* * Database table prefix
* * ABSPATH
*
* @link https://wordpress.org/support/article/editing-wp-config-php/
*
* @package WordPress
*/

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'word' );

/** MySQL database username */
define( 'DB_USER', 'user_0' );

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

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**#@+
* Authentication Unique Keys and Salts.
*
* Change these to different unique phrases!
* You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
* You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
*
* @since 2.6.0
*/
define( 'AUTH_KEY',         '.(=N{0qG8H~B~7SKFxMRJjT:c {)dWvVST#,->.Wk@?ofx-M]iCO.~K)SSXEj$D<' );
define( 'SECURE_AUTH_KEY',  'UVTt`8dOkilQltwX6l*=f$?<EWe:l4v]~6ozA_4qwE`to bPXDT`|?81M pCrA&(' );
define( 'LOGGED_IN_KEY',    'I$}o~mj:co` 2;z{_9dJjJIG)t)G#w1nTYD0Kp%H)i/*(lj77DSKyUja&,1j9d[v' );
define( 'NONCE_KEY',        'RhV**=0:Hsf7$ny[W.w^U>+R151nlf1IZ;vbra,-v&&H-#H2r<JZpy|{EX=n h]S' );
define( 'AUTH_SALT',        'K;ut:0?[(HH`~4pp?2@^}UWs3mVBuX&]wJM5#PE?NIqA<~dmL+6y]:dyN)<YQj:[' );
define( 'SECURE_AUTH_SALT', ']Tb2Pn(fC,bt,*Ug!P8Ub:;G%>ZA&L3eK$BO|m/Qapck8ILJgM,`7*WbPj`{c|5B' );
define( 'LOGGED_IN_SALT',   'kkU.>3tpoyU /@y0P:j/4g3xH$Um.7O}x`G_LS4!jE$RjK*_g8a,kim$ O6 `ZL5' );
define( 'NONCE_SALT',       ']4o :EJJD#:^D6]{L(oNcLb}zctw`ft8I[<5wd&{T[W@0tU-Ev?(C]{0<,@|vYnb' );

/**#@-*/

/**
* WordPress Database Table prefix.
*
* You can have multiple installations in one database if you give each
* a unique prefix. Only numbers, letters, and underscores please!
*/
$table_prefix = 'js';

/**
* For developers: WordPress debugging mode.
*
* Change this to true to enable the display of notices during development.
* It is strongly recommended that plugin and theme developers use WP_DEBUG
* in their development environments.
*
* For information on other constants that can be used for debugging,
* visit the documentation.
*
* @link https://wordpress.org/support/article/debugging-in-wordpress/
*/
define( 'WP_DEBUG', false );

/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
   define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

安装完毕后直接登录即可

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值