云计算学习路线教程大纲课件:HTTP Server: Apache知识点:
建议使用2.4及以上的版本
========================================================
一、Apache基础
Apache: www.apache.org
软件包: httpd
服务端口: 80/tcp(http) 443/tcp(https,http+ssl)
配置文件: /etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
/etc/httpd/conf.d/welcome.conf //默认测试页面
二、安装Apache
[root@apache ~]# yum -y install httpd
[root@apache ~]# systemctl start httpd
[root@apache ~]# systemctl enable httpd
网站主目录建立测试页:
[root@apache ~]# vim /var/www/html/index.html
tianyun
[root@apache ~]# vim /var/www/html/2.php
phpinfo();
?>
192.168.31.154/index.html
[root@apache ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@apache ~]# setenforce 0
[root@apache ~]# firewall-cmd --permanent --add-service=http
[root@apache ~]# firewall-cmd --permanent --add-service=https
[root@apache ~]# firewall-cmd --reload
三、安装PHP
[root@apache ~]# yum -y install php //php作为Apache的模块
[root@apache ~]# ll /etc/httpd/modules/libphp5.so
-rwxr-xr-x. 1 root root 4588368 Jun 24 2015 /etc/httpd/modules/libphp5.so
[root@apache ~]# ll /etc/httpd/conf.d/php.conf
-rw-r--r--. 1 root root 691 Jun 24 2015 /etc/httpd/conf.d/php.conf
[root@apache ~]# systemctl restart httpd
192.168.31.154/2.php
四、安装Mariadb
[root@apache ~]# yum -y install mariadb-server mariadb
[root@apache ~]# systemctl start mariadb.service
[root@apache ~]# systemctl enable mariadb.service
[root@apache ~]# mysql_secure_installation //提升mariadb安全 [可选]
Set root password? [Y/n]
New password: 123
Re-enter new password: 123
[root@apache ~]# mysql -uroot -p123 //登录mariadb测试
MariaDB [(none)]> \q
[root@apache ~]# rm -rf /var/www/html/*
[root@apache ~]# vim /var/www/html/index.php
$link=mysql_connect('localhost','root','123');
if ($link)
echo "Successfuly";
else
echo "Faile";
mysql_close();
?>
测试结果: php无法连接mysql
五、并配置php连接Mariadb
[root@apache ~]# yum -y install php-mysql
[root@apache ~]# php -m //查看php有哪些扩展
[PHP Modules]
mysql
mysqli
[root@apache ~]# systemctl restart httpd
六、Apache基本配置
[root@tianyun ~]# vim /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd" //安装目录
Listen 80 //监听端口
IncludeOptional conf.d/.conf //包含conf.d下的.conf文件
User apache //运行Apache的用户
Group apache //运行Apache的用户组
DirectoryIndex index.html index.php //设置默认主页
DocumentRoot //站点默认主目录
AllowOverride None
Allow open access:
Require all granted
========================================================
配置进程和线程 针对apache2.2 仅针对面试
prefork MPM //进程模式
StartServers 10 //初始建立的进程数
MinSpareServers 10 //最小空闲的进程数
MaxSpareServers 15 //最大空闲的进程数
ServerLimit 2000 //最大启动的进程数 默认256
MaxClients 2000 //最大并发连接数 默认256
MaxRequestsPerChild 4000 //每个子进程在其生命周期内允许响应的最大请求数,0不限制
worker MPM //线程模式
StartServers 2 //初始建立的进程数
ThreadsPerChild 50 //每个进程建立的线程数
MinSpareThreads 100 //最小空闲的线程数
MaxSpareThreads 200 //最大空间的线程数
MaxClients 2000 //最大的并发访问量(线程)
MaxRequestsPerChild 0 //每个子进程在其生命周期内允许响应的最大请求数,0不限制
========================================================
忘记MySQL密码
MySQL 5.7.5 and earlier:
[root@mysql1 ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
[root@mysql1 ~]# service mysqld restart
[root@mysql1 ~]# mysql
mysql> update mysql.user set password=password("456") where user="root" and host="localhost";
mysql> flush privileges;
mysql> \q
[root@mysql1 ~]# vim /etc/my.cnf
[mysqld]
#skip-grant-table
[root@mysql1 ~]# service mysqld restart