PS:Apache http server 需要依赖 apr、apr-util、pcre,所以要先下载和安装这三个东东。而apr-util和pcre又依赖apr,所以要先安装apr。
步骤:
1、 下载apr、apr-util、pcre、Apache httpserver
地址如下:
apr/ apr-util: http://apr.apache.org/download.cgi
pcre: http://www.pcre.org/
apache http server: http://httpd.apache.org/download.cgi#apache24
2、 将文件上传到服务器(linux)
例如目录:/usr/mytest/source
3、 分别解压四个文件
例如解压到当前目录:
解压apr : tar –vxf apr-1.5.0.tar.gz(在source目录下会多出一个目录apr-1.5.0)
解压apr : tar –vxf apr-util-1.5.3.tar.gz(在source目录下会多出一个目录apr-util-1.5.3)
解压pcre : tar –vxf pcre-8.33.tar.gz(在source目录下会多出一个目录pcre-8.33)
解压Apache http server:tar –vxf httpd-2.4.9.tar.gz(在source目录下会多出一个目录httpd-2.4.9)
PS:注意,我下载的都是tar.gz格式的,如果是其他格式的,请参考linux关于解压方面的相关命令。
4、 安装apr
切换到apr-1.5.0文件夹下,依次执行命令:
(1)./configure--prefix=/usr/mytest /soft/apr (该命令的意思是配置安装文件,指定安装路径为绝对路径)
(2)make (编译)
(3)make install(安装)
5、 安装apr-util
切换到apr-util-1.5.3文件夹下,依次执行命令:
(1)./configure --prefix=/usr/mytest /soft/apr-util --with-apr=/usr/mytest
/soft/apr/bin/apr-1-config
(该命令的意思是配置安装文件,指定安装路径为绝对路径;且需要依赖apr,否则将会出错)
(2)make (编译)
(3)make install(安装)
6、 安装pcre
切换到pcre-8.33文件夹下,依次执行命令:
(1)./configure--prefix=/usr/mytest /soft/pcre --with-apr=/usr/mytest
/soft/apr/bin/apr-1-config
(该命令的意思是配置安装文件,指定安装路径为绝对路径;且需要依赖apr,否则将会出错)
(2)make (编译)
(3)make install(安装)
7、 安装Apache httpserver
切换到httpd-2.4.9文件夹下,依次执行命令:
(1)./configure--prefix=/usr/mytest /soft/httpd
--with-apr=/usr/mytest/soft/apr/bin/apr-1-config
--with-apr-util=/usr/mytest/soft/apr-util/bin/apu-1-config
--with-pcre=/usr/mytest /soft/pcre/bin/pcre-config
(该命令的意思是配置安装文件,指定安装路径为绝对路径;且需要依赖apr/apr-util/pcre,否则将会出错)
(2)make (编译)
(3)make install(安装)
至此安装完成并结束。
8、 启动测试:
(1) 需要首先修改配置文件:(/usr/mytest /soft/httpd/conf/httpd.conf)
ServerName (如127.0.0.1:1025)
Listener (如127.0.0.1:1025)
PS:如果配置文件中Listen定义的是默认的80端口(或1024以下),那么启动Apache将需要root权限以将它绑定在特权端口上。
(2) 切换到/usr/mytest /soft/httpd/bin目录下,
执行:./apachectl –k start
(3) 到浏览器中输入ServerName配置的属性值,得到:It works!
9、 共享服务器使用说明:
在httpd/htdocs 目录下面增加目录、文件等,浏览器中即可查看。
Linux下注册Apache为系统服务
1:
vi /etc/rc.d/rc.local
增加:/usr/local/httpd/bin/apachectl start
2:[注册为Service]
cp /usr/local/httpd/bin/apachectl /etc/rc.d/init.d/httpd
vi httpd
找到:#!/bin/sh
另起一行,增加:
# chkconfig: 35 70 30
# description: Apache
Ok~
然后注册服务:chkconfig --add httpd
----
启动服务:service httpd start
停止服务:service httpd stop
重新启动:service httpd restart
又搜了一下其他的方法:
mysql设为linux服务
cp /usr/local/mysql5/share/mysql/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on
chown mysql:mysql -R /usr/local/mysql5/
service mysqld start
apache设为linux服务
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
在在#!/bin/sh后面加入下面两行
#chkconfig:345 85 15
#description: Start and stops the Apache HTTP Server.
然后
chmod +x /etc/rc.d/init.d/httpd
chkconfig --add httpd