一、使用网络YUM源手动搭建LNMP环境

1.配置基本环境

配置yum源
关闭防火墙(setenforce、seliunx、firewalld)
mount /dev/sr0 /opt/centos

2.安装Nginx

在 /etc/yum.repos.d/ 下创建 nginx.repo 文件

  1. vi /etc/yum.repos.d/nginx.repo

按i切换至编辑模式,输入以下内容

  1. [nginx]
  2. name = nginx repo
  3. baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/
  4. gpgcheck = 0
  5. enabled = 1

Esc退出编辑模式,:wq保存退出
安装nginx

  1. yum install -y nginx

打开 default.conf文件

  1. vi /etc/nginx/conf.d/default.conf

按i切换至编辑模式,编辑default.conf文件
找到server{……},并将server大括号中相应的配置信息配置成以下内容

  1. server {
  2. listen 80;
  3. root /usr/share/nginx/html;
  4. server_name localhost;
  5. #charset koi8-r;
  6. #access_log /var/log/nginx/log/host.access.log main;
  7. #
  8. location / {
  9. index index.php index.html index.htm;
  10. }
  11. #error_page 404 /404.html;
  12. #redirect server error pages to the static page /50x.html
  13. #
  14. error_page 500 502 503 504 /50x.html;
  15. location = /50x.html {
  16. root /usr/share/nginx/html;
  17. }
  18. #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  19. #
  20. location ~ .php$ {
  21. fastcgi_pass 127.0.0.1:9000;
  22. fastcgi_index index.php;
  23. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  24. include fastcgi_params;
  25. }
  26. }

Esc退出编辑模式,:wq保存退出
启动Nginx

  1. systemctl start nginx

设置Nginx为开机自启

  1. systemctl enable nginx

在浏览器访问虚拟机IP,查看Nginx服务是否正常运行
显示如下说明Nginx服务配置成功
image.png

3.安装数据库

查看系统中是否已安装Mariadb

  1. rpm -qa | grep -i mariadb

如反馈类似以下内容,则表明已存在Mariadb
image.png
移除已经安装的Mariadb

  1. yum -y remove 包名

如未反馈任何东西,说明未安装Mariadb,进行下一步
在 /etc/yum.repos.d/ 下创建 MariaDB.repo 文件

  1. vi /etc/yum.repos.d/MariaDB.repo

按i切换至编辑模式,写入以下内容,添加Mariadb软件库

  1. [mariadb]
  2. name = MariaDB
  3. baseurl = https://mirrors.cloud.tencent.com/mariadb/yum/10.4/centos7-amd64
  4. gpgkey=https://mirrors.cloud.tencent.com/mariadb/yum/RPM-GPG-KEY-MariaDB
  5. gpgcheck=1

Esc退出编辑模式,:wq保存退出
使用以下命令安装Mariadb

  1. yum -y install MariaDB-client MariaDB-server

启动Mariadb服务

  1. systemctl start mariadb

设置Mariadb为开机自启

  1. systemctl enable mariadb

检查Mariadb是否安装成功

  1. mysql

显示如下结果,则安装成功
image.png
Ctrl+c退出Mariadb

4.安装PHP

更新yum中PHP的软件源

  1. rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
  1. rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装PHP7.2所需要的包,这一步等待时间较长

  1. yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64

启动PHP服务

  1. systemctl start php-fpm

设置PHP服务为开机自启

  1. systemctl enable php-fpm

创建一个供PHP安装测试的文件

  1. echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php

重启Nginx

  1. systemctl restart nginx

访问虚拟机IP,查看环境配置是否成功
此时页面可能为以下
image.png
进入/usr/share/nginx/html目录

  1. cd /usr/share/nginx/html

删除两个网址后刷新,显示结果如下,说明配置环境成功
image.png

二、手动搭建Wordpress个人站点

在mysql服务器内创建一个名为wordpress的数据库并授权

  1. [root@xserver1 ~]# mysql -uroot -p000000
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MariaDB connection id is 4
  4. Server version: 5.5.44-MariaDB-log MariaDB Server
  5. Copyright (c) 2000, 2015, Oracle, MariaDB Corporation Ab and others.
  6. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  7. MariaDB [(none)]> create database wordpress;
  8. Query OK, 1 row affected (0.00 sec)
  9. MariaDB [(none)]> grant all privileges on *.* to "wordpress"@"localhost" identified by '000000';
  10. Query OK, 0 rows affected (0.00 sec)
  11. MariaDB [(none)]> flush privileges;
  12. Query OK, 0 rows affected (0.00 sec)

重启mysql服务

  1. systemctl restart mariadb

删除nginx的默认文件

  1. rm -rf /usr/share/nginx/html/*

上传解压wordpress安装包

  1. [root@xserver1 ~]# yum install -y unzip
  2. [root@xserver1 ~]# unzip wordpress-4.7.3-zh_CN.zip

部署wordpress服务

  1. [root@xserver1 ~]# cp -rf wordpress/* /usr/share/nginx/html/
  2. [root@xserver1 ~]# cd !$
  3. cd /usr/share/nginx/html/
  4. [root@xserver1 html]# ls
  5. index.php wp-blog-header.php wp-includes wp-settings.php
  6. license.txt wp-comments-post.php wp-links-opml.php wp-signup.php
  7. readme.html wp-config-sample.php wp-load.php wp-trackback.php
  8. wp-activate.php wp-content wp-login.php xmlrpc.php
  9. wp-admin wp-cron.php wp-mail.php

复制一个配置文件,根据mysql授权填写配置文件

  1. [root@xserver1 html]# cp wp-config-sample.php wp-config.php
  2. [root@xserver1 html]# vim wp-config.php
  3. 21 // ** MySQL
  4. 22 /** WordPress
  5. 23 define('DB_NAME', 'wordpress');
  6. 24
  7. 25 /** MySQL数据库用户名 */
  8. 26 define('DB_USER', 'wordpress');
  9. 27
  10. 28 /** MySQL数据库密码 */
  11. 29 define('DB_PASSWORD', '000000');
  12. 30
  13. 31 /** MySQL主机 */
  14. 32 define('DB_HOST', 'localhost');
  15. 33
  16. 34 /** 创建数据表时默认的文字编码 */
  17. 35 define('DB_CHARSET', 'utf8');

给予所有文件权限

  1. chmod -R 777 /usr/share/nginx/html/

查看端口是否启用,没有该命令需要安装

  1. [root@xserver1 html]#yum -y install net-tools
  2. [root@xserver1 html]#netstat -ntlp
  3. Active Internet connections (only servers)
  4. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  5. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4238/php-fpm: maste
  6. tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4460/mysqld
  7. tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 3118/smbd
  8. tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2739/rpcbind
  9. tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4236/nginx: master
  10. tcp 0 0 0.0.0.0:20048 0.0.0.0:* LISTEN 2754/rpc.mountd
  11. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1112/sshd
  12. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1605/master
  13. tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 3118/smbd
  14. tcp 0 0 0.0.0.0:45758 0.0.0.0:* LISTEN -
  15. tcp 0 0 0.0.0.0:2049 0.0.0.0:* LISTEN -
  16. tcp 0 0 0.0.0.0:52550 0.0.0.0:* LISTEN 2730/rpc.statd
  17. tcp6 0 0 :::139 :::* LISTEN 3118/smbd
  18. tcp6 0 0 :::111 :::* LISTEN 2739/rpcbind
  19. tcp6 0 0 :::20048 :::* LISTEN 2754/rpc.mountd
  20. tcp6 0 0 :::21 :::* LISTEN 2640/vsftpd
  21. tcp6 0 0 :::22 :::* LISTEN 1112/sshd
  22. tcp6 0 0 ::1:25 :::* LISTEN 1605/master
  23. tcp6 0 0 :::56316 :::* LISTEN -
  24. tcp6 0 0 :::445 :::* LISTEN 3118/smbd
  25. tcp6 0 0 :::2049 :::* LISTEN -
  26. tcp6 0 0 :::43140 :::* LISTEN 2730/rpc.statd

浏览器访问虚拟机IP,结果如下则说明配置成功
image.png