LAMP架构应用实战——构建博客网站

2020-09-16 15:20:53 浏览数 (1)

LAMP架构应用实战——构建博客网站

LAMP实战项目

一:首先检查LAMP环境

代码语言:javascript复制
[root@Centos~]# ps -ef|grep http
root 1854  10 00:43 ? 00:00:00/application/apache2.4.23/bin/httpd -k start
php  1877 1854  0 00:43 ? 00:00:00/application/apache2.4.23/bin/httpd -k start
php  1878 1854  0 00:43 ? 00:00:00/application/apache2.4.23/bin/httpd -k start
php  1879 1854  0 00:43 ? 00:00:00/application/apache2.4.23/bin/httpd -k start
root  2259 2086  0 01:44 pts/0 00:00:00grep http
[root@Centos~]# ps -ef|grep mysql
root      1623     1  0 00:43 ?        00:00:00 /bin/sh/application/mysql-5.1.72/bin/mysqld_safe --datadir=/application/mysql-5.1.72/data--pid-file=/application/mysql-5.1.72/data/Centos.pid
mysql     1743  1623  0 00:43 ?     00:00:01/application/mysql-5.1.72/libexec/mysqld --basedir=/application/mysql-5.1.72--datadir=/application/mysql-5.1.72/data --user=mysql--log-error=/application/mysql-5.1.72/data/Centos.err --pid-file=/application/mysql-5.1.72/data/Centos.pid--socket=/application/mysql-5.1.72/tmp/mysql.sock --port=3306
root       2262  2086  0 01:45 pts/0    00:00:00 grep mysql
[root@Centos~]# lsof -i tcp:80
COMMAND  PID USER  FD   TYPE DEVICE SIZE/OFF NODENAME
httpd   1854 root   4u  IPv6  14556      0t0 TCP *:http (LISTEN)
httpd   1877 php    4u  IPv6 14556      0t0  TCP *:http (LISTEN)
httpd   1878 php    4u  IPv6 14556      0t0  TCP *:http (LISTEN)
httpd   1879 php    4u  IPv6 14556      0t0  TCP *:http (LISTEN)
[root@Centos~]# lsof -i tcp:3306
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  1743 mysql  10u  IPv4  14546     0t0  TCP *:mysql (LISTEN)

二:下载博客软件

代码语言:javascript复制
[root@Centostools]# wget https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz
--2016-09-2100:52:50--  https://cn.wordpress.org/wordpress-4.5.3-zh_CN.tar.gz
Resolvingcn.wordpress.org... 66.155.40.249, 66.155.40.250
Connectingto cn.wordpress.org|66.155.40.249|:443... connected.
HTTPrequest sent, awaiting response... 200 OK
Length:8205680 (7.8M) [application/octet-stream]
Saving to:“wordpress-4.5.3-zh_CN.tar.gz”
 100%[==========>]8,205,680    241K/s   in 22s    
 2016-09-2100:53:19 (361 KB/s) - “wordpress-4.5.3-zh_CN.tar.gz” saved [8205680/8205680]
 [root@Centostools]# ls
apr-1.5.2  httpd-2.4.23.tar.gz  pcre-8.38
apr-1.5.2.tar.gz  libiconv-1.7  pcre-8.38.tar.gz
apr-util-1.5.4  libiconv-1.7.tar.gz  php-5.4.22
apr-util-1.5.4.tar.gz  mysql-5.1.72  php-5.4.22.tar.gz
httpd-2.4.23  mysql-5.1.72.tar.gz  wordpress-4.5.3-zh_CN.tar.gz
[root@Centostools]# tar zxf wordpress-4.5.3-zh_CN.tar.gz
[root@Centostools]# cp wordpress/* /data/www/blog/
cp:overwrite `/data/www/blog/index.php'? y
cp:omitting directory `wordpress/wp-admin'
cp: omittingdirectory `wordpress/wp-content'
cp:omitting directory `wordpress/wp-includes'

这时打开浏览器输入http://blog.abc.com 进行wordpress安装

浏览器无法打开网页

查看错误日志显示如下

代码语言:javascript复制
[Tue Sep 2006:04:10.470963 2016] [:error] [pid 35172:tid 140552569812736] [client192.168.1.200:49376] PHP Warning: require_once(/data/www/blog/wp-includes/load.php): failed to openstream: No such file or directory in /data/www/blog/wp-load.php on line 49
[Tue Sep 2006:04:10.471102 2016] [:error] [pid 35172:tid 140552569812736] [client 192.168.1.200:49376]PHP Fatal error:  require_once(): Failedopening required '/data/www/blog/wp-includes/load.php'(include_path='.:/application/php-5.4.22/lib/php') in/data/www/blog/wp-load.php on line 49

根据提示:意思是说一个文件或目录不存在或找不到,应该是路径问题

接着检查wordpress目录下的文件内容与/data/www/blog/下的内容对比发现,的确缺少相关的文件,最终发现使用cp命令无法将目录下所有的文件及目录拷贝至目标目录下

最终使用mv /Download/tools/wordpress/* /data/www/blog/

代码语言:javascript复制
[root@Centosblog]# ll
total 8920
-rw-r--r--.  1 root root     418 Sep 25 2013 index.php
-rw-r--r--.  1 root root  19935 Mar  6  2016license.txt
-rw-r--r--.  1 root root   6789 Jul  2 15:34 readme.html
-rw-r--r--.  1 root root   5032 Jan 28  2016 wp-activate.php
drwxr-xr-x.  9 root root   4096 Jul  2 15:34 wp-admin
-rw-r--r--.  1 root root     364 Dec 19 2015 wp-blog-header.php
-rw-r--r--.  1 root root   1476 Jan 31  2016wp-comments-post.php
-rw-r--r--.  1 root root   2930 Jul  2 15:34wp-config-sample.php
drwxr-xr-x.  5 root root   4096 Jul  2 15:34 wp-content
-rw-r--r--.  1 root root   3286 May 25  2015 wp-cron.php
drwxr-xr-x.16 root root   12288 Jul  2 15:34 wp-includes
-rw-r--r--.  1 root root   2380 Oct 25  2013wp-links-opml.php
-rw-r--r--.  1 root root   3316 Nov  6  2015 wp-load.php
-rw-r--r--.  1 root root  33837 Mar  6  2016 wp-login.php
-rw-r--r--.  1 root root   7887 Oct  6  2015 wp-mail.php
-rw-r--r--.  1 root root  13106 Feb 18  2016 wp-settings.php
-rw-r--r--.  1 root root  28624 Jan 28  2016 wp-signup.php
-rw-r--r--.  1 root root   4035 Dec  1  2014 wp-trackback.php
-rw-r--r--.  1 root root   3061 Oct  3  2015 xmlrpc.php

接着打开浏览器输入http://blog.abc.com 进行wordpress安装显示如下

说明已正常了

三:安装与配置wordpress

1、建立数据库

因为博客的安装需要用到MySQL数据库

代码语言:javascript复制
[root@Centosblog]# mysql -u root -p
Enterpassword: 
Welcome tothe MySQL monitor.  Commands end with ;or g.
Your MySQLconnection id is 6
Serverversion: 5.1.72 Source distribution 
Copyright(c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. 
Oracle is aregistered trademark of Oracle Corporation and/or its
affiliates.Other names may be trademarks of their respective
owners.
Type'help;' or 'h' for help. Type 'c' to clear the current input statement. 
mysql>create database wordpress DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci; 
Query OK, 1row affected (0.00 sec)   

#创建一个gbk数据库,默认是拉丁字符集

代码语言:javascript复制
mysql>show databases like 'wordpress';       
#查看创建的数据库
 ---------------------- 
| Database(wordpress) |
 ---------------------- 
|wordpress            |
 ---------------------- 
1 row inset (0.23 sec)
mysql>grant select,delete,insert,update,create on wordpress.* to wordpress@localhostidentified by'wordpress';                
#给用户(wordpress)设置权限
Query OK, 0rows affected (0.00 sec)
mysql>flush privileges;  
 #刷新权限
Query OK, 0rows affected (0.00 sec)
mysql>select user,host from mysql.user; 
#查看数据用户信息
 ----------- ----------- 
| user      | host      |
 ----------- ----------- 
| root      | 127.0.0.1 |
|           | Centos    |
| root      | Centos    |
|           | localhost |
| root      | localhost |
| wordpress| localhost |
 ----------- ----------- 
6 rows inset (0.00 sec)
mysql>show grants for wordpress@localhost; 
#查看用户权限
 -------------------------------- 
| Grantsfor wordpress@localhost    |
 ------------------------------------------------ 
| GRANTUSAGE ON *.* TO 'wordpress'@'localhost' IDENTIFIED BY PASSWORD'*C260A4F79FA905AF65142FFE0B9A14FE0E1519CC' |
| GRANTSELECT, INSERT, UPDATE, DELETE, CREATE ON `wordpress`.* TO'wordpress'@'localhost'         |
 -------------------------------------- 
2 rows inset (0.00 sec)

2、安装wordpress

接着打开浏览器输入http://blog.abc.com 进行wordpress安装显示如下

点击现在就开始出现下图所示

填写数据库名、用户名、密码、数据库主机名等信息——提交

出现错误提示,可能是站点目录权限不够,修改站目录的权限

代码语言:javascript复制
[root@Centosblog]# chown -R php.php ../blog/   
######################################
#因为之前配置安装PHP时将Apache默认用户修改了,具体用户可以使用下面的命令进行查看
[root@Centosblog]# egrep "User|Group" /application/apache/conf/httpd.conf
# User/Group:The name (or #number) of the user/group to run httpd as.
User php
Group php
    LogFormat "%h %l %u %t"%r" %>s %b "%{Referer}i""%{User-Agent}i"" combined
     LogFormat "%h %l %u %t"%r" %>s %b "%{Referer}i""%{User-Agent}i" %I %O" combinedio
# User homedirectories
#####################################################################
[root@Centosblog]# ls -l
total 8920
-rw-r--r--.  1 php php  50657 Sep 18 09:36 20160918093614.jpg
-rw-r--r--.  1 php php    300 Sep 18 16:15 a.log
-rw-r--r--.  1 php php    777 Sep 18 16:10 deflate.html
-rw-r--r--.  1 php php     31 Sep  9 20:19 index.html
-rw-r--r--.  1 php php    418 Sep 25  2013 index.php
-rw-r--r--.  1 php php  19935 Mar  6  2016 license.txt
-rw-r--r--.  1 php php   6789 Jul  2 15:34 readme.html
drwxr-xr-x.  2 php php   4096 Sep 20 05:57 wordpress
-rw-r--r--.  1 php php 8877479 Jul  2 15:34 wordpress-4.5.3-zh_CN.zip
-rw-r--r--.  1 php php   5032 Jan 28  2016 wp-activate.php
drwxr-xr-x.  9 php php   4096 Jul  2 15:34 wp-admin
-rw-r--r--.  1 php php    364 Dec 19  2015wp-blog-header.php
-rw-r--r--.  1 php php   1476 Jan 31  2016wp-comments-post.php
-rw-r--r--.  1 php php   2930 Jul  2 15:34wp-config-sample.php
drwxr-xr-x.  5 php php   4096 Jul  2 15:34 wp-content
-rw-r--r--.  1 php php   3286 May 25  2015 wp-cron.php
drwxr-xr-x.16 php php   12288 Jul  2 15:34 wp-includes
-rw-r--r--.  1 php php   2380 Oct 25  2013wp-links-opml.php
-rw-r--r--.  1 php php   3316 Nov  6  2015 wp-load.php
-rw-r--r--.  1 php php  33837 Mar  6  2016 wp-login.php
-rw-r--r--.  1 php php   7887 Oct  6  2015 wp-mail.php
-rw-r--r--.  1 php php  13106 Feb 18  2016 wp-settings.php
-rw-r--r--.  1 php php  28624 Jan 28  2016 wp-signup.php
-rw-r--r--.  1 php php   4035 Dec  1  2014 wp-trackback.php
-rw-r--r--.  1 php php   3061 Oct  3  2015 xmlrpc.php

修改权限后,重新刷新页面

运行安装

安装wordpress

登陆后台

发布文章看看

正常显示刚刚发布的文章,表明配置安装成功拉,博客建立好拉!!!!!!!

0 人点赞