LAMP 指的Linux(操作系统)、 ApacheHTTP 服务器, MySQL (数据库软件) 和PHP(有时也是指Perl 或 Python) 的第一个字母,是一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。
前提条件
想要实现源码安装,必须先要配置好编译环境
先使用 yum grouplist 查看安装的组
Development Tools
Development Libraries
Legacy Software Development
X Software Development
如果依赖于jave的也需要安装Java的开发环境
yum -y groupinstall 上述的软件包组
实验环境
[root@localhost ~]# uname -r 2.6.18-164.el5 [root@localhost ~]# cat /etc/RedHat-release Red Hat Enterprise Linux Server release 5.4 (Tikanga)
一、安装mysql
1.解压缩mysql-5.5.15-linux2.6-i686
[root@localhost ~]# tar zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/
2.新建用户以安全方式运行进程
[root@localhost ~]# groupadd -r mysql
[root@localhost ~]# useradd -g mysql -r -s /sbin/nologin -M -d /mydat/data mysql
[root@localhost ~]# mkdir -pv /mydata/data
[root@localhost ~]# chown -R mysql:mysql /mydata/data
3.安装并初始化数据库
[root@localhost ~]# cd /usr/local/
[root@localhost local]# ln -sv mysql-5.5.15-linux2.6-i686 mysql
##建立一个软连接
[root@localhost local]# cd mysql
[root@localhost mysql]# chown -R mysql:mysql .
[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
##--user定义数据库的所属主,--datadir定义数据库安装到哪里
##./bin/mysqladmin -u root password 'new-password'
##./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
##Alternatively you can run:
##./bin/mysql_secure_installation
[root@localhost mysql]# chown -R root .
4.为mysql拷贝配置文件
[root@localhost ~]# cd /usr/local/mysql
[root@localhost mysql]# cp support-files/my-large.cnf /etc/my.cnf
[root@localhost mysql]# vim /etc/my.cnf
38 # Try number of CPU's*2 for thread_concurrency
39 thread_concurrency = 2
##thread_concurrency的值为你的CPU个数的2倍
40 datadir = /mydata/data
##mysql数据文件的存放位置
5.为mysql提供sysv服务脚本
[root@localhost mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
6.添加至服务列表
[root@localhost mysql]# chkconfig --add mysqld
[root@localhost mysql]# service mysqld start
Starting MySQL................. [ OK ]
[root@localhost mysql]# chkconfig mysqld on
##设置开机启动
二、安装apache
1.解压缩httpd-2.2.19
[root@localhost ~]# tar -jxvf httpd-2.2.19.tar.bz2 -C /usr/local/src
2.编译并安装
[root@localhost ~]# cd /usr/local/src/httpd-2.2.19/
[root@localhost httpd-2.2.19]# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --with-z
[root@localhost httpd-2.2.19]# make && make install
3.修改httpd的主配置文件,设置其Pid文件的路径
[root@localhost ~]# vim /etc/httpd/httpd.conf
31 PidFile "/var/run/httpd.pid"
4.提供SysV服务脚本/etc/rc.d/init.d/httpd,内容如下
#!/bin/bash # # httpd Startup script for the Apache HTTP Server # # chkconfig: - 85 15 # description: Apache is a World Wide Web server. It is used to serve \ # HTML files and CGI. # processname: httpd # config: /etc/httpd/conf/httpd.conf # config: /etc/sysconfig/httpd # pidfile: /var/run/httpd.pid # Source function library. . /etc/rc.d/init.d/functions if [ -f /etc/sysconfig/httpd ]; then . /etc/sysconfig/httpd fi # Start httpd in the C locale by default. HTTPD_LANG=${HTTPD_LANG-"C"} # This will prevent initlog from swallowing up a pass-phrase prompt if # mod_ssl needs a pass-phrase from the user. INITLOG_ARGS="" # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server # with the thread-based "worker" MPM; BE WARNED that some modules may not # work correctly with a thread-based MPM; notably PHP will refuse to start. # Path to the apachectl script, server binary, and short-form for messages. apachectl=/usr/local/apache/bin/apachectl httpd=${HTTPD-/usr/local/apache/bin/httpd} prog=httpd pidfile=${PIDFILE-/var/run/httpd.pid} lockfile=${LOCKFILE-/var/lock/subsys/httpd} RETVAL=0 start() { echo -n $"Starting $prog: " LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS RETVAL=$? echo [ $RETVAL = 0 ] && touch ${lockfile} return $RETVAL } stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile} -d 10 $httpd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} } reload() { echo -n $"Reloading $prog: " if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then RETVAL=$? echo $"not reloading due to configuration syntax error" failure $"not reloading $httpd due to configuration syntax error" else killproc -p ${pidfile} $httpd -HUP RETVAL=$? fi echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} $httpd RETVAL=$? ;; restart) stop start ;; condrestart) if [ -f ${pidfile} ] ; then stop start fi ;; reload) reload ;; graceful|help|configtest|fullstatus) $apachectl $@ RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}" exit 1 esac exit $RETVAL
5.为此脚本赋予执行权限
[root@localhost ~]# chmod +x /etc/rc.d/init.d/httpd
6.添加至服务列表
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# service httpd start
[root@localhost ~]# chkconfig httpd on