httpd主配置文件/usr/local/apache2.4/conf/httpd.confphp
vim /usr/local/apache2.4/conf/httpd.conf //修改如下4个地方。 ServerName //删除井号便可。 Require all denied //<Directory />下面的这个参数的denied改为granted。 AddType application/x-httpd-php .php //在AddType application/x-gzip .gz .tgz下增长一行。 DirectoryIndex index.html index.php //在DirectoryIndex index.html增长index.php参数。 /usr/local/apache2.4/bin/apachectl -t //检查配置文件语法是否正确。 /usr/local/apache2.4/bin/apachectl start //启动服务。
修改完配置文件后,可先用/usr/local/apache2.4/bin/apachectl graceful 从新加载下配置文件,不会关闭服务。html
netstat -lntp curl localhost //测试apache是否正常。 vim /usr/local/apache2.4/htdocs/test.php //建立测试php页面,增长以下内容。 <?php phpinfo(); ?> curl localhost/test.php //测试php是否正常。
apache之默认虚拟机linux
一台服务器能够访问多个网站,每一个网站都是一个虚拟主机 概念:域名(主机名)、DNS、解析域名、hosts 任何一个域名解析到这台机器,均可以访问的虚拟主机就是默认虚拟主机 vim /usr/local/apache2.4/conf/httpd.conf //搜索httpd-vhost,去掉#开启虚拟主机
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //改成以下,定义多个虚拟主机 <VirtualHost *:80> ServerAdmin admin@aminglinux.com //邮箱地址,若是服务器有任何问题将发信到这个地址 DocumentRoot "/data/wwwroot/aming.com" //网站文件存放的根目录 ServerName aming.com //网站域名, 须要跟 DNS 指向的域名一致 ServerAlias www.aming.com //网站别名 ErrorLog "logs/aming.com-error_log" //错误日志 CustomLog "logs/aming.com-access_log" common //访问日志 </VirtualHost> <VirtualHost *:80> DocumentRoot "/data/wwwroot/www.abc.com"; ServerName www.abc.com ServerAlias www.aming.com //网站别名 ErrorLog "logs/abc.com-error_log" //错误日志 CustomLog "logs/abc.com-access_log" common //访问日志 </VirtualHost>
测试下配置文件语法,及生效配置文件apache
/usr/local/apache2.4/bin/apachectl –t /usr/local/apache2.4/bin/apachectl graceful
建立相应的网站目录和网页vim