一、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

  1. // 修改主机名
  2. [root@localhost ~]# hostnamectl set-hostname lnmp
  3. [root@localhost ~]# su
  4. [root@lnmp ~]#
  5. // 查看主机名
  6. [root@lnmp ~]# hostnamectl
  7. Static hostname: lnmp
  8. Icon name: computer-vm
  9. Chassis: vm
  10. Machine ID: 583789aef18c4eb09432b6c75f03c8f4
  11. Boot ID: a1e9a62e216243f58a2e781a26af30ec
  12. Virtualization: vmware
  13. Operating System: CentOS Linux 7 (Core)
  14. CPE OS Name: cpe:/o:centos:centos:7
  15. Kernel: Linux 3.10.0-1127.el7.x86_64
  16. Architecture: x86-64
  17. // 安装依赖
  18. [root@lnmp ~]# yum install -y unzip
  19. //上传软件包【lnmp+wordpress】并解压
  20. [root@lnmp ~]# unzip lnmp+wordpress.zip
  21. // 配置yum源
  22. [root@lnmp ~]# cat /etc/yum.repos.d/local.repo
  23. [centos]
  24. name=centos7
  25. baseurl=file:///opt/centos
  26. gpgcheck=0
  27. enabled=1
  28. [lnmp]
  29. name=lnmp
  30. baseurl=file:///root/lnmp+wordpress/lnmp
  31. gpgcheck=0
  32. enabled=1
  33. [root@lnmp lnmp+wordpress]# yum clean all
  34. Loaded plugins: fastestmirror
  35. Cleaning repos: centos lnmp
  36. Cleaning up list of fastest mirrors
  37. [root@lnmp lnmp+wordpress]# yum repolist
  38. Loaded plugins: fastestmirror
  39. Determining fastest mirrors
  40. centos | 3.6 kB 00:00:00
  41. lnmp | 3.0 kB 00:00:00
  42. (1/3): centos/primary_db | 3.3 MB 00:00:00
  43. (2/3): centos/group_gz | 153 kB 00:00:00
  44. (3/3): lnmp/primary_db | 153 kB 00:00:00
  45. repo id repo name status
  46. centos centos7 4,071
  47. lnmp lnmp 178
  48. repolist: 4,249
  49. //安装依赖
  50. [root@lnmp ~]# yum -y install nginx mariadb-server mariadb php-fpm php-mysql
  51. [root@lnmp ~]# cd lnmp+wordpress
  52. [root@lnmp lnmp+wordpress]# ll
  53. total 9012
  54. drwxr-xr-x. 3 root root 12288 Oct 17 18:40 lnmp
  55. -rw-r--r--. 1 root root 9210722 Mar 28 2017 wordpress-4.7.3-zh_CN.zip
  56. [root@lnmp lnmp+wordpress]# mv * /root/
  57. [root@lnmp lnmp+wordpress]# cd
  58. [root@lnmp ~]# rm -rf lnmp+wordpress
  59. [root@lnmp ~]# vim /etc/yum.repos.d/local.repo
  60. [centos]
  61. name=centos7
  62. baseurl=file:///opt/centos
  63. gpgcheck=0
  64. enable=1
  65. [lnmp]
  66. name=lnmp
  67. baseurl=file:///root/lnmp
  68. gpgcheck=0
  69. enabled=1
  70. [root@lnmp ~]# yum clean all
  71. [root@lnmp ~]# yum repolist
  72. [root@lnmp ~]# systemctl start nginx && systemctl enable nginx
  73. Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
  74. [root@lnmp ~]# vi /etc/nginx/conf.d/default.conf
  75. server {
  76. listen 80;
  77. server_name localhost;
  78. #charset koi8-r;
  79. #access_log /var/log/nginx/host.access.log main;
  80. // 添加index.php
  81. location / {
  82. root /usr/share/nginx/html;
  83. index index.php index.html index.htm;
  84. }
  85. // 添加以下内容
  86. location ~ \.php$ {
  87. root /usr/share/nginx/html;
  88. fastcgi_pass 127.0.0.1:9000;
  89. fastcgi_index index.php;
  90. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script
  91. _name;
  92. include fastcgi_params;
  93. }
  94. #error_page 404 /404.html;
  95. // 重启服务
  96. [root@lnmp ~]# systemctl restart nginx
  97. // 启动数据库
  98. [root@lnmp ~]# systemctl start mariadb && systemctl enable mariadb
  99. Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
  100. // 初始化数据库
  101. [root@lnmp ~]# mysql_secure_installation
  102. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
  103. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  104. In order to log into MariaDB to secure it, we'll need the current
  105. password for the root user. If you've just installed MariaDB, and
  106. you haven't set the root password yet, the password will be blank,
  107. so you should just press enter here.
  108. Enter current password for root (enter for none):
  109. OK, successfully used password, moving on...
  110. Setting the root password ensures that nobody can log into the MariaDB
  111. root user without the proper authorisation.
  112. Set root password? [Y/n] y
  113. New password:
  114. Re-enter new password:
  115. Password updated successfully!
  116. Reloading privilege tables..
  117. ... Success!
  118. By default, a MariaDB installation has an anonymous user, allowing anyone
  119. to log into MariaDB without having to have a user account created for
  120. them. This is intended only for testing, and to make the installation
  121. go a bit smoother. You should remove them before moving into a
  122. production environment.
  123. Remove anonymous users? [Y/n] y
  124. ... Success!
  125. Normally, root should only be allowed to connect from 'localhost'. This
  126. ensures that someone cannot guess at the root password from the network.
  127. Disallow root login remotely? [Y/n] n
  128. ... skipping.
  129. By default, MariaDB comes with a database named 'test' that anyone can
  130. access. This is also intended only for testing, and should be removed
  131. before moving into a production environment.
  132. Remove test database and access to it? [Y/n] y
  133. - Dropping test database...
  134. ... Success!
  135. - Removing privileges on test database...
  136. ... Success!
  137. Reloading the privilege tables will ensure that all changes made so far
  138. will take effect immediately.
  139. Reload privilege tables now? [Y/n] y
  140. ... Success!
  141. Cleaning up...
  142. All done! If you've completed all of the above steps, your MariaDB
  143. installation should now be secure.
  144. Thanks for using MariaDB!

登录数据库

  1. [root@lnmp ~]# mysql -uroot -p123456
  2. Welcome to the MariaDB monitor. Commands end with ; or \g.
  3. Your MariaDB connection id is 9
  4. Server version: 5.5.56-MariaDB MariaDB Server
  5. Copyright (c) 2000, 2017, 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 root@localhost identified by '123456' with grant option;
  10. Query OK, 0 rows affected (0.00 sec) // 授权所有用户拥有本地数据库的所有权限
  11. MariaDB [(none)]> grant all privileges on *.* to root@"%" identified by '123456' with grant option;
  12. Query OK, 0 rows affected (0.01 sec)// 授权用户可进行远程登录
  13. MariaDB [(none)]>

PHP

  1. [root@lnmp ~]# vi /etc/php-fpm.d/www.conf
  2. 39 user = nginx
  3. 40 ; RPM: Keep a group allowed to write in log dir.
  4. 41 group = nginx
  5. [root@lnmp ~]# systemctl start php-fpm && systemctl enable php-fpm
  6. Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

image.png
Wordpress

  1. [root@lnmp ~]# unzip wordpress-4.7.3-zh_CN.zip
  2. [root@lnmp ~]# cd /usr/share/nginx/html
  3. [root@lnmp html]# rm -rf *
  4. [root@lnmp html]# cp -rvf /root/wordpress* ./
  5. [root@lnmp html]# ls
  6. wordpress wordpress-4.7.3-zh_CN.zip
  7. [root@lnmp html]# cd wordpress
  8. [root@lnmp wordpress]# ls
  9. index.php wp-activate.php wp-comments-post.php wp-cron.php wp-load.php wp-settings.php xmlrpc.php
  10. license.txt wp-admin wp-config-sample.php wp-includes wp-login.php wp-signup.php
  11. readme.html wp-blog-header.php wp-content wp-links-opml.php wp-mail.php wp-trackback.php
  12. [root@lnmp wordpress]# cd ..
  13. [root@lnmp html]# mv wordpress/* ./
  14. [root@lnmp html]# cp wp-config-sample.php wp-config.php
  15. [root@lnmp html]# vi wp-config.php
  16. <?php
  17. /**
  18. * WordPress基础配置文件。
  19. *
  20. * 这个文件被安装程序用于自动生成wp-config.php配置文件,
  21. * 您可以不使用网站,您需要手动复制这个文件,
  22. * 并重命名为“wp-config.php”,然后填入相关信息。
  23. *
  24. * 本文件包含以下配置选项:
  25. *
  26. * * MySQL设置
  27. * * 密钥
  28. * * 数据库表名前缀
  29. * * ABSPATH
  30. *
  31. * @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
  32. *
  33. * @package WordPress
  34. */
  35. // ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
  36. /** WordPress数据库的名称 */
  37. define('DB_NAME', 'wordpress');
  38. /** MySQL数据库用户名 */
  39. define('DB_USER', 'root');
  40. /** MySQL数据库密码 */
  41. define('DB_PASSWORD', '123456');
  42. /** MySQL主机 */
  43. define('DB_HOST', '127.0.0.1');
  44. /** 创建数据表时默认的文字编码 */
  45. define('DB_CHARSET', 'utf8');
  46. /** 数据库整理类型。如不确定请勿更改 */
  47. define('DB_COLLATE', '');
  48. /**#@+
  49. * 身份认证密钥与盐。
  50. *
  51. * 修改为任意独一无二的字串!
  52. * 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/
  53. "wp-config.php" [dos] 96L, 2905C written

四、登录网页编辑

image.png
image.png