码迷,mamicode.com
首页 > 其他好文 > 详细

漫漫运维路——基于rpm包安装实现LAMP

时间:2015-05-02 23:31:59      阅读:414      评论:0      收藏:0      [点我收藏+]

标签:开源软件   linux   lamp   

LAMP早期即为Linux+Apache+MySQL+PHP,以基于Linux平台的三个软件搭建出动态网页站点,而现在的LAMP不仅仅代表以上几个软件,因为现在的开源软件种类较多,网站的构建人员的选择也较多,所以现在的M可以为MySQL,也可以为maria DB或者是其他的数据库管理系统。而P则也不仅可代表PHP,在实际应用中还可能是Python、Perl、JSP等语言。

本文将基于rpm包安装的形式实现Linux+Apache+MySQL+PHP的LAMP平台,并且实现以下功能:

1.创建两个虚拟主机,分别用于wordpress和phpmyadmin,要求能使用wordpress创建自己的博客,能使用phpmyadmin管理本机上的数据库。

2.使用HTTPD+SSL配置worpress的那台虚拟主机成HTTPS服务器,实现加密通信。

准备实验环境介绍:

物理机是基于Windows 7的系统,在物理机上安装Vmware 9,然后再在虚拟机上安装CentOS 6.6系统,并配置好YUM源等。准备好后检查YUM仓库是否可用,如下图所示:


技术分享


实验过程:

一.安装配置虚拟主机

1.安装httpd,

在确定未安装httpd的情况下使用如下命令安装即可:

[root@LAMP /]# yum install httpd -y

2.配置虚拟主机

切换目录在/etc/httpd/conf.d/新建虚拟主机配置文件virtualhost.conf,如下所示


技术分享


注释掉/etc/httpd/conf/httpd.conf配置文件中的Section 2 部分内的DocumentRoot


技术分享


1.为虚拟主机新建目录并提供测试页面

新建虚拟主机目录

[root@LAMP conf.d]# mkdir -pv /data/{wordpress,Myadmin}

mkdir: created directory `/data‘

mkdir: created directory `/data/wordpress‘

mkdir: created directory `/data/Myadmin‘

[root@LAMP conf.d]# 

提供临时测试页面index.html

[root@LAMPconf.d]#echo"HIwordpress">/data/wordpress/index.html

[root@LAMP conf.d]# echo "HI Myadmin">/data/Myadmin/index.html

[root@LAMP conf.d]# 

2.重启测试

重启服务并关闭iptables和SElinux

[root@LAMP conf.d]# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd: httpd: apr_sockaddr_info_get() failed for LAMP

httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

                                                           [  OK  ]

[root@LAMP conf.d]# service iptables stop

[root@LAMP conf.d]# setenforce 0

      [root@LAMP conf.d]# 


技术分享


二、安装phpph-mysqlmysql-server,配置phpMyadminwordpress

1.直接使用yum安装好以上软件,

[root@LAMP wordpress]# yum install php php-mysql mysql-server -y

2.下载phpMyadmin和wordpress并解压到/data/Myadmin和/data/wordpress目录下,删除以前存在的Myadmin和wordpress目录并直接将phpMyadmin和wordpress解压后更名为Myadmin和wordpress

[root@LAMP data]# ls

Myadmin  wordpress

3.重启服务,并测试

能看到如下信息,则表示配置没问题

[root@LAMP data]# elinks -dump www.myadmin.com

ELinks: Host not found

[root@LAMP data]# vim /etc/hosts

[root@LAMP data]# elinks -dump www.myadmin.com

   [1]phpMyAdmin

 

               Welcome to phpMyAdmin

 

   Language [[2]________________________________] [3][ Go ]

   Log in[4]phpMyAdmin documentation

   Username: [5]_________________________

   Password: [6]_________________________

   [7][ Go ]

   Cannot load [8]mcrypt extension. Please check your PHP configuration.

   Cookies must be enabled past this point.

 

References

 

   Visible links

   1. http://www.phpmyadmin.net/

   4. http://www.myadmin.com/Documentation.html?phpMyAdmin=vvpak8172gftl0hi3fqkkpiu036he9vh

   8. http://php.net/mcrypt

[root@LAMP data]# elinks -dump www.wordpress.com

   看起来似乎没有 wp-config.php 文件。开始之前,我们需要这个文件。需要帮助?

   您可查看[1]这篇帮助文档。您可以通过本网页界面来编辑 wp-config.php 文件,但

   并非所有主机都支持这种方法。最安全的做法仍是手动创建。

 

   [2]试试创建一个配置文件

 

References

 

   Visible links

   1. http://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php

   2. http://www.wordpress.com/wp-admin/setup-config.php

4.启动并配置mysql,创建wordpress数据库,为用户wuxiaotao授权。

创建wordpress数据库

mysql> CREATE DATABASE wordpress;

Query OK, 1 row affected (0.00 sec)

 

mysql> SHOW DATABASES;

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| test               |

| wordpress          |

+--------------------+

4 rows in set (0.00 sec)

 

mysql> 

为用户wuxiaotao授权

mysql> GRANT ALL ON wordpress.* TO ‘wuxiaotao‘@‘127.0.0.1‘ IDENTIFIED BY ‘hello mage‘;#因为mysql和http是安装在同一主机上,配置其可在本地登录即可

Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL ON wordpress.* TO ‘wuxiaotao‘@‘localhost‘ IDENTIFIED BY ‘hello mage‘;#配置其反解

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;#通知mysql重读授权信息

Query OK, 0 rows affected (0.00 sec)

5.配置wordpress,测试

切换目录至/data/wordpress目录,并复制wp-config-sample.php 为wp-config.php

[root@LAMP data]# cd wordpress/

[root@LAMP wordpress]# ls

index.php        wp-admin            wp-comments-post.php  wp-cron.php        wp-load.php   wp-rdf.php       wp-settings.php

license.txt      wp-app.php          wp-commentsrss2.php   wp-feed.php        wp-login.php  wp-register.php  wp-signup.php

readme.html      wp-atom.php         wp-config-sample.php  wp-includes        wp-mail.php   wp-rss2.php      wp-trackback.php

wp-activate.php  wp-blog-header.php  wp-content            wp-links-opml.php  wp-pass.php   wp-rss.php       xmlrpc.php

[root@LAMP wordpress]# cp wp-config-sample.php wp-config.php

修改wp-config.php文件,更改内容如下


技术分享


重启服务并测试

    www.myadmin.com


    

技术分享


登录mysql


技术分享


        www.mywordpress.com


技术分享


如上显示,成功!

三、配置wordpress称为HTTPS

  1.另起一台虚拟机,设置其IP为172.16.35.3,改主机用作CA

     生成CA私钥

[root@CA CA]# (umask 077;openssl genrsa -out private/pam.key 1024)

Generating RSA private key, 1024 bit long modulus

..........++++++

............++++++

e is 65537 (0x10001)

   生成签证书

[root@CA CA]# openssl req -new -x509 -key private/pam.key -out server.pem -days 36000

根据提示键入相关信息

   修改openssl配置文件(/etc/pki/tls/openssl.cf),并为CA提供配置文件


技术分享


[root@CA CA]# echo "01">serial

 

2.客户端生成证书

客户端生成私钥

[root@LAMP ssl]# (umask 077;openssl genrsa -out httpd.key 1024)

Generating RSA private key, 1024 bit long modulus

.........++++++

...++++++

e is 65537 (0x10001)

客户端生成证书

[root@LAMP ssl]# openssl req -new -key httpd.key -out httpd.csr

根据提示键入相关信息

3.复制客户端证书到CA服务器端,并签署

复制客户端证书到CA服务器

[root@LAMP ssl]# scp /etc/httpd/ssl/httpd.csr root@172.16.35.3:/etc/pki/CA/

根据提示输入密码等验证信息

CA服务器端签署请求

[root@CA CA]# openssl ca -in httpd.csr -out httpd.crt -days 3650

把签署号的证书发回http服务器

[root@CA CA]#scp/etc/pki/CA/root@172.16.35.3:/etc/httpd/ssl/httpd.csr 

4.在主机LAMP上安装mod_ssl模块并配置。

安装mod_ssl

[root@LAMP ssl]# yum install mod_ssl

配置/etc/httpd/conf.d/ssl.conf


技术分享


把之前在virtualhost.conf文件中的关于wordpress的虚拟主机删除。

2.为网卡子接口配置第地址,并测试:

配置网卡子接口

[root@LAMP ~]# ifconfig eth0:1 172.16.35.4/16

在windows主机中修改C:\Windows\System32\drivers\etc\hosts文件为其添加如下条目


技术分享


重启服务并测试

[root@LAMP ~]# service httpd restart

Stopping httpd:                                            [  OK  ]

Starting httpd: httpd: apr_sockaddr_info_get() failed for LAMP

httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

[Thu Apr 30 23:55:41 2015] [warn] NameVirtualHost *:80 has no VirtualHosts

[  OK  ]

测试www.mywordpress.com


技术分享


测试www.myadmin.com


技术分享



本文出自 “linux-冒泡” 博客,请务必保留此出处http://7703592.blog.51cto.com/7693592/1641321

漫漫运维路——基于rpm包安装实现LAMP

标签:开源软件   linux   lamp   

原文地址:http://7703592.blog.51cto.com/7693592/1641321

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!