云计算学习路线教程大纲课件: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
[[email protected] ~]# yum -y install httpd
[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd
网站主目录建立测试页:
[[email protected] ~]# vim /var/www/html/index.html
tianyun
[[email protected] ~]# vim /var/www/html/2.php
<?php
phpinfo();
?>
192.168.31.154/index.html
[[email protected] ~]# sed -ri ‘/^SELINUX=/cSELINUX=disabled‘ /etc/selinux/config
[[email protected] ~]# setenforce 0
[[email protected] ~]# firewall-cmd --permanent --add-service=http
[[email protected] ~]# firewall-cmd --permanent --add-service=https
[[email protected] ~]# firewall-cmd --reload
三、安装PHP
[[email protected] ~]# yum -y install php //php作为Apache的模块
[[email protected] ~]# ll /etc/httpd/modules/libphp5.so
-rwxr-xr-x. 1 root root 4588368 Jun 24 2015 /etc/httpd/modules/libphp5.so
[[email protected] ~]# ll /etc/httpd/conf.d/php.conf
-rw-r--r--. 1 root root 691 Jun 24 2015 /etc/httpd/conf.d/php.conf
[[email protected] ~]# systemctl restart httpd
192.168.31.154/2.php
四、安装Mariadb
[[email protected] ~]# yum -y install mariadb-server mariadb
[[email protected] ~]# systemctl start mariadb.service
[[email protected] ~]# systemctl enable mariadb.service
[[email protected] ~]# mysql_secure_installation //提升mariadb安全 [可选]
Set root password? [Y/n]
New password: 123
Re-enter new password: 123
[[email protected] ~]# mysql -uroot -p123 //登录mariadb测试
MariaDB [(none)]> \q
[[email protected] ~]# rm -rf /var/www/html/*
[[email protected] ~]# vim /var/www/html/index.php
<?php
$link=mysql_connect(‘localhost‘,‘root‘,‘123‘);
if ($link)
echo "Successfuly";
else
echo "Faile";
mysql_close();
?>
测试结果: php无法连接mysql
五、并配置php连接Mariadb
[[email protected] ~]# yum -y install php-mysql
[[email protected] ~]# php -m //查看php有哪些扩展
[PHP Modules]
mysql
mysqli
[[email protected] ~]# systemctl restart httpd
六、Apache基本配置
[[email protected] ~]# 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 //站点默认主目录
<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:
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
[[email protected] ~]# service mysqld restart
[[email protected] ~]# mysql
mysql> update mysql.user set password=password("456") where user="root" and host="localhost";
mysql> flush privileges;
mysql> \q
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
#skip-grant-table
[[email protected] ~]# service mysqld restart
原文地址:https://blog.51cto.com/14489558/2444220