apache(2)-linux环境下apache-httpd编译安装
https://httpd.apache.org/download.cgi#apache24
1. 下载, 上传至服务器的/opt/目录
2. 前提:需要安装apr,apr-util,pcre,分别下载,然后编译安装。
参考:https://www.cnblogs.com/yiyaxuan/p/12516938.html
3. 开始进行 make 编译和make install 安装
[root@localhost httpd-2.4.43]# cd /opt/
[root@localhost httpd-2.4.43]# cd httpd-2.4.43
[root@localhost httpd-2.4.43]# ./configure --prefix=/usr/local/apache-2.4.3
遇到报错:
再次尝试下,编译安装的时候加上apr-util:
[root@localhost httpd-2.4.43]# ./configure --prefix=/usr/local/apache-2.4.3 --with-apr-util=/usr/local/apr-util --with-apr=/usr/local/apr 成功了!
[root@localhost httpd-2.4.43]# make && make install
4.开始启动httpd
[root@localhost httpd-2.4.43]# ./httpd
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globa 意思是设置severname,在配置文件中设置为localhost即可。也可以加入系统服务。
解决方法:
1.先找到apache-httpd的配置文件在哪?
apache-httpd的配置文件在哪?
[root@localhost conf]# pwd
/usr/local/apache-2.4.3/conf
[root@localhost conf]# vi httpd.conf
然后修改此文件
2.修改完毕后
启动httpd:
方法1: /usr/local/apache-2.4.3/bin/httpd -k start
方法2: #cd /usr/local/apache2/bin
#./apachectl start
关闭httpd:
方法1: /usr/local/apache-2.4.3/bin/httpd -k stop
方法2: #cd /usr/local/apache2/bin
#./apachectl stop
重启httpd:
方法1: /usr/local/apache-2.4.3/bin/httpd -k restart
方法2: #cd /usr/local/apache2/bin
#./apachectl restart
sudo '/usr/local/apache-2.4.3/bin/apachectl' -k stop 因为我把apache-httpd安装在了/usr/local/apache-2.4.3
[root@localhost httpd-2.4.43]# ./httpd -S AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message VirtualHost configuration: ServerRoot: "/usr/local/apache-2.4.3" Main DocumentRoot: "/usr/local/apache-2.4.3/htdocs" Main ErrorLog: "/usr/local/apache-2.4.3/logs/error_log" Mutex default: dir="/usr/local/apache-2.4.3/logs/" mechanism=default Mutex mpm-accept: using_defaults PidFile: "/usr/local/apache-2.4.3/logs/httpd.pid" Define: DUMP_VHOSTS Define: DUMP_RUN_CFG User: name="daemon" id=2 Group: name="daemon" id=2 [root@localhost httpd-2.4.43]# pwd /opt/httpd-2.4.43 [root@localhost httpd-2.4.43]#
5.安装成功后,配置参数修改:
#vi /usr/local/apache/conf/httpd.conf
Listen 80 //apache默认端口,可以修改
DocumentRoot "/home/mahaibo/apache/htdocs" //用户默认访问的apache目录
//日志输出的2种格式
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog logs/access_log common //访问日志:access_log的输出采用common格式
6、网站的测试:
网站放在/usr/local/apache2/htdocs目录下
在IE中通过http://localhost:80
如果看到页面中显示“It works!”字样,则代表Apache验证通过。
如果网站的index后缀是PHP格式的,则要修改httpd.conf配置文件(/usr/local/apache2/conf),在DirectoryIndex增加 index.php。
# # DirectoryIndex: sets the file that Apache will serve if a directory# is requested.#<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
7、网站的安全加固:
-
修改文件的所有者和所有组
cd /usr/local/apache
chown -R nobody:root htdocs -
修改apache下所有文件权限
chmod -R 755 *
8、apache的默认重要配置信息如下:
配置文件:/usr/local/apache2/httpd/httpd.conf
服务器的根目录:/usr/local/apache2/htdocs
访问日志文件:/var/log/httpd/access_log
错误日志文件:/var/log/httpd/error_log
运行apache的用户:apache
运行apache的组:apache
端口:80
模块存放路径:/usr/lib/httpd/modules
9、安装apache补充说明
安装apache2 , ./configure ;make;make install。安装完毕后却不能找到mod_proxy和mod_rewrite模块,主要原因是APACHE2.2默认的安装选项是最小化的安装,一些扩展模块在默认的状态下都没有被安装,如果需要要在./configure后用参数指定,比方要用到mod_proxy 和 mod_rewrite两个模块进行实验,所以命令行是:./configure --enable-mods-shared='proxy proxy_ajp proxy_balancer proxy_connect proxy_ftp proxy_http proxy_rewrite'。这个配置不仅指定了这些模块,同时也默认安装其他最小项。这样配置完后make和make install后,mod_proxy和mod_rewrite两个模块都能找到了