# yum -y install httpd
出现Complete!说明安装完成。可以通过httpd -v来查看Apache版本信息。
2、安装PHP
说明:必须先安装Apache然后再安装PHP,不然会出现PHP不被解析,或者网页访问下载文件的情况。出现这种情况需要配置Apache加入PHP模块。
# yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof
(上述的安装可以选择性安装。)
3、接下来就是下载安装OpenSSL了
# yum install mod_ssl openssl
安装成功后,会生成 /etc/httpd/conf.d/ssl.conf 这个文件。接下来
开始倒入证书PS(我的证书是从阿里云申请免费的)
最好把所有证书放在同一个目录下面,方便管理
通过配置ssl.conf中的下面这几个字段实现https
SSLCertificateFile
SSLCertificateKeyFile
SSLCACertificateFile
这时候就会发现通过https://ip就可以访问了,如果证书是自己生成的那么就会出现危险的提示。需要从正规网站申请证书。
扩展知识:
1.申请你的 SSL 证书,这里可以在阿里去免费的 DV SS
2.等待证书签发,签发后下载证书
下载完成后,重命名文件名(为了后面方便配置 Apache)
在你的 Apache 安装目录下新建 cert 文件夹
把上面的三个文件放到该文件夹中
3.接下来先打开 Apache 安装目录下 conf 目录中的 httpd.conf 文件
<span style="font-size:18px;"><VirtualHost 0.0.0.0:443>
DocumentRoot "/data/www/default"
ServerName ding.com
ServerAlias www.ding.com
<Directory /data/www/default>
#AllowOverride伪静态
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /usr/local/apache/conf/ssl/www.ding.com.cer
SSLCertificateKeyFile /usr/local/apache/conf/ssl/www.ding.com.key
SSLCertificateChainFile /usr/local/apache/conf/ssl/www.ding.com_ca.crt
</VirtualHost></span>
<span style="font-size:18px;"><VirtualHost *:80>
ServerName localhost
ServerAlias localhost
DocumentRoot /data/www/default
<Directory /data/www/default>
SetOutputFilter DEFLATE
Options FollowSymLinks
AllowOverride All
Order Deny,Allow
Require all granted
DirectoryIndex index.php index.html index.htm
</Directory>
#强制http转向为https
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}$1 [L,R]
</VirtualHost></span>
说明:
# 添加 SSL 协议支持协议,去掉不安全的协议
SSLProtocol all -SSLv2 -SSLv3
# 修改加密套件如下
SSLCipherSuite HIGH:!RC4:!MD5:!aNULL:!eNULL:!NULL:!DH:!EDH:!EXP:+MEDIUM
SSLHonorCipherOrder on
# 证书公钥配置
SSLCertificateFile cert/a_public.crt
# 证书私钥配置
SSLCertificateKeyFile cert/a.key
# 证书链配置,如果该属性开头有 '#'字符,请删除掉
SSLCertificateChainFile cert/a_chain.crt
4.接下来,重启 Apache (我直接暴力 reboot 重启服务器)
最后,来到阿里云的控制台:
打开 https,完成!