CentOS 6下搭建Apache+MySQL+PHP+SSL
網(wǎng)上的一些文章都已經(jīng)比較老了,現(xiàn)在版本高了之后,其實配置是很省力的(不考慮什么負載的話)
分享全過程,出了文中提到的安裝epel rpmfushion 源指令不同外,其他的過程也適用與Centos 5
1.安裝CentOS 6 ,可以選擇最小安裝,也可以安裝桌面
2.升級系統(tǒng)
yum update3.安裝mysql,并設(shè)置mysql開機自啟動,同時啟動mysql
yum install mysql yum install mysql-server chkconfig --levels 35 mysqld on service mysqld start4.配置mysql的root密碼
mysql_secure_installation
Enter current password for root (enter for none): ( 回車)
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] (Y)
New password: (123456)
Re-enter new password: (123456)
Password updated successfully!
Reloading privilege tables..
?... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.? This is intended only for testing, and to make the installation
go a bit smoother.? You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n]
(是否移出數(shù)據(jù)庫的默認帳戶,如果移出,那么在終端中直接輸入mysql是會提示連接錯誤的)Y
Normally, root should only be allowed to connect from 'localhost'.? This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n]
(是否禁止root的遠程登錄)Y
By default, MySQL comes with a database named 'test' that anyone can
access.? This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
5.安裝apache,并設(shè)置開機啟動
yum install httpd chkconfig --levels 35 httpd on service httpd start這時候可以測試apache是否正常工作
直接瀏覽器訪問localhost應(yīng)該沒問題,但是如果別的機子訪問不了的話,是因為防火墻的關(guān)系,配置防火墻
(后面的ssl還會有這個問題的)
6.安裝php
yum install phpyum 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
首先先給系統(tǒng)安裝epel 和rpmfushion兩個軟件大倉庫
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如果是centos 5 的話執(zhí)行下面
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安裝完成后還需要配置一下訪問權(quán)限,使得出了本機外,其他機子也能訪問phpMyAdmin
vi /etc/httpd/conf.d/phpMyAdmin.conf找到兩個directory的權(quán)限設(shè)置,Allow from 改成All
<Directory /usr/share/phpMyAdmin/>
?? Order Deny,Allow
?? Deny from All
?? Allow from 127.0.0.1
?? Allow from All
</Directory>
<Directory /usr/share/phpMyAdmin/setup/>
?? Order Deny,Allow
?? Deny from All
?? Allow from 127.0.0.1
?? Allow from All
</Directory>
重啟服務(wù)器
service httpd restart測試localhost/phpMyAdmin
用戶名密碼:root 123456
OK~ LAMP搭建完畢,
8.搭建SSL,讓apache支持https
yum install mod_ssl其實安裝完這個模塊后,重啟完apache 就可以用https://localhost測試了,因為他創(chuàng)建了默認的證書
在/etc/pki/tls下
當然我們也可以用openssl創(chuàng)建自己的證書
yum install openssl生成證書文件
創(chuàng)建一個rsa私鑰,文件名為server.key
Generating RSA private key, 1024 bit long modulus
............++++++
............++++++
e is 65537 (0x10001)
用 server.key 生成證書簽署請求 CSR
Country Name:兩個字母的國家代號
State or Province Name:省份名稱
Locality Name:城市名稱
Organization Name:公司名稱
Organizational Unit Name:部門名稱
Common Name:你的姓名
Email Address:地址
至于 'extra' attributes 不用輸入.直接回車
生成證書CRT文件server.crt。
修改ssl.conf指定我們自己生成的證書
vi /etc/httpd/conf.d/ssl.conf找到如下位置,修改路徑
#?? Server Certificate:
# Point SSLCertificateFile at a PEM encoded certificate.? If
# the certificate is encrypted, then you will be prompted for a
# pass phrase.? Note that a kill -HUP will prompt again.? A new
# certificate can be generated using the genkey(1) command.
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
#?? Server Private Key:
#?? If the key is not combined with the certificate, use this
#?? directive to point at the key file.? Keep in mind that if
#?? you've both a RSA and a DSA private key you can configure
#?? both in parallel (to also allow the use of DSA ciphers, etc.)
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
OK
service httpd restart一切都搞定拉~~
整個過程我們不需要修改/etc/httpd/conf/httpd.conf 這就是版本高了的好處阿~
轉(zhuǎn)載于:https://www.cnblogs.com/cryinstall/archive/2011/09/25/2189900.html
總結(jié)
以上是生活随笔為你收集整理的CentOS 6下搭建Apache+MySQL+PHP+SSL的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [读书笔记]TCP/IP详解V1读书笔记
- 下一篇: 我的Google Adsense帐户被关