LAMP实战之构建博客网站

2018-03-28 12:54:41 浏览数 (1)

1、首先检查LAMP环境

代码语言:javascript复制
[root@cairui htdocs]# ps -ef | grep httpd
php      13160     1  0 Mar03 ?        00:00:00 /opt/apache2.2.34/bin/httpd -k start
root     19311     1  0 Mar03 ?        00:00:02 /opt/apache2.2.34/bin/httpd -k graceful
php      19401 19311  0 Mar03 ?        00:00:00 /opt/apache2.2.34/bin/httpd -k graceful
php      19402 19311  0 Mar03 ?        00:00:00 /opt/apache2.2.34/bin/httpd -k graceful
php      19403 19311  0 Mar03 ?        00:00:00 /opt/apache2.2.34/bin/httpd -k graceful
root     24835 24810  0 09:11 pts/0    00:00:00 grep httpd
[root@cairui htdocs]# ps -ef | grep mysql
root      1470     1  0 Mar01 ?        00:00:00 /bin/sh /opt/mysql-5.7.21/bin/mysqld_safe --datadir=/opt/mysql-5.7.21/data --pid-file=/opt/mysql-5.7.21/data/cairui.pid
mysql     1557  1470  0 Mar01 ?        00:02:51 /opt/mysql-5.7.21/bin/mysqld --basedir=/opt/mysql-5.7.21 --datadir=/opt/mysql-5.7.21/data --plugin-dir=/opt/mysql-5.7.21/lib/plugin --user=mysql --log-error=cairui.err --pid-file=/opt/mysql-5.7.21/data/cairui.pid
root     24837 24810  0 09:11 pts/0    00:00:00 grep mysql
[root@cairui htdocs]# lsof -i tcp:80
COMMAND     PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
AliYunDun  1335 root   18u  IPv4   9047      0t0  TCP 120.25.255.87:36408->106.11.68.13:http (ESTABLISHED)
httpd     19311 root    3u  IPv4 356362      0t0  TCP *:http (LISTEN)
httpd     19402  php    3u  IPv4 356362      0t0  TCP *:http (LISTEN)
httpd     19403  php    3u  IPv4 356362      0t0  TCP *:http (LISTEN)
[root@cairui htdocs]# lsof -i tcp:3306
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mysqld  1557 mysql   29u  IPv4   9380      0t0  TCP *:mysql (LISTEN)

2、配置博客软件(wordpress)

代码语言:javascript复制
WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上架设属于自己的网站。也可以把 WordPress当作一个内容管理系统(CMS)来使用。
WordPress是一款个人博客系统,并逐步演化成一款内容管理系统软件,它是使用PHP语言和MySQL数据库开发的。用户可以在支持 PHP 和 MySQL数据库的服务器上使用自己的博客。
WordPress有许多第三方开发的免费模板,安装方式简单易用。不过要做一个自己的模板,则需要你有一定的专业知识。比如你至少要懂的标准通用标记语言下的一个应用HTML代码、CSS、PHP等相关知识。
WordPress官方支持中文版,同时有爱好者开发的第三方中文语言包,如wopus中文语言包。WordPress拥有成千上万个各式插件和不计其数的主题模板样式。
代码语言:javascript复制
[root@cairui software]# wget https://wordpress.org/latest.tar.gz
--2018-03-04 09:16:34--  https://wordpress.org/latest.tar.gz
Resolving wordpress.org... 198.143.164.252
Connecting to wordpress.org|198.143.164.252|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 8565525 (8.2M) [application/octet-stream]
Saving to: “latest.tar.gz”

100%[=========================================================>] 8,565,525   2.83M/s   in 2.9s    

2018-03-04 09:16:38 (2.83 MB/s) - “latest.tar.gz” saved [8565525/8565525]

[root@cairui software]# ls
cmake-3.9.6         httpd-2.2.34         latest.tar.gz  libiconv-1.15.tar.gz  php-7.2.3
cmake-3.9.6.tar.gz  httpd-2.2.34.tar.gz  libiconv-1.15  mysql-5.7.21          php-7.2.3.tar.gz
[root@cairui software]# tar zxf latest.tar.gz 
[root@cairui software]# ls
cmake-3.9.6         httpd-2.2.34.tar.gz  libiconv-1.15.tar.gz  php-7.2.3.tar.gz
cmake-3.9.6.tar.gz  latest.tar.gz        mysql-5.7.21          wordpress
httpd-2.2.34        libiconv-1.15        php-7.2.3
[root@cairui software]# cd wordpress/
[root@cairui wordpress]# ls
index.php        wp-admin              wp-content         wp-load.php      wp-signup.php
license.txt      wp-blog-header.php    wp-cron.php        wp-login.php     wp-trackback.php
readme.html      wp-comments-post.php  wp-includes        wp-mail.php      xmlrpc.php
wp-activate.php  wp-config-sample.php  wp-links-opml.php  wp-settings.php
[root@cairui wordpress]# cd ..
[root@cairui software]# cp wordpress/* /opt/apache/htdocs/
cp: overwrite `/opt/apache/htdocs/index.php'? y
cp: omitting directory `wordpress/wp-admin'
cp: omitting directory `wordpress/wp-content'
cp: omitting directory `wordpress/wp-includes'
代码语言:javascript复制
[root@cairui apache]# mv /home/cairui/software/wordpress/* /opt/apache/htdocs/

上述mv的原因是cp出错,查看错误日志

代码语言:javascript复制
[Sun Mar 04 09:04:36 2018] [error] [client 114.239.215.144] File does not exist: /opt/apache2.2.34/htdocs/favicon.ico, referer: http://120.25.255.87/

缺少文件,所以cp无法全部拷贝,使用mv

输入120.25.255.87,进入wordpress设置

3、配置数据库

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

代码语言:javascript复制
mysql> create database wordpress default character set gbk collate gbk_chinese_ci;  #创建一个gbk数据库,默认是拉丁字符集
Query OK, 1 row affected (0.02 sec)

mysql> show databses;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'databses' at line 1
mysql> show databases;
 -------------------- 
| Database           |
 -------------------- 
| information_schema |
| managerie          |
| mysql              |
| performance_schema |
| sys                |
| test               |
| wordpress          |
 -------------------- 
7 rows in set (0.00 sec)

mysql> grant select,delete,insert,update,create on wordpress.* to wordpress@localhost identified by'wordpress';  #给用户wordpress设置权限
Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> flush privileges;  #刷新权限
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host from mysql.user;
 --------------- ----------- 
| user          | host      |
 --------------- ----------- 
| mysql.session | localhost |
| mysql.sys     | localhost |
| root          | localhost |
| wordpress     | localhost |
 --------------- ----------- 
4 rows in set (0.00 sec)

mysql> show grants for wordpress@localhost;
 ------------------------------------------------------------------------------------------ 
| Grants for wordpress@localhost                                                           |
 ------------------------------------------------------------------------------------------ 
| GRANT USAGE ON *.* TO 'wordpress'@'localhost'                                            |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE ON `wordpress`.* TO 'wordpress'@'localhost' |
 ------------------------------------------------------------------------------------------ 
2 rows in set (0.00 sec)

权限不够,因为把httpd.conf用户改为了php

代码语言:javascript复制
[root@cairui apache]# chown -R php.php /opt/apache/htdocs/
[root@cairui apache]# cd htdocs/
[root@cairui htdocs]# ls
index.php        wp-admin              wp-content         wp-load.php      wp-signup.php
license.txt      wp-blog-header.php    wp-cron.php        wp-login.php     wp-trackback.php
readme.html      wp-comments-post.php  wp-includes        wp-mail.php      xmlrpc.php
wp-activate.php  wp-config-sample.php  wp-links-opml.php  wp-settings.php
[root@cairui htdocs]# ll
total 188
-rw-r--r--  1 php php   418 Sep 25  2013 index.php
-rw-r--r--  1 php php 19935 Jan  7 03:32 license.txt
-rw-r--r--  1 php php  7413 Dec 12  2016 readme.html
-rw-r--r--  1 php php  5434 Sep 23 20:21 wp-activate.php
drwxr-xr-x  9 php php  4096 Feb  6 23:49 wp-admin
-rw-r--r--  1 php php   364 Dec 19  2015 wp-blog-header.php
-rw-r--r--  1 php php  1627 Aug 29  2016 wp-comments-post.php
-rw-r--r--  1 php php  2853 Dec 16  2015 wp-config-sample.php
drwxr-xr-x  4 php php  4096 Feb  6 23:49 wp-content
-rw-r--r--  1 php php  3669 Aug 20  2017 wp-cron.php
drwxr-xr-x 18 php php 12288 Feb  6 23:49 wp-includes
-rw-r--r--  1 php php  2422 Nov 21  2016 wp-links-opml.php
-rw-r--r--  1 php php  3306 Aug 22  2017 wp-load.php
-rw-r--r--  1 php php 36583 Oct 13 10:10 wp-login.php
-rw-r--r--  1 php php  8048 Jan 11  2017 wp-mail.php
-rw-r--r--  1 php php 16246 Oct  4 08:20 wp-settings.php
-rw-r--r--  1 php php 30071 Oct 19 01:36 wp-signup.php
-rw-r--r--  1 php php  4620 Oct 24 06:12 wp-trackback.php
-rw-r--r--  1 php php  3065 Sep  1  2016 xmlrpc.php
代码语言:javascript复制
mysql> use wordpress
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
 ----------------------- 
| Tables_in_wordpress   |
 ----------------------- 
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
 ----------------------- 
12 rows in set (0.01 sec)

 错误:进入详情界面无法显示(原因,链接内包含中文,把链接改为英文即可)

0 人点赞