Centos 6.9 LAMP及WordPress教程

126 阅读4分钟
原文链接: blog.didiyun.com

LAMP即Linux、Apache、MySQL、PHP的简称,目前仍有大量的企业以LAMP为架构的原型基础,搭建自己的服务应用。WordPress是成熟的博客平台产品,本文向广大用户和有兴趣的朋友介绍如何在滴滴云上搭建LAMP和WordPress。

其架构示意图如下:

购买了云主机相关产品(具体配置及数量请根据自身需求选定)以后,具体的LAMP及WordPress安装操作如下(不同的操作系统安装的命令略有不同,本文以centos 6.9为样例):

一、Apache的安装

yum -y install httpd

安装完成后输入命令启动服务并且设置为开机启动

这里会出现一个提示:

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain

可以事先避免,解决方法如下:

vi /etc/httpd/conf/httpd.conf

将下面一行注释掉

#ServerName www.example.com:80 service httpd start chkconfig httpd on
1
2
3
4
#ServerName www.example.com:80
service httpd start                                                  
chkconfig httpd on
 

如果这一步安装正确,就可以直接在浏览器中输入公有IP地址,访问到Apache的测试页面。

二、Mysql安装

输入下面的命令安装Mysql服务,同时也设置为开机启动

[root@10-254-23-* dc2-user]# yum -y install mysql-server

[root@10-254-23-* dc2-user]# service mysqld start

[root@10-254-23-* dc2-user]# chkconfig mysqld on

如果这一步安装正确,可以输入下面的命令进入sql,默认的root用户没有设置密码,直接回车便可进入。

[root@10-254-23-8 dc2-user]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered 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>
1
2
3
4
5
6
7
8
9
10
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered 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>
 

在sql终端中输入exit便可以退出
mysql> exit

Bye

[root@10-254-23-8 dc2-user]#
利用以下命令可以修改root用户的密码为 123456
[root@10-254-23-8 dc2-user]# mysqladmin -u root password 123456

三、PHP的安装

输入以下命令可以安装PHP及其组件

yum install php php-mysql –y

利用下面的命令安装常用的组件

yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

安装完成后,可以编辑一个测试页面,测试php是否安装成功。

vi /var/www/html/info.php

输入以下内容

<?php phpinfo(); ?>
1
2
3
4
<?php
phpinfo();  
?>
 

编辑完成后,重启httpd,在浏览器中输入http://x.x.x.x/info.php,查看版本信息。

四、WordPress的安装

安装wget,unzip命令

yum install -y wget yum install -y unzip
1
2
3
yum install -y wget
yum install -y unzip
 

下载最新版本的WordPress并解压

wget http://wordpress.org/latest.zip unzip latest.zip
1
2
3
wget http://wordpress.org/latest.zip
unzip latest.zip
 

编辑配置文件,修改数据库信息

cd wordpress/ cp wp-config-sample.php wp-config.php vi wp-config.php
1
2
3
4
cd wordpress/
cp wp-config-sample.php wp-config.php
vi wp-config.php
 

修改数据库名称,用户名,密码。

// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpressdb'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'abcD123456$');
1
2
3
4
5
6
7
8
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpressdb');
/** MySQL database username */
define('DB_USER', 'wordpressuser');
/** MySQL database password */
define('DB_PASSWORD', 'abcD123456$');
 

配置完成后移动所有文件到/var/www/html目录下

cd .. cp -rf wordpress/* /var/www/html/
1
2
3
cd ..
cp -rf wordpress/* /var/www/html/
 

WordPress安装完毕,之后对目录的权限进行编辑

chown -R apache:apache /var/www/html/ chmod -R 755 /var/www/html/ mkdir -p /var/www/html/wp-content/uploads chown -R :apache /var/www/html/wp-content/uploads
1
2
3
4
5
chown -R apache:apache /var/www/html/
chmod -R 755 /var/www/html/
mkdir -p /var/www/html/wp-content/uploads
chown -R :apache /var/www/html/wp-content/uploads
 

建立数据库和用户,并设置密码

mysql -u root -p mysql> CREATE DATABASE wordpressdb; Query OK, 1 row affected (0.00 sec) mysql> CREATE USER wordpressuser@localhost IDENTIFIED BY '123456'; Query OK, 0 rows affected (0.00 sec) mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO wordpressuser@localhost; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
1
2
3
4
5
6
7
8
9
10
11
12
mysql -u root -p
mysql> CREATE DATABASE wordpressdb;
Query OK, 1 row affected (0.00 sec)
mysql> CREATE USER wordpressuser@localhost IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON wordpressdb.* TO wordpressuser@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
 

重启服务

systemctl restart mysqld systemctl restart httpd
1
2
3
systemctl restart mysqld
systemctl restart httpd
 

完成以上配置后,便可以登陆http://x.x.x.x/来访问你的博客了。

登陆界面如下图