LAMP 指的Linux (操作系统)、 ApacheHTTP 服务器, MySQL (数据库软件) 和PHP (有时也是指Perl 或 Python) 的第一个字母,一般用来建立的web 服务器。
Linux+Apache+Mysql+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案。
其中L代表的就是我们所熟知的Linux系统;A代表的是Apache,Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。同时Apache音译为阿帕奇,是北美印第安人的一个部落,叫阿帕奇族,在美国的西南部。也是一个基金会的名称、一种武装直升机等等;M代表的是MySQL(数据库软件);P代表的是PHP
(有时也是指Perl 或 Python);
使用源码包安装配置LAPM服务平台步骤:
一、Apache安装:
要想安装httpd服务首先需要安装APR,APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。
1)检查并安装yum配置环境。
- #cd /etc/yum.repos.d/
- #wget ftp://172.16.0.1/pub/gls/server.repo--(自己事先准备好的yum源)
- #hwclock -s --同步时间,一定要保证自己的系统时间与硬件时间一致,不然会报错。
- #yum grouplist---检查yum配置环境;
-
#yum -y groupinstall "Development Libraries"---安装yum配置环境;
2)下载编译安装APR:
- #lftp 172.16.0.1
- #cd pub/Sources/new_lamp/
- #get apr-1.4.6.tar.bz2 apr-util-1.4.1.tar.bz2--APR-util是APR 辅助工具;
- #bye
- #tar xf apr-1.4.6.tar.bz2
- #cd apr-1.4.6
- #./buildconf
- #./configure --prefix=/usr/local/apr-------指定apr安装路径;
- #make
- #make install---APR安装完成;
3)编译安装APR-util:
- #cd
- #tar xf apr-util-1.4.1.tar.bz2
- #cd apr-util-1.4.1
- #./buildconf --with-apr=/root/apr-1.4.6--执行apr源码的位置;
- #./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr----指定apr和apr-util的安装路径;
- #make----编译;
-
#make install-----安装,apr-util安装完成;
4)下载编译安装httpd:
- #cd
- #lftp 172.16.0.1
- #cd pub/Sources/new_lamp/
- #get httpd-2.4.2.tar.bz2
- #bye
- #tar xf httpd-2.4.2.tar.bz2
- #cd httpd-2.4.2
- #rpm -q pcre-devel----查看pcre-devel包是否已安装;
- #yum -y install pcre-devel----安装pcre-devel软件包;
- #./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-modules-shared=most
- #make---编译;
- #make install----安装;--------httpd安装完成;
-
#vim /etc/profile--编辑bash环境变量文件;
1)编辑bash环境的配置文件,添加httpd命令路径。
# No core files by default- ulimit -S -c 0 > /dev/null 2>&1
- if [ -x /usr/bin/id ]; then
- USER="`id -un`"
- LOGNAME=$USER
- MAIL="/var/spool/mail/$USER"
- fi
- HOSTNAME=`/bin/hostname`
- HISTSIZE=1000
- if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
- INPUTRC=/etc/inputrc
- fi
- PATH=/usr/local/apache/bin:$PATH ------增加该项,声明httpd位置,使对所有用户均有效;
- export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
2)使用httpd -l命令查看所有模块:
- [root@localhost ~]# httpd -l
- Compiled in modules:
- core.c
- mod_so.c
- http_core.c
- event.c ----httpd2.4版本新特性模块;
-
[root@localhost ~]#
3)启用httpd服务
- [root@localhost bin]# apachectl start
- [root@localhost bin]# netstat -tnlp
- Active Internet connections (only servers)
- Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
- tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN 3310/./hpiod
- tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 2954/portmap
- tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 3688/httpd
- tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 3335/sshd
- tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 3351/cupsd
- tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 3407/sendmail
- tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 3620/sshd
- tcp 0 0 127.0.0.1:6012 0.0.0.0:* LISTEN 4318/sshd
- tcp 0 0 0.0.0.0:636 0.0.0.0:* LISTEN 2998/rpc.statd
- tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN 3315/python
4)编辑/etc/httpd/httpd.conf(apache的配置文件),打开虚拟主机选项
-
DocumentRoot: The directory out of which you will serve your# documents. By default, all requests are taken from this directory, but# symbolic links and aliases may be used to point to other locations.##DocumentRoot "/usr/local/apache/htdocs" -------把该项禁用掉;<Directory "/usr/local/apache/htdocs">
-
# Virtual hosts
-
Include /etc/httpd/extra/httpd-vhosts.conf ----打开虚拟主机选项;
5)编辑/etc/httpd/extra/httpd-vhosts.conf配置文件:
-
#<VirtualHost *:80> -------把下面示例虚拟主机选项禁用掉;
- # ServerAdmin webmaster@dummy-host.example.com
- # DocumentRoot "/usr/local/apache/docs/dummy-host.example.com"
- # ServerName dummy-host.example.com
- # ServerAlias www.dummy-host.example.com
- # ErrorLog "logs/dummy-host.example.com-error_log"
- # CustomLog "logs/dummy-host.example.com-access_log" common
- #</VirtualHost>
- #
- #<VirtualHost *:80>
- # ServerAdmin webmaster@dummy-host2.example.com
- # DocumentRoot "/usr/local/apache/docs/dummy-host2.example.com"
- # ServerName dummy-host2.example.com
- # ErrorLog "logs/dummy-host2.example.com-error_log"
- # CustomLog "logs/dummy-host2.example.com-access_log" common
- #</VirtualHost>
- <VirtualHost *:80> -----------------------增加一下三个虚拟主机,主页面根据自己情况而定;
- ServerName www.magedu.com
- DocumentRoot /web/vhosts/www
- <Directory "/web/vhosts/www">
- Options Indexes
- AllowOverride none
- Require all granted
- </Directory>
- </VirtualHost>
- <VirtualHost *:80>
- ServerName pma.magedu.com
- DocumentRoot /web/vhosts/pma
- </VirtualHost>
6)编辑/etc/man.config文件,将man命令永久生效:
- # Every automatically generated MANPATH includes these fields
- #
- MANPATH /usr/man
- MANPATH /usr/share/man
- MANPATH /usr/local/man
- MANPATH /usr/local/share/man
- MANPATH /usr/X11R6/man
- MANPATH /usr/local/apache/man-----添加man命令路径;
- #
- # Uncomment if you want to include one of these by default
7)让apache的头文件能被访问到:
- #ln -sv /usr/local/apache/include/ /usr/include/
8)开机让httpd服务能进行正常的开启、关闭、重启:
从其它主机上复制httpd开机脚本文件到这台主机上,然后对其进行修改并放到/etc/
- apachectl=/usr/local/apache/bin/apachectl ----改成apachectl所在路径;
- httpd=${HTTPD-/usr/local/apache/bin/httpd}----改成httpd所在路径;
- prog=httpd
- pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid} --改成httpd.pid所在路径;
- lockfile=${LOCKFILE-/var/lock/subsys/httpd}
- RETVAL=0
- STOP_TIMEOUT=${STOP_TIMEOUT-10}
- # check for 1.3 configuration ----把以下14行注释掉,因为我这里用的不是1.3版本的apache;
- #check13 () {
- # CONFFILE=/etc/httpd/conf/httpd.conf
- # GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
- # GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
- # GONE="${GONE}AccessConfig|ResourceConfig)"
- # if LANG=C grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
- # echo
- # echo 1>&2 " Apache 1.3 configuration directives found"
- # echo 1>&2 " please read /usr/share/doc/httpd-2.2.3/migration.html"
- # failure "Apache 1.3 config directives test"
- # echo
- # exit 1
- # fi
- #}
- #
- # The semantics of these two functions differ from the way apachectl does
- # things -- attempting to start while running is a failure, and shutdown
- # when not running is also a failure. So we just do it the way init scripts
- # are expected to behave here.
- start() {
- echo -n $"Starting $prog: "
- # check13 || exit 1 ---把改行注释掉;
- LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && touch ${lockfile}
- return $RETVAL
- #cp httpd /etc/rc.d/init.d/httpd
- #chmod +x /etc/rc.d/init.d/httpd
- #chkconfig --add httpd ---将httpd服务添加到列表中去;
-
# chkconfig httpd on 开机默认启动;
二、mysql编译安装;
- #lftp 172.16.0.1
- #cd pub/Sources/mysql-5.5/
- #get mysql-5.5.24-linux2.6-i686.tar.gz ---下载mysql源码安装包;
- #useradd -r mysql ---创建mysql用户,因为mysql需要普通用户mysql用户运行;
- #id mysql
- #finger mysql
- #tar xf mysql-5.5.24-linux2.6-i686.tar.gz -C /usr/local/ ---必须要解压到/usr/local目录下;
- #创建一个逻辑分区----为了方便存储数据,需要创建逻辑卷,这里我创建的是/dev/sda5;
- #pvcreate /dev/sda5
- # vgcreate myvg /dev/sda5
- #lvcreate -L 1G -n mydata myvg
- #mke2fs -j -L MYDATA /dev/myvg/mydata
- #vim /etc/fstab
- #mkdir /data
- #mount -a
- #mkdir /data/mysql
- #chown mysql:mysql /data/mysql/
- #cd /usr/local/
- #ln -sv mysql-5.5.24-linux2.6-i686 mysql
- #cd mysql
- #chown -R mysql:mysql .
- #scripts/mysql_install_db --datadir=/data/mysql/ --user=mysql ---初始化mysql;
- #cp support-files/my-large.cnf /etc/my.cnf--提供配置文件;
- #vim /etc/my.cnf
- thread_concurrency = 4 如果是双核的就改为4; datadir= /data/mysql --指定数据目录;
- #cp support-files/mysql.server /etc/rc.d/init.d/mysqld ----提供服务启动脚本;
- #chkconfig --add mysqld
- #chkconfig --list mysqld
- #chown -R root . -----为了安全将当前目录的属组和属主改为root;
- #service mysqld start
- #vim /etc/profile-------(PATH=/usr/local/mysql/bin:$PATH) 指定环境变量;
- #export PATH=$PATH:/usr/local/mysql/bin/ -----重新输出使其立即生效;
- #vim /etc/ld.so.conf.d/mysql.conf----指定mysql的库文件/usr/local/mysql/lib
- #ldconfig------通知系统重新生成;
- #ln -sv /usr/local/mysql/include/ /usr/include/mysql---指定mysql的头文件;
- ----mysql安装编译配置完成;
三、php编译安装;
-
#lftp 172.16.0.1
-
#cd pub/Sources/new_lamp/
-
#get php-5.4.4.tar.bz2 ---下载php源码安装包;
-
#bye
-
#tar xf php-5.4.4.tar.bz2
-
#cd php-5.4.4
-
#yum -y groupinstall "X Software Development" ------安装开发库;
-
#lftp 172.16.0.1
-
#cd pub/Sources/nginx/
-
#mget libmcrypt-2.5.7-5.el5.i386.rpm libmcrypt-devel-2.5.7-5.el5.i386.rpm
-
#bye
-
#rpm -ivh libmcrypt-*
-
#./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --编译安装php;
-
#make----编译;
-
#make install ---安装-----此时php已经安装完成;
1)下面整合php和apache:
-
#cp php.ini-production /etc/php.ini
-
#vim /etc/httpd/httpd.conf
-
-
# DirectoryIndex: sets the file that Apache will serve if a directory
-
# is requested.
-
#
-
<IfModule dir_module>
-
DirectoryIndex index.php index.html ----- 添加php页面;
-
</IfModule>
-
# 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 .php ---- 添加web能够识别的php页面类型;
-
AddType application/x-httpd-php-source .phps ---- 添加web能够识别的php页面类型;
#service httpd restart----php安装完成;
1)下面编译安装php加速器xcache-
2.0.0
- #lftp 172.16.0.1
- #cd pub/Sources/new_lamp/
- #get xcache-2.0.0.tar.bz2 -----下载xcache源码包;
- #bye
- #tar xf xcache-2.0.0.tar.gz
- #cd xcache-2.0.0
- #/usr/local/php/bin/phpize----让php能识别xcache模块;
- #./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config
- #make --编译;
- #make install--安装;
2)编辑php.ini,整合php和xcache:
- #mkdir /etc/php.d
- #cp xcache.ini /etc/php.d----首先将xcache提供的样例配置导入php.ini;
- #vim /etc/php.d/xcache.ini--接下来编辑/etc/php.d/xcache.ini,找到zend_extension开头的行,修改为如下行:
- zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
- #service httpd restart---整合php和xcache完成;
说明:xcache.ini文件在xcache的源码目录中。
注意:如果php.ini文件中有多条zend_extension指令行,要确保此新增的行排在第一位。
四:总结:
以上就是LAMP的介绍及源码安装编译过程,鉴于作者的记忆力与能力有限,错误在所免,望朋友们给予指点。
转载于:https://blog.51cto.com/wjw7702/923860