从无到有——搭建LAMP和wordpress

搭建个人博客

环境:vps(CentOS7)和域名

一、搭建LAMP

1、yum安装需要软件

# yum install -y httpd php php-mysql mariadb-server

2、测试httpd服务

[root@www ~]# systemctl start httpd
[root@www ~]# echo "This is a httpd test page.">/var/www/html/index.html
[root@www ~]# curl 127.0.0.1
This is a httpd test page. #出现主页表示安装成功

3、测试数据库服务

[root@www ~]# systemctl start mariadb.service 
[root@www ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show variables like 'version';
+---------------+----------------+
| Variable_name | Value          |
+---------------+----------------+
| version       | 5.5.56-MariaDB |
+---------------+----------------+
1 row in set (0.00 sec)

MariaDB [(none)]> exit
Bye

4、测试php

测试PHP模块

[root@www ~]# httpd -M |grep php
 php5_module (shared)
[root@www ~]# httpd -M |grep rewrite
 rewrite_module (shared)

 测试PHP

# cat /var/www/html/index.php  #编辑PHP测试页
<html>
<h1>This is a php test page.</h1>
<?php
phpinfo();
?>
</html>
# curl http://127.0.0.1/index.php 
在浏览器中输入http://xxx.xxx.xxx.xxx/index.php 测式php页面

测试PHP连接数据库

[root@www ~]# vim /var/www/html/connmysql.php
<?php $conn=mysql_connect("localhost","root", ""); if ($conn) echo "succ"; else echo "fail"; mysql_close($conn); ?>
[root@www ~]# curl http://127.0.0.1/connmysql.php
succ #看到succ说明OK

二、搭建wordpress

1、下载和安装

[root@www ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.zip
[root@www ~]# unzip wordpress-4.9.4-zh_CN.zip
[root@www ~]# cp -R wordpress /var/www/html/
[root@www html]# cp /var/www/html/wordpress/wp-config-sample.php /var/www/html/wordpress/wp-config.php

2、配置wordpress

[root@www ~]# vim /var/www/html/wordpress/wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'wpadmin');

/** MySQL主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

3、配置数据库

[root@www ~]# mysql
MariaDB [(none)]> create database wpdb character set utf8;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all privileges on wpdb.* to 'wpadmin'@'localhost' identified by 'wpadmin';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

4、打开浏览器输入http://host_IP/wordpress/wp-admin/install.php,按照提示配置进入后台管理界面

记录2018-05-24 18:10:07

猜你喜欢

转载自www.cnblogs.com/L-dongf/p/9083776.html