免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3079 | 回复: 2
打印 上一主题 下一主题

新_CentOS 6下搭建Apache+MySQL+PHP+SSL [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-02-17 15:52 |只看该作者 |倒序浏览

新_CentOS 6下搭建Apache+MySQL+PHP+SSL



phpapachecentos.

CentOS 6下搭建Apache+MySQL+PHP+SSL
网上的一些文章都已经比较老了,现在版本高了之后,其实配置是很省力的(不考虑什么负载的话)

分享全过程,出了文中提到的安装epel rpmfushion 源指令不同外,其他的过程也适用与Centos 5


1.安装CentOS 6 ,可以选择最小安装,也可以安装桌面

2.升级系统

?yum update
3.安装mysql,并设置mysql开机自启动,同时启动mysql

?yum install mysql yum install mysql-server chkconfig --levels 35 mysqld on service mysqld start
4.配置mysql的root密码

?
  1. mysql_secure_installation

  2. Enter current password for root (enter for none): ( 回车)
  3. OK, successfully used password, moving on...

  4. Setting the root password ensures that nobody can log into the MySQL
  5. root user without the proper authorisation.

  6. Set root password? [Y/n] (Y)

  7. New password: (123456)
  8. Re-enter new password: (123456)
  9. Password updated successfully!
  10. Reloading privilege tables..
  11. ... Success!

  12. By default, a MySQL installation has an anonymous user, allowing anyone
  13. to log into MySQL without having to have a user account created for
  14. them.  This is intended only for testing, and to make the installation
  15. go a bit smoother.  You should remove them before moving into a
  16. production environment.

  17. Remove anonymous users? [Y/n]
复制代码
(是否移出数据库的默认帐户,如果移出,那么在终端中直接输入mysql是会提示连接错误的)Y
  1. Normally, root should only be allowed to connect from 'localhost'.  This
  2. ensures that someone cannot guess at the root password from the network.

  3. Disallow root login remotely? [Y/n]
复制代码
(是否禁止root的远程登录)Y
  1. By default, MySQL comes with a database named 'test' that anyone can
  2. access.  This is also intended only for testing, and should be removed
  3. before moving into a production environment.

  4. Remove test database and access to it? [Y/n] Y
  5. Reload privilege tables now? [Y/n] Y
复制代码
5.安装apache,并设置开机启动

?yum install httpd chkconfig --levels 35 httpd on service httpd start
这时候可以测试apache是否正常工作

直接浏览器访问localhost应该没问题,但是如果别的机子访问不了的话,是因为防火墙的关系,配置防火墙

(后面的ssl还会有这个问题的)

6.安装php

?yum install php   yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
这个时候php就安装完成拉,写个脚本测试一下

?vi /var/www/html/info.php
输入

?<?php phpinfo();?>
访问localhost/info.php即可~

7.安装phpMyAdmin

首先先给系统安装epel 和rpmfushion两个软件大仓库

?
  1. rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm rpm -Uvh http://download1.rpmfusion.org/free/el/updates/testing/6/i386/rpmfusion-free-release-6-0.1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/testing/6/i386/rpmfusion-nonfree-release-6-0.1.noarch.rpm
  2. 如果是centos 5 的话执行下面

  3. ?rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm rpm -Uvh http://download1.rpmfusion.org/free/el/updates/testing/5/i386/rpmfusion-free-release-5-0.1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/testing/5/i386/rpmfusion-nonfree-release-5-0.1.noarch.rpm
复制代码
接着安装起来就很方便拉,~根本不需要去下载就可以获得最新的版本

?yum install phpmyadmin
安装完成后还需要配置一下访问权限,使得出了本机外,其他机子也能访问phpMyAdmin

?vi /etc/httpd/conf.d/phpMyAdmin.conf
找到两个directory的权限设置,Allow from 改成All
  1. <Directory /usr/share/phpMyAdmin/>
  2.    Order Deny,Allow
  3.    Deny from All
  4.    Allow from 127.0.0.1
  5.    Allow from All
  6. </Directory>
  7. <Directory /usr/share/phpMyAdmin/setup/>
  8.    Order Deny,Allow
  9.    Deny from All
  10.    Allow from 127.0.0.1
  11.    Allow from All
  12. </Directory>
复制代码
重启服务器

?service httpd restart

测试localhost/phpMyAdmin

用户名密码:root 123456

OK~ LAMP搭建完毕,


8.搭建SSL,让apache支持https

?yum install mod_ssl
其实安装完这个模块后,重启完apache 就可以用https://localhost测试了,因为他创建了默认的证书

在/etc/pki/tls下

当然我们也可以用openssl创建自己的证书

?yum install openssl

生成证书文件
创建一个rsa私钥,文件名为server.key

?openssl genrsa -out server.key 1024

Generating RSA private key, 1024 bit long modulus
............++++++
............++++++
e is 65537 (0x10001)


用 server.key 生成证书签署请求 CSR
  1. ?openssl req -new -key server.key -out server.csr
  2. Country Name:两个字母的国家代号
  3. State or Province Name:省份名称
  4. Locality Name:城市名称
  5. Organization Name:公司名称
  6. Organizational Unit Name:部门名称
  7. Common Name:你的姓名
  8. Email Address:地址
复制代码
至于 'extra' attributes 不用输入.直接回车

生成证书CRT文件server.crt。

?openssl x509 -days 365 -req -in server.csr -signkey server.key -out server.crt
修改ssl.conf指定我们自己生成的证书

?vi /etc/httpd/conf.d/ssl.conf
找到如下位置,修改路径
  1. #   Server Certificate:
  2. # Point SSLCertificateFile at a PEM encoded certificate.  If
  3. # the certificate is encrypted, then you will be prompted for a
  4. # pass phrase.  Note that a kill -HUP will prompt again.  A new
  5. # certificate can be generated using the genkey(1) command.
  6. SSLCertificateFile /etc/pki/tls/certs/localhost.crt

  7. #   Server Private Key:
  8. #   If the key is not combined with the certificate, use this
  9. #   directive to point at the key file.  Keep in mind that if
  10. #   you've both a RSA and a DSA private key you can configure
  11. #   both in parallel (to also allow the use of DSA ciphers, etc.)
  12. SSLCertificateKeyFile /etc/pki/tls/private/localhost.key


  13. OK

  14. ?service httpd restart
复制代码
一切都搞定拉~~

论坛徽章:
0
2 [报告]
发表于 2012-02-17 22:07 |只看该作者
谢谢分享

论坛徽章:
0
3 [报告]
发表于 2012-08-03 13:21 |只看该作者
谢谢分享~~~~~~~~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP