①Linux,操作系统
②Nginx,网页服务器
③MariaDB或MySQL,数据库管理系统(或者数据库服务器)
④PHP、Perl或Python,脚本语言
配置nginx源
[root@localhost ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装nginx
[root@localhost share]# yum install nginx -y
[root@localhost ~]# nginx -v
nginx version: nginx/1.16.1
[root@localhost /]# systemctl enable nginx
[root@localhost /]# systemctl start nginx
(注) 文件默认位置:
二进制文件 /usr/sbin/nginx
配置文件夹 /etc/nginx/
log文件夹 /var/log/nginx
[root@localhost ~]# yum install mariadb-server
[root@localhost /]# systemctl enable mariadb
[root@localhost /]# systemctl start mariadb
初始化数据库
[root@localhost /]# 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用户密码
New password: #输入密码
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] #删除匿名用户
... 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] #禁止远程root登录
... 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] #是否删除测试数据库
- 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] #是否重载特权表
... 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!
#增加SCL源
yum install -y centos-release-scl
#安装PHP7.2
yum install -y rh-php72 \
rh-php72-php \
rh-php72-php-bcmath \
rh-php72-php-fpm \
rh-php72-php-gd \
rh-php72-php-intl \
rh-php72-php-mbstring \
rh-php72-php-mysqlnd \
rh-php72-php-opcache \
rh-php72-php-pdo \
rh-php72-php-pecl-apcu \
rh-php72-php-xmlrpc \
rh-php72-php-devel
进入 rh-php72 环境
scl enable rh-php72 bash
查看版本
[root@localhost ~]# php -v
PHP 7.2.24 (cli) (built: Nov 4 2019 10:23:08) ( NTS )
Copyright © 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright © 1998-2018 Zend Technologies
with Zend OPcache v7.2.24, Copyright © 1999-2018, by Zend Technologies
增加开机启动
systemctl enable rh-php72-php-fpm
启动 PHP-FPM 服务
systemctl start rh-php72-php-fpm
查看 PHP-FPM 服务状态
[root@localhost ~]# systemctl status rh-php72-php-fpm
● rh-php72-php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/rh-php72-php-fpm.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2020-04-20 18:43:42 CST; 6min ago
Main PID: 42967 (php-fpm)
Status: “Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec”
CGroup: /system.slice/rh-php72-php-fpm.service
├─42967 php-fpm: master process (/etc/opt/rh/rh-php72/php-fpm.conf)
├─42968 php-fpm: pool www
├─42969 php-fpm: pool www
├─42970 php-fpm: pool www
├─42971 php-fpm: pool www
└─42972 php-fpm: pool www
Apr 20 18:43:42 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager…
Apr 20 18:43:42 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager.
以上我们就安装好了基础环境,接下来我们对其进行配置
#登录Mariadb数据库
mysql -u root -p
#创建数据库
create database wordpress;
#允许用户 user_name 从ip为 localhost 的主机连接到 database_name 数据库,并使用 password 作为密码
grant all privileges on database_name.* to user_name@‘localhost’ identified by ‘password’;
#刷新数据库系统权限相关表
flush privileges;
#退出数据库
exit
vim /etc/nginx/conf.d/default.conf
###############################################
需要把'#'去掉,取消注释,详细对照文本
server {
listen 80;
server_name localhost; #你的域名或者公网IP
root /usr/share/nginx/html/wordpress; #你的站点的目录
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html/wordpress;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html/wordpress;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
#下载wordpress安装包
tar zxvf latest-zh_CN.tar.gz
#解压缩
cd wordpress/
#进入到wordpress目录
cp wp-config-sample.php wp-config.php
#复制wp-config-sample.php并重命名为wp-config.php
vim wp-config.php
#编辑该文件
找到mysql设置的配置部分,按i进入编辑模式,填入之前创建的数据库及用户密码
// ** 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’, ‘root’); # 数据库用户名
/* MySQL database password /
define(‘DB_PASSWORD’, ‘123456’); # 数据库密码
/* MySQL hostname */
define(‘DB_HOST’, ‘localhost’); # 一般不修改
输入完成后,按ESC进入命令模式,输入:wq,回车保存并退出
若该文件不在你的站点目录下需要将其移动到你的站点目录
cp wordpress /你的站点目录
rm /usr/share/nginx/html/index.html # 删除nginx中的主页文件
完成后,在浏览器中输入 http://你的主机IP或者域名/wp-admin/install.php
,进入到wordpress的配置页面,输入网站标题,用户名和密码后,就可以进入wordpress后台管理界面,到此便大功告成。