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密码
mysql_secure_installation |
Entercurrentpasswordforroot(enterfornone):(回车)
OK,successfullyusedpassword,movingon...
SettingtherootpasswordensuresthatnobodycanlogintotheMySQL
rootuserwithouttheproperauthorisation.
Setrootpassword?[Y/n](Y)
Newpassword:(123456)
Re-enternewpassword:(123456)
Passwordupdatedsuccessfully!
Reloadingprivilegetables..
...Success!
Bydefault,aMySQLinstallationhasananonymoususer,allowinganyone
tologintoMySQLwithouthavingtohaveauseraccountcreatedfor
them.Thisisintendedonlyfortesting,andtomaketheinstallation
goabitsmoother.Youshouldremovethembeforemovingintoa
productionenvironment.
Remove anonymous users? [Y/n](是否移出数据库的默认帐户,如果移出,那么在终端中直接输入mysql是会提示连接错误的)Y
Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.This
ensuresthatsomeonecannotguessattherootpasswordfromthenetwork.
Disallow root login remotely? [Y/n](是否禁止root的远程登录)Y
Bydefault,MySQLcomeswithadatabasenamed'test'thatanyonecan
access.Thisisalsointendedonlyfortesting,andshouldberemoved
beforemovingintoaproductionenvironment.
Removetestdatabaseandaccesstoit?[Y/n]Y
Reload privilege tables now? [Y/n] Y5.安装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两个软件大仓库
rpm -Uvh <a target="_blank" href="https://www.ancii.com/link/v1/anXGoB7DqCaHTmVAv-Y-Vqz5AHiVqskEGkieByKQ86Qb5OtVVaPoEYNm4KBjvXQZil7hQQEr9gPrwFuLTvfluoggfIyYKzX4M8P1RAHjU3w/" rel="nofollow" title="http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm">http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm</a> |
rpm -Uvh <a target="_blank" href="https://www.ancii.com/link/v1/Wb27EzFQ0UKIXRFZ9t1OA396Bh1gODyXeZW4bIfl7T0RocbM_4ghAOo2MLJKOovUAoixizJ8wkO61enuzJ9xPUS6MPV-M26CiFDRm1YXmCGkhbs02E_ePAmApE5S2xeJInNKepZVDCdfFn5I5Yw0PQ/" rel="nofollow" title="http://download1.rpmfusion.org/free/el/updates/testing/6/i386/rpmfusion-free-release-6-0.1.noarch.rpm">http://download1.rpmfusion.org/free/el/updates/testing/6/i386/rpmfusion-free-release-6-0.1.noarch.rpm</a> <a target="_blank" href="https://www.ancii.com/link/v1/Wb27EzFQ0UKIXRFZ9t1OA9q6LiApSoTNWROhb8YD1_SmFrrPpeDUY66jQLhGPLWFwJFKV4K4wnUFr6PcWodaBlbteDu3VxXI0wXC800A1KKea526tlMf3EJX48OnRf9LbVaawYqN6ciyvB1ttE-V7Q/" rel="nofollow" title="http://download1.rpmfusion.org/nonfree/el/updates/testing/6/i386/rpmfusion-nonfree-release-6-0.1.noarch.rpm">http://download1.rpmfusion.org/nonfree/el/updates/testing/6/i386/rpmfusion-nonfree-release-6-0.1.noarch.rpm</a> |
如果是centos 5 的话执行下面
rpm -Uvh <a target="_blank" href="https://www.ancii.com/link/v1/anXGoB7DqCaHTmVAv-Y-VisdtZw7YbCpCEg5kt__ToMfG2qzzuF5Y9VfulDgYOQw7hDiDd7G63U2aRBITfZrzNYrEK7csjgYqlm-UogS97A/" rel="nofollow" title="http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm">http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm</a> |
rpm -Uvh <a target="_blank" href="https://www.ancii.com/link/v1/Wb27EzFQ0UKIXRFZ9t1OA396Bh1gODyXeZW4bIfl7T0RocbM_4ghAOo2MLJKOovUfQn0h-nv69K-DfJFQi9kTES6MPV-M26CiFDRm1YXmCFS4Kc5m2oXzVUzrjW2yu9AInNKepZVDCdfFn5I5Yw0PQ/" rel="nofollow" title="http://download1.rpmfusion.org/free/el/updates/testing/5/i386/rpmfusion-free-release-5-0.1.noarch.rpm">http://download1.rpmfusion.org/free/el/updates/testing/5/i386/rpmfusion-free-release-5-0.1.noarch.rpm</a> <a target="_blank" href="https://www.ancii.com/link/v1/Wb27EzFQ0UKIXRFZ9t1OA9q6LiApSoTNWROhb8YD1_SmFrrPpeDUY66jQLhGPLWFYmqN0Sq7K4_cl4k0_qkVN1bteDu3VxXI0wXC800A1KIsOhQAwfMkVynxSSBcT0D0bVaawYqN6ciyvB1ttE-V7Q/" rel="nofollow" title="http://download1.rpmfusion.org/nonfree/el/updates/testing/5/i386/rpmfusion-nonfree-release-5-0.1.noarch.rpm">http://download1.rpmfusion.org/nonfree/el/updates/testing/5/i386/rpmfusion-nonfree-release-5-0.1.noarch.rpm</a> |
接着安装起来就很方便拉,~根本不需要去下载就可以获得最新的版本
yum install phpmyadmin |
安装完成后还需要配置一下访问权限,使得出了本机外,其他机子也能访问phpMyAdmin
vi /etc/httpd/conf.d/phpMyAdmin.conf |
找到两个directory的权限设置,Allow from 改成All
<Directory /usr/share/phpMyAdmin/>
OrderDeny,Allow
DenyfromAll
Allowfrom127.0.0.1
AllowfromAll
</Directory>
<Directory/usr/share/phpMyAdmin/setup/>
OrderDeny,Allow
DenyfromAll
Allowfrom127.0.0.1
AllowfromAll
</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 |
GeneratingRSAprivatekey,1024bitlongmodulus
............++++++
............++++++
eis65537(0x10001)
用 server.key 生成证书签署请求 CSRopenssl req -new -key server.key -out server.csr |
Country Name:两个字母的国家代号
StateorProvinceName:省份名称
LocalityName:城市名称
OrganizationName:公司名称
OrganizationalUnitName:部门名称
CommonName:你的姓名
EmailAddress:地址
至于'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 |
找到如下位置,修改路径
# Server Certificate:
#PointSSLCertificateFileataPEMencodedcertificate.If
#thecertificateisencrypted,thenyouwillbepromptedfora
#passphrase.Notethatakill-HUPwillpromptagain.Anew
#certificatecanbegeneratedusingthegenkey(1)command.
SSLCertificateFile/etc/pki/tls/certs/localhost.crt
#ServerPrivateKey:
#Ifthekeyisnotcombinedwiththecertificate,usethis
#directivetopointatthekeyfile.Keepinmindthatif
#you'vebothaRSAandaDSAprivatekeyyoucanconfigure
#bothinparallel(toalsoallowtheuseofDSAciphers,etc.)
SSLCertificateKeyFile /etc/pki/tls/private/localhost.keyOK
service httpd restart |
一切都搞定拉~~
整个过程我们不需要修改/etc/httpd/conf/httpd.conf 这就是版本高了的好处阿~