一、lnmp项目简介

Nginx:是由俄罗斯人开发的一款开源的高性能的HTTP和反向代理的Web服务器同时也提供了IMAP(交互邮件访问协议)/POP3(邮局协议版本3)/SMTP(电子邮件传输协议)服务。它的特点是占有内存少,并发能力强,在同类型的网页服务器中表现得尤其出色,目前中国大陆使用Nginx网站的用户有:百度、新浪、京东等企业。C语言编写。
MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,属于Oracle旗下产品。MySQL 是最流行的关系型数据库管理系统之一,MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。其特点是体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL 作为网站数据库。MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。
PHP—“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法学习了C语言,吸纳JavaPerl多个语言的特色发展出自己的特色语法。
这4种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。

二、wordpress简介

WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。全球约34%的网站都在用WordPress、小到兴趣博客、大到新闻网站,国外的学校里甚至都有WordPress相关的课程。

三、构建lnmp+wordpress

上传lnmp+wordpress包到根目录下

  1. hostnamectl set-hostname lnmp //修改主机名
  2. bash
  3. [root@lnmp html]# hostnamectl //查看主机名
  4. Static hostname: lnmp
  5. Icon name: computer-vm
  6. Chassis: vm
  7. Machine ID: 8e678fb0617d400a991be932f99bace0
  8. Boot ID: 7fce301a22cb488291cabbd35d426c32
  9. Virtualization: vmware
  10. Operating System: CentOS Linux 7 (Core)
  11. CPE OS Name: cpe:/o:centos:centos:7
  12. Kernel: Linux 3.10.0-862.el7.x86_64
  13. Architecture: x86-64

配置yum 源

  1. [root@lnmp html]# cat /etc/yum.repos.d/local.repo
  2. [centos]
  3. name=centos
  4. baseurl=file:///opt/centos
  5. gpgcheck=0
  6. enabled=1
  7. [lnmp]
  8. name=lnmp
  9. baseurl=file:///root/lnmp
  10. gpgcheck=0
  11. enabled=1
  12. [root@lnmp html]#
  13. [root@lnmp html]# yum clean all
  14. Loaded plugins: fastestmirror
  15. Cleaning repos: centos lnmp
  16. Cleaning up everything
  17. Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
  18. Cleaning up list of fastest mirrors
  19. [root@lnmp html]# yum repolist
  20. Loaded plugins: fastestmirror
  21. Determining fastest mirrors
  22. centos | 3.6 kB 00:00
  23. lnmp | 3.0 kB 00:00
  24. (1/3): centos/primary_db | 3.1 MB 00:00
  25. (2/3): centos/group_gz | 166 kB 00:00
  26. (3/3): lnmp/primary_db | 153 kB 00:00
  27. repo id repo name status
  28. centos centos 3,971
  29. lnmp lnmp 178
  30. repolist: 4,149
  31. [root@lnmp html]#

安装工具

  1. [root@lnmp html]# yum -y install nginx mariadb-server mariadb php-fpm php-mysql

nginx

  1. [root@lnmp ~]# systemctl start nginx && systemctl enable nginx //启动服务
  2. [root@lnmp ~]# vi /etc/nginx/conf.d/default.conf
  3. server {
  4. listen 80;
  5. server_name localhost;
  6. #charset koi8-r;
  7. #access_log /var/log/nginx/host.access.log main;
  8. location / {
  9. root /usr/share/nginx/html;
  10. index index.html index.htm;
  11. }
  12. location ~ \.php$ {
  13. root /usr/share/nginx/html;
  14. server {
  15. listen 80;
  16. server_name localhost;
  17. #charset koi8-r;
  18. #access_log /var/log/nginx/host.access.log main;
  19. location / {
  20. root /usr/share/nginx/html;
  21. index index.php index.html index.htm;
  22. }
  23. location ~ \.php$ {
  24. root /usr/share/nginx/html;
  25. fastcgi_pass 127.0.0.1:9000;
  26. fastcgi_index index.php;
  27. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  28. include fastcgi_params;
  29. }
  30. #error_page 404 /404.html;
  31. # redirect server error pages to the static page /50x.html
  32. #
  33. error_page 500 502 503 504 /50x.html;
  34. location = /50x.html {
  35. root /usr/share/nginx/html;
  36. }
  37. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  38. #
  39. #location ~ \.php$ {
  40. # proxy_pass http://127.0.0.1;
  41. #}
  42. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  43. #
  44. #location ~ \.php$ {
  45. # root html;
  46. # fastcgi_pass 127.0.0.1:9000;
  47. [root@lnmp ~]# systemctl restart nginx //重启服务

mysql

  1. [root@lnmp ~]# systemctl start mariadb && systemctl enable mariadb //启动服务
  2. [root@lnmp ~]# mysql_secure_installation //初始化数据库
  3. yynyy
  4. [root@lnmp ~]# mysql -uroot -p123456 //登录数据库
  5. Welcome to the MariaDB monitor. Commands end with ; or \g.
  6. Your MariaDB connection id is 35
  7. Server version: 5.5.56-MariaDB MariaDB Server
  8. Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
  9. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  10. MariaDB [(none)]>
  11. MariaDB [(none)]> create database wordpress; //创建数据库服务
  12. MariaDB [(none)]> grant all privileges on *.* to root@localhost identified by '123456' with grant option; //授权所有用户拥有本地数据库的所有权限。
  13. MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '123456' with grant option; //授权用户可进行远程登录
  14. MariaDB [(none)]> exit
  15. Bye
  16. [root@lnmp ~]#

php

  1. [root@lnmp ~]# vi /etc/php-fpm.d/www.conf
  2. 输入set nu 显示行号
  3. 39 user = nginx
  4. 40 ; RPM: Keep a group allowed to write in log dir.
  5. 41 group = nginx
  6. 修改39行和41
  7. [root@lnmp ~]# systemctl start php-fpm && systemctl enable php-fpm //重启服务并设置开机自启

wordpress

  1. [root@lnmp ~]# unzip wordpress-4.7.3-zh_CN.zip
  2. [root@lnmp ~]# cd /usr/share/nginx/html
  3. [root@lnmp html]#
  4. [root@lnmp html]# rm -rf *
  5. [root@lnmp html]# cp -rvf /root/wordpress/* ./
  6. [root@lnmp html]# cp wp-config-sample.php wp-config.php
  7. [root@lnmp html]# chmod 777 *
  8. [root@lnmp html]# vi wp-config.php
  9. // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
  10. /** WordPress数据库的名称 */
  11. define('DB_NAME', 'wordpress');
  12. /** MySQL数据库用户名 */
  13. define('DB_USER', 'root');
  14. /** MySQL数据库密码 */
  15. define('DB_PASSWORD', '123456');
  16. /** MySQL主机 */
  17. define('DB_HOST', '127.0.0.1');
  18. /** 创建数据表时默认的文字编码 */
  19. define('DB_CHARSET', 'utf8');
  20. /** 数据库整理类型。如不确定请勿更改 */
  21. define('DB_COLLATE', '');
  22. /**#@+
  23. * 身份认证密钥与盐。
  24. *
  25. * 修改为任意独一无二的字串!
  26. * 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/
  27. salt/
  28. * WordPress.org密钥生成服务}
  29. * 任何修改都会导致所有cookies失效,所有用户将必须重新登录。
  30. *

至此完成,在网页输入IP地址即可
192.168.100.11
image.png