云计算学习路线教程大纲课件: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
<?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
<?PHP
$link=MysqL_connect('localhost','root','123');
if ($link)
echo "Successfuly";
else
echo "Faile";
MysqL_close();
?>
五、并配置PHP连接Mariadb
[root@apache ~]# yum -y install PHP-MysqL
[root@apache ~]# PHP -m //查看PHP有哪些扩展
[PHP Modules]
[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 //设置默认主页
<Directory "/var/www"> //Apache访问控制
AllowOverride None
Allow open access:
Require all granted
</Directory>
========================================================
配置进程和线程 针对apache2.2 仅针对面试
prefork MPM //进程模式
<IfModule prefork.c>
StartServers 10 //初始建立的进程数
MinSpareServers 10 //最小空闲的进程数
MaxSpareServers 15 //最大空闲的进程数
ServerLimit 2000 //最大启动的进程数 默认256
MaxClients 2000 //最大并发连接数 默认256
MaxRequestsPerChild 4000 //每个子进程在其生命周期内允许响应的最大请求数,0不限制
</IfModule>
worker MPM //线程模式
<IfModule worker.c>
StartServers 2 //初始建立的进程数
ThreadsPerChild 50 //每个进程建立的线程数
MinSpareThreads 100 //最小空闲的线程数
MaxSpareThreads 200 //最大空间的线程数
MaxClients 2000 //最大的并发访问量(线程)
MaxRequestsPerChild 0 //每个子进程在其生命周期内允许响应的最大请求数,0不限制
</IfModule>
========================================================
忘记MysqL密码
MysqL 5.7.5 and earlier:
[root@MysqL1 ~]# vim /etc/my.cnf
[MysqLd]
skip-grant-tables
[root@MysqL1 ~]# service MysqLd restart
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