Ubuntu配置Apache
系统环境: Ubuntu 10.10(linux-kernel 2.6.35-22)
安装版本: httpd-2.4.34.tar.gz
Apache httpd 官网:http://httpd.apache.org
apr 官网:http://apr.apache.org/download.cgi
pcre 官网:http://www.pcre.org
CentOS 安装配置 httpd
下载 apr-1.6.3.tar.gz 、apr-util-1.6.1.tar.gz 、apr-iconv-1.2.2.tar.gz 、pcre-8.42.tar.gz 、httpd-2.4.34.tar.gz
注意: --prefix=/opt/apr 后不要添加 / ,安装时会自动认为是目录或路径了,否则会是 /opt/apr//xxx
1. 安装 apr
tar zxvf apr-1.6.3.tar.gz
cd apr-1.6.3
./configure --prefix=/usr/local/apr
make && make install
2. 安装 apr-util
tar zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
3. 安装 pcre
tar zxvf pcre-8.42.tar.gz
cd pcre-8.42
./configure --prefix=/usr/local/pcre
make && make install
4. 清理环境,重新安装httpd
cd httpd-2.4.34
make clean install
make clean
然后,指定环境路径,重新安装 httpd
cd httpd-2.4.34
./configure --prefix=/usr/local/httpd --enable-module=all --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make && make install
Ubuntu 安装配置 httpd
1、下载 httpd
下载 httpd-2.4.2.tar.gz (最新版 httpd-2.4.34.tar.gz)
2、解压 httpd
tar -zxvf httpd-2.4.2.tar.gz
3、安装 httpd
进入解压后的目录
cd httpd-2.4.2
创建 /opt/ httpd-2.4.2-server
sudo mkdir -p /opt/ httpd-2.4.2-server
安装到指定目录 /opt/httpd-2.4.2-server
sudo ./configure --prefix=/opt/ httpd-2.4.2-server/ --enable-module=so
上图中,出现了 APR not found 错误!
在安装Apache过程中,依次遇到的错误与解决方法如下:
问题1: APR not found
a、下载 apr-1.4.6.tar.gz ( 官方网址 )
b、解压 apr
tar -zxvf apr-1.4.6.tar.gz
cd apr-1.4.6
c、安装 apr
sudo mkdir -p /opt/apr
sudo ./configure --prefix=/opt/apr
sudo make
sudo make install
问题2: APR-util not found
a、下载 apr-util-1.4.1.tar.gz ( 官方网址 )
b、解压 apr-util
tar -zxvf apr-util-1.4.1.tar.gz
cd apr-util-1.4.1
c、安装 apr
sudo mkdir -p /opt/apr-util
sudo ./configure --prefix= /opt/apr-util --with-apr = /opt/apr
sudo make
sudo make install
问题3: pcre-config for libpcre not found
a、下载 pcre-8.31.tar.gz ( 官方网址, 注意:不是 pcre2)
b、解压 pcre
tar -zxvf pcre-8.31.tar.gz
cd pcre-8.31
c、安装 apr
sudo mkdir -p /opt/pcre
sudo ./configure --prefix= /opt/pcre
sudo make
sudo make install
问题4: 清理编译后重新编译
sudo make clean; make
sudo make clean install
完成上述准备后,再次安装 httpd ( 附带参数 ):
sudo ./configure --prefix=/opt/httpd-2.4.2-server/ --enable-module=all --with-apr=/opt/apr --with-apr-util=/opt/apr-util --with-pcre=/opt/pcre
sudo make
sudo make install
手动启动apache
sudo ./bin/apachectl start // stop, restart
httpd 开机启动脚本
第一步:复制脚本
cp /usr/local/httpd-2.4.34-server/bin/apachectl /etc/init.d/httpd
第二步:注释说明
vim /etc/init.d/httpd
在第一行#!/bin/sh下增加两行文字
# chkconfig: 35 70 30 这里的35指的是在3和5级别开启该服务 70是开机启动服务在70位,30是关机关闭服务在30位,一般启动服务的顺序和关闭顺序的和100。
# description: The Apache HTTP Server 描述信息 这里的#不再是注释符,而是服务列表中的特殊用法。
chkconfig 解释:
# chkconfig: 2345 10 90 其中 2345是设为要启动的运行级别,10是启动优先级,90是杀死进程的优先级,谁优先谁先挂的意思
2345 表示系统运行级别,Linux下系统服务的运行级别分别有0~6个级别,共7个级别,分别代表的含义如下:
0-表示关机
1-单用户模式
2-无网络连接的多用户命令行模式
3-有网络连接的多用户命令行模式
4-不可用
5-带图形界面的多用户模式
6-重新启动
10 90 后两位分别代表启动/停止优先级,优先级范围是0~100,数字越大,优先级越低。
# chkconfig aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
添加后的效果:
#!/bin/sh # # chkconfig: 35 70 30 # The Apache HTTP Server
第三步:开机启动
chkconfig --level 35 httpd on
或
chkconfig httpd on
解释说明:
chkconfig –list 列出所有的系统服务
chkconfig –add httpd 增加httpd服务
chkconfig –del httpd 删除httpd服务
chkconfig –level httpd 2345 on 把httpd在运行级别为2、3、4、5的情况下都是on(开启)的状态。
第四步:手动启动
/etc/init.d/httpd start
/etc/init.d/httpd stop
若不喜欢默认开机启动脚本,也可自己写脚本,参考如下:
vim /etc/init.d/myhttpd
#!/bin/bash # # chkconfig: 12345 80 90 # description: The Apache HTTP Server function start_http() { /opt/httpd-2.4.2-server/bin/apachectl start } function stop_http() { /opt/httpd-2.4.2-server/bin/apachectl stop } case "$1" in start) start_http ;; stop) stop_http ;; restart) stop_http start_http ;; *) echo "Usage : start | stop | restart" ;; esac
使其可执行:
chmod +x /etc/init.d/myhttpd
4、验证安装是否成功
1)打开浏览器,输入 http://localhost 或 http://localhost:80 (httpd默认端口是80)
配置成功!
Ubuntu安装php步骤 ,请参考我的博客 Linux 搭建 discuz 论坛
2)打开验证index.php
拷贝php.ini:
sudo cp php.ini-development /opt/php-5.4.15-server/lib/
修改apache httpd.conf:
sudo vi /opt/httpd-2.4.2-server/conf/httpd.conf
在 AddType application/x-gzip .gz .tgz 下面添加以下两行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
如下:
#AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php-source .phps AddType application/x-httpd-php .php
检查 LoadModule php7_module modules/libphp7.so 是否已经添加 libphp7.so文件是否存在(重要、关键,否则php文件无法解析,会是下载文件状态)
LoadModule alias_module modules/mod_alias.so #LoadModule rewrite_module modules/mod_rewrite.so LoadModule php7_module modules/libphp7.so
在 /opt/httpd-2.4.2-server/htdocs/ 目录下,新建一个文件 index.php:
sudo vi /opt/httpd-2.4.2-server/htdocs/index.php
<?php phpinfo(); ?>
在浏览器中,输入网址: http://localhost/index.php,打开以下页面,说明配置php成功
5、配置开机自动启动
1) 复制 /usr/server/apache2/bin/apachectl到/etc/init.d
sudo cp /opt/httpd-2.4.2-server/bin/apachectl /etc/init.d/
2) 设置启动时为默认服务
sudo update-rc.d apachectl defaults
这样,开机就可以自动启动Apache httpd服务了
6、允许异地访问
Apache默认对本机(localhost)访问,为了让其它机器对其访问,需要修改conf/httpd.conf文件
1)修改默认网络端口
#Listen 12.34.56.78:80
Listen 8088 // 为了避免冲突,修改为8088
2)修改管理员邮件地址
#ServerAdmin you@example.com
ServerAdmin yanggang_xxx@163.com
3)修改域名,允许对外访问
#ServerName www.example.com:80
ServerName 172.27.29.14:8088
参考推荐:
configure: error: APR not found (推荐)
Compile Apache 2.4.2 in Solaris 10 in a x86 (Stack OVerflow)
原文: Ubuntu配置Apache
版权所有: 本文系米扑博客原创、转载、摘录,或修订后发表,最后更新于 2018-07-29 09:34:36
侵权处理: 本个人博客,不盈利,若侵犯了您的作品权,请联系博主删除,莫恶意,索钱财,感谢!
转载注明: Ubuntu配置Apache (米扑博客)