LAMP搭建过程(源码包)
------------------------------------------
一、前言
二、环境
三、安装前准备
四、搭建LAMP环境
1.安装mysql
2.安装apache
3.安装php
4.安装wordpress
--------------------------------------------
一、前言
LAMP即Linux+Apache+Mysql+PHP,一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。从网站的流量上来说,70%以上的访问流量是LAMP来提供的,LAMP是最强大的网站解决方案.
二、环境
系统:CentOS6.4 32位
源码包 :
httpd-2.4.4.tar.bz2
apr-1.4.6.tar.gz
apr-util-1.5.1.tar.gz
mysql-5.6.15.tar.gz
php-5.5.8.tar.bz2
三、安装前准备
1.安装开发工具
Development tools
Additional Development
2.关闭防火墙和SELinux
3.安装顺序
mysql→apache→php
四、搭建LAMP环境
1.安装mysql
# rpm -qa |grep mysql //安装源码前查看系统中是否有和mysql相关的包 mysql-libs-5.1.66-2.el6_3.i686 mysql-5.1.66-2.el6_3.i686 mysql-devel-5.1.66-2.el6_3.i686 # yum remove mysql mysql-devel mysql-libs //将所有关于mysql及依赖包全部卸载,避免冲突 # tar -zxvf mysql-5.6.15.tar.gz -C /usr/local/src //解压缩 # cd /usr/local/src/mysql-5.6.15 # vi INSTALL-SOURCE //关于安装mysql源码步骤,INSTALL文件说的很清楚,按照步骤即可
# groupadd mysql # useradd -r -g mysql mysql # cd mysql-5.6.15/ # yum install cmake //编译需要使用cmake #cmake . #make //耐心等待... #make install # cd /usr/local/mysql/ # chown -R mysql . # chgrp -R mysql . # scripts/mysql_install_db --user=mysql //重置数据库 # chown -R root . # chown -R mysql data # cp my.cnf /etc/ //mysql主配置文档 # cp support-files/mysql.server /etc/init.d/mysqld //创建启动脚本 # chmod a+x /etc/init.d/mysqld # service mysqld start //启动mysql Starting MySQL.. SUCCESS! # netstat -tupln |grep 3306 tcp 0 0 :::3306 :::* LISTEN 18960/mysqld # chkconfig --add mysqld # chkconfig mysqld on //添加至开机启动 # vi /etc/profile //系统调用 # . /etc/profile # mysql //测试登录,正常。 mysql> \q Bye # mysqladmin -u root -p password '123' //创建用户 Enter password: //让输入旧的密码,此处回车即可 # mysql -u root -p Enter password: mysql> \q Bye
2.安装apache
# rpm -qa |grep httpd //同样安装前查看系统中是否有和httpd相关的包 httpd-tools-2.2.15-26.el6.centos.i686 httpd-2.2.15-26.el6.centos.i686 # yum remove httpd //卸载 # yum install pcre-devel # tar -jxvf httpd-2.4.4.tar.bz2 -C /usr/local/src/ # tar -zxvf apr-util-1.5.1.tar.gz -C /usr/local/src/ # tar -zxvf apr-1.4.6.tar.gz -C /usr/local/src/ # cd /usr/local/src/ # cd apr-1.4.6/ //安装apr # ./configure --prefix=/usr/local/apr #make && make install # cd ../apr-util-1.5.1/ //安装apr-util # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config # make && make install # cd ../httpd-2.4.4/ //安装httpd # ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd //配置文件路径 --enable-so --enable-ssl --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr-util/bin/apu-1-config --with-pcre -with-z --enable-mpms-shared=all # make && make install //耐心等待... # vi /etc/httpd/httpd.conf //查看httpd根路径位置 212 DocumentRoot “/usr/local/apache/htdocs” # cd /usr/local/apache/bin # ./httpd -h //查看帮助 # ./httpd -k start //启动apache # netstat -tupln |grep 80 tcp 0 0 :::80 :::* LISTEN 20027/./httpd # cd /etc/init.d/ # vi httpd //创建启动脚本,以系统service方式启动
1 #!/bin/bash 2 [ -e /etc/init.d/functions ] && . /etc/init.d/functions 3 prog=/usr/local/apache/bin/httpd 4 lockfile=/var/lock/subsys/httpd 5 6 start () { 7 if [ -e $lockfile ];then 8 echo "The httpd server is started" 9 else 10 echo "The httpd server is starting..." 11 sleep 1 12 $prog && echo -e "[ \033[32mOK\033[0m ]" && touch $lockfile 13 fi 14 15 } 16 17 stop () { 18 if [ ! -e $lockfile ];then 19 echo "The httpd server is stoped..." 20 else 21 echo -n "The httpd server is stoping..." 22 sleep 1 23 killproc httpd && echo "ok" && rm -rf $lockfile || echo "failer" 24 fi 25 26 } 27 28 status () { 29 if [ -e $lockfile ];then 30 echo "The httpd server is running..." 31 else 32 echo "The httpd is stop" 33 fi 34 35 } 36 37 case "$1" in 38 start) 39 start 40 ;; 41 stop) 42 stop 43 ;; 44 restart) 45 stop 46 start 47 ;; 48 status) 49 status 50 ;; 51 *) 52 echo "USE ONLY:start|stop|restart|status" 53 esac
# chmod a+x httpd //赋予执行权限 # service httpd restart //重启测试 The httpd server is stoped... The httpd server is starting... # service httpd status The httpd server is running...
访问测试http://192.168.8.100 //访问apache服务器地址,测试正常。
3.安装php
# rpm -qa |grep php //系统中没有和php相关的包。 # tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/ # cd /usr/local/src/php-5.5.8/ # ./configure -h //可以帮助看下各个指令的含义 # ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all # make && make install //编译成功后安装 # vi /etc/httpd/httpd.conf //添加148行内容,正确处理基于php的请求。
# service httpd restart //修改配置文件后要重启
4.安装wordpress测试
# unzip wordpress-3.8-zh_CN.zip # mv wordpress /usr/local/apache/htdocs/ # cd /usr/local/apache/htdocs/ # ll -rw-r--r--. 1 root root 45 Jun 11 2007 index.html drwxr-xr-x. 5 root root 4096 Dec 12 23:26 wordpress
访问http://192.168.8.100/wordpress/ //出现以下信息
//如果出现以上信息,修改248行内容即可。也可直接点击index.php进入
# vi /etc/httpd/httpd.conf
# service httpd restart
重新访问http://192.168.8.100/wordpress/
点击“创建配置文件”
# mysql -u root -p //首先创建wordpress数据库,再提交。
Enter password:
mysql> create database wordpress;
mysql> \q
Bye
[[email protected] htdocs]# cd wordpress/ //复制以上内容到wp-config.php中,再点击“进行安装”。
[[email protected] wordpress]# vi wp-config.php
OK,成功安装!
测试登录!
登录成功!
至此,LAMP环境搭建完毕!
转载于:https://blog.51cto.com/hatech/1352931