Apache服务器的编译安装和 LAMP 环境的构建

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
云数据库 RDS MySQL Serverless,价值2615元额度,1个月
简介:

    Apache服务器的编译安装和 LAMP 环境的构建 
 

以前在做实验的过程中总结和写的一些教程的一些资料,一直没时间发布到博客上面,五一到了,终于有点时间发布啦!关于Linux上面还会有RHCE系列的学习笔记发表

制作人:wqmsl

一、编译安装过程: 
1、制作光盘并挂载光盘,然后将包复制到/root目录下: 
[root@cisco ~]# cd /root 
[root@cisco ~]# ls 
abc                  login.txt 
anaconda-ks.cfg       mysql-standard-4.1.7-pc-linux-i686.tar.gz 
httpd-2.0.52.tar.gz     php-4.3.9.tar.gz 
install.log           phpBB-2.0.21.tar.gz 
install.log.syslog 
2、解压缩 
[root@cisco ~]# tar -zxvf httpd-2.0.52.tar.gz -C /usr/local/src 
[root@cisco ~]# cd /usr/local/src/ 
[root@cisco src]# ls 
httpd-2.0.52 
3、编译前准备: 
[root@cisco src]# cd httpd-2.0.52/ 
[root@cisco httpd-2.0.52]# ls 
ABOUT_APACHE      CHANGES        InstallBin.dsp  os 
acconfig.h        config.layout  LAYOUT          README 
acinclude.m4      configure      libhttpd.dsp    README.platforms 
Apache.dsp        configure.in   LICENSE         server 
Apache.dsw        docs           Makefile.in     srclib 
apachenw.mcp.zip  emacs-style    Makefile.win    support 
build             httpd.spec     modules         test 
BuildBin.dsp      include        NOTICE          VERSIONING 
buildconf         INSTALL        NWGNUmakefile 
[root@cisco httpd-2.0.52]# ./configure --prefix=/usr/local/apache2 \ 
¾  --enable-so --enable-rewrite 
4、编译: 
[root@cisco httpd-2.0.52]# make 
5、安装: 
[root@cisco httpd-2.0.52]# make install 
二、系统个人主页的演示: 
1、创建用户 
2、在用户的家目录下创建 public_html 目录,然后创建 index.html 主页内容 
3、启动 apache 服务器 
[root@cisco public_html]# /usr/local/apache2/bin/apachectl start 
4、然后 windows主机访问,用浏览器,发现报权限的错误 
http://192.168.20.1/~cisco/
5、更改用户家目录的权限,给其他用户执行权限即可 
批注 [l1]: 规定安装目录 
批注 [l2]: 允许动态模块加载
批注 [l3]: 可以使用重写功能
www.wqmsl.cn三、虚拟主机的演示: 
1、修改主配置文件: 
[root@cisco sina]# vi /usr/local/apache2/conf/httpd.conf 
NameVirtualHost 192.168.20.1 
<VirtualHost 192.168.20.1> 
    servername  www.baidu.com 
    documentroot  /baidu 
</virtualhost> 
<virtualhost  192.168.20.1> 
   servername  www.sina.com 
   documentroot  /sina 
</virtualhost> 
2、创建目录下的首页文件/baidu/index.html   /sina/index.html 
3、用 windows主机访问即可,没有 dns 可以用 hosts 文件来测试 
四、LAMP 环境的搭建 
1、先有 Linux 操作系统 
2、搭建 apache 服务器 
3、搭建 mysql 数据库: 
创建 mysql 用户和用户组 
[root@cisco sina]# groupadd -g 200 mysql 
[root@cisco sina]# useradd -u 200 -g mysql -d /usr/local/mysql/data -M mysql 
[root@cisco sina]# id mysql 
uid=200(mysql) gid=200(mysql) groups=200(mysql) 
解压缩 mysql 数据库文件 
[root@cisco ~]# tar zxvf mysql-standard-4.1.7-pc-linux-i686.tar.gz -C /usr/local/ 
[root@cisco ~]# cd /usr/local/ 
[root@cisco local]# ls 
apache2  etc    include  libexec                             sbin   src 
bin      games  lib       mysql-standard-4.1.7-pc-linux-i686  share 
[root@cisco local]# ln -s mysql-standard-4.1.7-pc-linux-i686 mysql 
[root@cisco local]# cd mysql 
[root@cisco mysql]# ls 
bin        docs               lib         scripts        tests 
configure  EXCEPTIONS-CLIENT  man         share 
COPYING    include            mysql-test  sql-bench 
data        INSTALL-BINARY     README      support-files 
建立用到的库文件并更改权限 
[root@cisco mysql]# mkdir /var/lib/mysql 
[root@cisco local]# chown -R mysql:mysql /var/lib/mysql/ 
[root@cisco local]# chown -R mysql:mysql /usr/local/mysql-standard-4.1.7-pc-linux-i686/ 
创建 mysql 数据库的配置文件 
[root@cisco lib]# cd /usr/local/mysql 
[root@cisco mysql]# cp support-files/my-medium.cnf    /etc/my.cnf 
批注 [l4]: 启动一个虚拟主机
批注 [l5]: 添加域名 
批注 [l6]: 文件根目录 
批注 [l7]: 组ID必须是200
批注 [l8]: 用户ID必须是200
批注 [l9]: 家目录必须是这个
批注 [l10]: 不按默认安装 
批注 [l11]: 解压的目录必须
是这个 
批注 [l12]: 目的是创建
mysql的家目录 
批注 [l13]: 可以看到家目录
已经创建 
批注 [l14]: 配置文件目录 初始化数据库服务器: 
[root@cisco mysql]# cd /usr/local/mysql 
[root@cisco mysql]# ls 
bin        docs               lib          scripts         tests 
configure  EXCEPTIONS-CLIENT  man         share 
COPYING    include            mysql-test  sql-bench 
data       INSTALL-BINARY     README      support-files 
[root@cisco mysql]# ./scripts/mysql_install_db 
更改初始化数据库产生的家目录文件 
[root@cisco mysql]# cd /usr/local/mysql/data/ 
[root@cisco data]# ll 
total 116 
-rw-rw----  1 root  root   8835 Jun 24 11:17 cisco-bin.000001 
-rw-rw----  1 root  root  69239 Jun 24 11:17 cisco-bin.000002 
-rw-rw----  1 root  root     38 Jun 24 11:17 cisco-bin.index 
drwxr-x---  2 mysql mysql  4096 Jun 24 11:17 mysql 
drwxr-x---  2 mysql mysql  4096 Oct 24  2004 test 
[root@cisco data]# chown -R mysql:mysql /usr/local/mysql/data/ 
[root@cisco data]# ll 
total 116 
-rw-rw----  1 mysql mysql  8835 Jun 24 11:17 cisco-bin.000001 
-rw-rw----  1 mysql mysql 69239 Jun 24 11:17 cisco-bin.000002 
-rw-rw----  1 mysql mysql    38 Jun 24 11:17 cisco-bin.index 
drwxr-x---  2 mysql mysql  4096 Jun 24 11:17 mysql 
drwxr-x---  2 mysql mysql  4096 Oct 24  2004 test 
启动 mysql 数据库 
[root@cisco data]# /usr/local/mysql/bin/safe_mysqld --user=mysql & 
[1] 322 
[root@cisco data]# Starting mysqld daemon with databases from /usr/local/mysql/data 
 
给数据库管理员设定密码,并登陆数据库,创建一个新数据库 
[root@cisco data]# /usr/local/mysql/bin/mysqladmin -u root password '123' 
[root@cisco data]# /usr/local/mysql/bin/mysql -u root -p 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g. 
Your MySQL connection id is 2 to server version: 4.1.7-standard-log 
 
Type 'help;' or '\h' for help. Type '\c' to clear the buffer. 
 
mysql> show databases; 
+----------+ 
| Database | 
+----------+ 
| mysql    | 
批注 [l15]: 初始化名令 
批注 [l16]: 就是这三个文件| test     | 
+----------+ 
2 rows in set (0.00 sec) 
 
mysql> create database phpbb; 
Query OK, 1 row affected (0.00 sec) 
 
mysql> show databases; 
+----------+ 
| Database | 
+----------+ 
| mysql    | 
| phpbb    | 
| test     | 
+----------+ 
3 rows in set (0.00 sec) 
 
mysql> exit 
4、搭建 php 环境 
[root@cisco php-4.3.9]# tar zxvf php-4.3.9.tar.gz -C /usr/local/src 
[root@cisco php-4.3.9]# cd /usr/local/src 
[root@cisco php-4.3.9]# ./configure --prefix=/usr/local/php4 \ 
> --with-apxs2=/usr/local/apache2/bin/apxs \ 
> --with-mysql=/usr/local/mysql \ 
> --with-config-file-path=/usr/local/php4 
编译准备过程中会报错,缺少 lex命令, 
configure: error: cannot find output from lex; giving up 
安装 lex 命令 
[root@cisco RPMS]# rpm -ivh flex-2.5.4a-33.i386.rpm 
warning: flex-2.5.4a-33.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e 
Preparing...                ########################################### [100%] 
   1:flex                   ########################################### [100%] 
又会报错: 
configure: error: Try adding --with-zlib-dir=<DIR>. Please check config.log for more 
information. 
安装 zlib库 
[root@cisco RPMS]# rpm -ivh zlib-devel-1.2.1.2-1.i386.rpm 
warning: zlib-devel-1.2.1.2-1.i386.rpm: V3 DSA signature: NOKEY, key ID db42a60e 
Preparing...                ########################################### [100%] 
   1:zlib-devel             ########################################### [100%] 
重新执行命令,并编译和安装 
创建 PHP配置文件: 
[root@cisco php-4.3.9]# cp php.ini-dist /usr/local/php4/php.ini 
批注 [l17]: 作为论坛演示的
数据库使用 
批注 [l18]: 指定安装目录 
批注 [l19]: 指定php 为
apache服务器提供的模块的
安装位置 
批注 [l20]: 设置 mysql服务
器程序的安装位置 
批注 [l21]: 设置php 程序的
配置文件所在的位置 5、修改 apache 的配置文件并重新启动: 
[root@cisco php-4.3.9]# vi /usr/local/apache2/conf/httpd.conf 
LoadModule php4_module        modules/libphp4.so 
AddType application/x-httpd-php  .php 
DirectoryIndex index.html index.html.var index.php 
[root@cisco php-4.3.9]# /usr/local/apache2/bin/apachectl restart 
httpd: Could not determine the server's fully qualified domain name, using 192.168.20.1 for 
ServerName 
6、创建测试文件: 
[root@cisco php-4.3.9]# vi /usr/local/apache2/htdocs/test.php 
<?php 
phpinfo(); 
?> 
7、搭建论坛 
~[root@cisco ~]# tar zxvf phpBB-2.0.21.tar.gz -C /usr/local/apache2/htdocs/ 
[root@cisco ~]# cd /usr/local/apache2/htdocs/ 
[root@cisco htdocs]# ls 
apache_pb2_ani.gif       index.html.et             index.html.pt-br 
apache_pb2.gif           index.html.fr             index.html.ru.cp-1251 
apache_pb2.png           index.html.he.iso8859-8   index.html.ru.cp866 
apache_pb.gif            index.html.hr.iso8859-2   index.html.ru.iso-ru 
apache_pb.png            index.html.it             index.html.ru.koi8-r 
index.html.ca            index.html.ja.iso2022-jp  index.html.ru.utf8 
index.html.cz.iso8859-2  index.html.ko.euc-kr      index.html.sv 
index.html.de            index.html.lb.utf8        index.html.var 
index.html.dk            index.html.nl             index.html.zh-cn.gb2312 
index.html.ee            index.html.nn             index.html.zh-tw.big5 
index.html.el            index.html.no              phpBB2 
index.html.en            index.html.po.iso8859-2   test.php 
index.html.es            index.html.pt 
[root@cisco htdocs]# chown -R nobody:nobody phpBB2/ 
进入图形界面安装,安装完成后要删除一些文件 
[root@cisco phpBB2]# rm -rf install/ contrib/ 
这样就可以使用了 
http://192.168.20.1/phpBB2



     本文转自 wqmsl 51CTO博客,原文链接:http://blog.51cto.com/wqmsl/307851,如需转载请自行联系原作者



相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5天前
|
弹性计算 Shell Apache
某时间段访问apache 服务器的请求IP
【4月更文挑战第29天】
10 2
|
5天前
|
弹性计算 Shell Apache
|
11天前
|
运维 Apache 数据安全/隐私保护
CentOS6.5搭建SVN服务器(Apache+SVN)
CentOS6.5搭建SVN服务器(Apache+SVN)
|
15天前
|
网络安全 API Apache
本地快速部署Apache服务器并使用内网穿透实现远程访问
本地快速部署Apache服务器并使用内网穿透实现远程访问
|
15天前
|
存储 Java 网络安全
ZooKeeper【搭建 03】apache-zookeeper-3.6.0 伪集群版(一台服务器实现三个节点的ZooKeeper集群)
【4月更文挑战第10天】ZooKeeper【搭建 03】apache-zookeeper-3.6.0 伪集群版(一台服务器实现三个节点的ZooKeeper集群)
28 1
|
18小时前
|
弹性计算
阿里云ECS使用体验
在申请高校学生免费体验阿里云ECS云服务器后的一些使用体验和感受。
|
3天前
|
存储 弹性计算 固态存储
阿里云服务器CPU内存配置详细指南,如何选择合适云服务器配置?
阿里云服务器配置选择涉及CPU、内存、公网带宽和磁盘。个人开发者或中小企业推荐使用轻量应用服务器或ECS经济型e实例,如2核2G3M配置,适合低流量网站。企业用户则应选择企业级独享型ECS,如通用算力型u1、计算型c7或通用型g7,至少2核4G配置,公网带宽建议5M,系统盘可选SSD或ESSD云盘。选择时考虑实际应用需求和性能稳定性。
|
3天前
|
弹性计算 运维 安全
阿里云ecs使用体验
整了台服务器部署项目上线
|
4天前
|
弹性计算
阿里云ECS的使用心得
本文主要讲述了我是如何了解到ECS,使用ECS的一些经验,以及自己的感悟心得
|
5天前
|
域名解析 弹性计算 Linux
阿里云购买云服务器、注册域名、备案及绑定图文教程参考
本文为大家介绍了2024年购买阿里云服务器和注册域名,绑定以及备案的教程,适合需要在阿里云购买云服务器、注册域名并备案的用户参考,新手用户可通过此文您了解在从购买云服务器到完成备案的流程。
阿里云购买云服务器、注册域名、备案及绑定图文教程参考

热门文章

最新文章