LAMP的环境的搭建

转载 2016年05月31日 00:24:46

LAMP的环境的搭建

 

 

目录

1 环境准备... 1

2 安装apache1

1)选择版本... 1

2)开始安装... 1

3)继续安装apache1

4)启动apache1

5)网站打不开排查方法... 1

6)部署一个简单WEB站点... 1

3 mysql的安装... 1

1)版本选择... 1

2)创建mysql用户和用户组... 1

3)配置安装... 1

4) MySQL的启动和关闭... 1

5) 修改密码... 1

6) 开机自动启动... 1

4 PHP安装... 1

1) 需要获取如下相关文件... 1

2)首先安装所需要的安装插件,避免安装失败... 1

3)编译安装四个专用的PHP支持插件... 1

4)PHP软件的编译安装... 1

5)编辑测试文件... 1

5 apache结合php测试环境... 1

6 参考资料... 1

 

 

 

 

 

1 环境准备

 

 

1.1 克隆虚拟机

 

1.2 配置IP

         192.168.1.66

 

2 安装apache

 

1)选择版本

         httpd-2.2.27.tar.gz

 

2)开始安装

 

[root@lamphttpd-2.2.27]# mkdir /home/oldboy/tools -p

[root@lamphttpd-2.2.27]# cd /home/oldboy/tools/

[root@lamphttpd-2.2.27]# tar xf httpd-2.2.27.tar.gz

[root@lamphttpd-2.2.27]# cd httpd-2.2.27

[root@lamphttpd-2.2.27]# ./configure --prefix=/application/apache2.2.27 --enable-deflate--enable-expires --enable-headers --enable-modules=most --enable-so--with-mpm=worker --enable-rewrite

 

 

错误1

checking for zlib location... not found

checking whether to enable mod_deflate...configure: error: mod_deflate has been requested but can not be built due toprerequisite failures

 

解决方法:

[root@lamp httpd-2.2.27]# yum install zlib zlib-devel -y

 

3)继续安装apache

 

[root@lamphttpd-2.2.27]# ./configure --prefix=/application/apache2.2.27 --enable-deflate--enable-expires --enable-headers --enable-modules=most --enable-so--with-mpm=worker --enable-rewrite

[root@lamphttpd-2.2.27]# make

[root@lamphttpd-2.2.27]# make install

[root@lamp httpd-2.2.27]#

[root@lamphttpd-2.2.27]# ln -s /application/apache2.2.27/ /application/apache

[root@lamphttpd-2.2.27]# ll /application/apache/

total 60

drwxr-xr-x. 2 root root  4096 Jun 17 06:40 bin

drwxr-xr-x. 2 root root  4096 Jun 17 06:40build

drwxr-xr-x. 2 root root  4096 Jun 17 06:40cgi-bin

drwxr-xr-x. 4 root root  4096 Jun 17 06:40conf

drwxr-xr-x. 3 root root  4096 Jun 17 06:40error

drwxr-xr-x. 2 root root  4096 Mar 14  2014 htdocs

drwxr-xr-x. 3 root root  4096 Jun 17 06:40icons

drwxr-xr-x. 2 root root  4096 Jun 17 06:40include

drwxr-xr-x. 3 root root  4096 Jun 17 06:40 lib

drwxr-xr-x. 2 root root  4096 Jun 17 06:40logs

drwxr-xr-x. 4 root root  4096 Jun 17 06:40 man

drwxr-xr-x. 14 root root 12288 Mar 14  2014 manual

drwxr-xr-x. 2 root root  4096 Jun 17 06:40modules

[root@lamp httpd-2.2.27]#

[root@lamphttpd-2.2.27]# /application/apache/bin/apachectl  -l|egrep"_so|_rewrite|header|expire|deflate"

 mod_deflate.c

  mod_expires.c

 mod_headers.c

 mod_rewrite.c

  mod_so.c

[root@lamp httpd-2.2.27]#

[root@lampconf]# /application/apache/bin/apachectl

[root@lampconf]# /application/apache/bin/apachectl -l

[root@lamp httpd-2.2.27]#/application/apache/bin/apachectl start

httpd: apr_sockaddr_info_get() failed for lamp

 

 

 

问题2

httpd: Could not reliably determine theserver's fully qualified domain name, using 127.0.0.1 for ServerName

解决方法:

[root@lampconf]# cd /application/apache/conf/

[root@lampconf]# vi httpd.conf

#ServerNamewww.example.com:80

ServerName127.0.0.1

 

4)启动apache

 

[root@lampconf]# /application/apache/bin/apachectl start

httpd (pid 70321) already running

[root@lampconf]# /application/apache/bin/apachectl restart

[root@lamp conf]#

[root@lampconf]# netstat -lnt

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State     

tcp       0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN     

tcp       0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN     

tcp       0      0 :::80                       :::*                        LISTEN     

tcp       0      0 :::22                       :::*                        LISTEN     

tcp       0      0 ::1:25                      :::*                        LISTEN     

[root@lampconf]# curl 192.168.1.66

<html><body><h1>Itworks!</h1></body></html>[root@lamp conf]#

[root@lamp conf]#

[root@lampconf]# lsof -i tcp:80

COMMAND  PID   USER   FD  TYPE DEVICE SIZE/OFF NODE NAME

httpd  70321   root    4u IPv6  67916      0t0 TCP *:http (LISTEN)

httpd   70420daemon    4u  IPv6 67916      0t0  TCP *:http (LISTEN)

httpd   70421daemon    4u  IPv6 67916      0t0  TCP *:http (LISTEN)

httpd   70422daemon    4u  IPv6 67916      0t0  TCP *:http (LISTEN)

[root@lampconf]# ps -ef |grep http

root     70321      1  0 06:47 ?        00:00:00/application/apache2.2.27/bin/httpd -k start

daemon   70419  70321  0 06:53 ?        00:00:00/application/apache2.2.27/bin/httpd -k start

daemon   70420  70321  0 06:53 ?        00:00:00/application/apache2.2.27/bin/httpd -k start

daemon   70421  70321  0 06:53 ?        00:00:00/application/apache2.2.27/bin/httpd -k start

daemon   70422  70321  0 06:53 ?        00:00:00 /application/apache2.2.27/bin/httpd-k start

root     70508   1535  0 06:54 pts/0    00:00:00 grep http

[root@lampconf]# curl -I 192.168.1.66

HTTP/1.1 200 OK

Date: Tue, 16 Jun 2015 22:55:03 GMT

Server: Apache/2.2.27 (Unix) DAV/2

Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT

ETag: "21d3d-2c-3e9564c23b600"

Accept-Ranges: bytes

Content-Length: 44

Content-Type: text/html

 

[root@lamp conf]#

[root@lamp conf]#

 

 

 

 

 

5)网站打不开排查方法

 

iptables防火墙和selinux是否关闭

/etc/init.d/iptables stop #这是关闭防火墙的命令,如果是生产环境则是允许80端口的访问,而不是关闭防火墙

iptables -I INPUT  -p tcp --dport 80 -jACCEPT #非正式环境可以禁止防火墙开机启动,便于学习调试Apache服务。

chkconfig iptables stop

/etc/init.d/iptables status #查看iptables的当前状态

tail -100/application/apache/logs/error_log

 

[root@localhost ~]# service iptables stop

iptables:清除防火墙规则:[确定]

iptables:将链设置为政策 ACCEPT:filter [确定]

iptables:正在卸载模块:[确定]

[root@localhost ~]# setenforce 0

[root@localhost ~]# getenforce 0

Permissive

 

 

 

6)部署一个简单WEB站点

 

 

[root@lampconf]# grep -i DocumentRoot /application/apache/conf/httpd.conf

# DocumentRoot: The directory out of which you willserve your

DocumentRoot"/application/apache2.2.27/htdocs"

# This should be changed to whatever you setDocumentRoot to.

    # accesscontent that does not live under the DocumentRoot.

[root@lamp conf]#

 

 

         如果想要部署网站服务,只需要把开发好的程序全部放置到/application/apache2.2.22/htdocs下面即可

这里我们进入到/application/apache2.2.22/htdocs下,删除掉Apache默认的首页index.html(原始内容为itworks),然后建立一个index.html,加入一段网页内容并保存

此时在浏览器端输入http://IP地址就应该可以看到网页内容了。

 

 

在这里apache就安装好了;

 

参考资料:

         http://hanyanwei.blog.51cto.com/8672126/1395487/

 

 

 

 

3 mysql的安装

 

 

1)版本选择

 

         MySQL-5.1.72.tar.gz

 

 

2)创建mysql用户和用户组

 

[root@lamp conf]#

[root@lamp conf]# useradd mysql -s/sbin/nologin -M

 

 

3)配置安装

 

 

 

[root@lampconf]# useradd mysql -s /sbin/nologin -M

[root@lampconf]# yum -y install ncurses-devel

[root@lampconf]# cd /home/oldboy/tools/

[root@lamp tools]# ll

total 7348

drwxr-xr-x. 12 mysql mysql    4096 Jun 17 06:40 httpd-2.2.27

-rw-r--r--. 1 root  root  7519677 Jun 9 02:59 httpd-2.2.27.tar.gz

[root@lamptools]# rz

rz waiting to receive.

正在开始 zmodem 传输。按 Ctrl+C 取消。

正在传输 mysql-5.1.72.tar.gz...

  100%   23480 KB 3913 KB/s 00:00:06       0 错误

[root@lamptools]# tar -zxf mysql-5.1.72.tar.gz

[root@lamptools]# cd mysql-5.1.72

[root@lamp mysql-5.1.72]#  ./configure --prefix=/application/mysql5.1.72--with-unix-socket-path=/application/mysql5.1.72/tmp/mysql.sock --localstatedir=/application/mysql5.1.72/data--enable-assembler --enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables--without-debug --with-pthread --enable-assembler --with-extra-charsets=complex--with-readline --with-ssl --with-embedded-server --enable-local-infile--with-plugins=partition,innobase --with-mysqld-ldflags=-all-static--with-client-ldflags=-all-static

[root@lampmysql-5.1.72]# ln -s /application/mysql5.1.72 /application/mysql

[root@lampmysql-5.1.72]# cp support-files/my-small.cnf /etc/my.cnf

cp: overwrite `/etc/my.cnf'? yes

[root@lampmysql-5.1.72]# mkdir -p /application/mysql/data

[root@lampmysql-5.1.72]# chown -R mysql.mysql /application/mysql

[root@lampmysql-5.1.72]# /application/mysql/bin/mysql_install_db  --basedir=/application/mysql--datadir=/application/mysql/data

 

 

错误1

150617 7:48:55 [Warning] '--skip-locking'is deprecated and will be removed in a future release. Please use'--skip-external-locking' instead.

OK

Filling help tables...

150617 7:48:55 [Warning] '--skip-locking' is deprecated and will be removed ina future release. Please use '--skip-external-locking' instead.

OK

解决方法:

[root@lamp mysql-5.1.72]# vi /etc/my.cnf

# The MySQL server

[mysqld]

port           = 3306

socket         = /application/mysql5.1.72/tmp/mysql.sock

#skip-locking  #把这行注释掉即可

key_buffer_size = 16K

max_allowed_packet = 1M

table_open_cache = 4

"/etc/my.cnf" 82L, 2500C written

 

 

[root@lampmysql-5.1.72]# /application/mysql/bin/mysql_install_db  --basedir=/application/mysql--datadir=/application/mysql/data

[root@lampmysql-5.1.72]# cp support-files/mysql.server /application/mysql/bin

[root@lampmysql-5.1.72]# chmod 755 /application/mysql/bin/mysql.server

[root@lampmysql-5.1.72]# /application/mysql/bin/mysql.server start

[root@lampmysql-5.1.72]# cp support-files/mysql.server /etc/init.d/mysqld

[root@lampmysql-5.1.72]# chmod 755 /etc/init.d/mysqld

[root@lampmysql-5.1.72]# echo "#start mysqld" >> /etc/rc.local

[root@lampmysql-5.1.72]# echo "/etc/init.d/mysqld start" >> /etc/rc.local

[root@lampmysql-5.1.72]# echo "PATH=/application/mysql/bin:$PATH" >>/etc/profiles

[root@lampmysql-5.1.72]# source /etc/profiles

[root@lampmysql-5.1.72]# mysqladmin -uroot password '888888'

[root@lampmysql-5.1.72]# /application/mysql/bin/mysqld_safe &

[root@lampmysql-5.1.72]# /application/mysql/bin/mysql.server start

[root@lampmysql-5.1.72]# mysqladmin -uroot password '888888'

[root@lampmysql-5.1.72]# mysql -uroot -p

 

 

4) MySQL的启动和关闭

 

第一种方法:

启动:

/application/mysql/bin/mysqld_safe &

关闭:

mysqladmin shutdown

 

第二种:

/etc/init.d/mysqld start

/etc/init.d/mysqld stop

混合用有问题

 

[root@lamp ~]# ps -ef|grep mysql

root      2501   2468  0 10:21 pts/0    00:00:00 grep mysql

 

 

5) 修改密码

 

mysql> use mysql;

mysql> UPDATE user SET password=PASSWORD('888888')WHERE user='root';

mysql> FLUSH PRIVILEGES;

 

 

 

6) 开机自动启动

 

 

[root@lamp ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@lamp ~]# echoPATH=$PATH:/application/mysql/bin/ >> /etc/profile

[root@lamp ~]# source/etc/profile

[root@lamp ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/application/mysql/bin/

[root@lamp ~]#

[root@lamp ~]#

[root@lamp ~]# mysql -uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.1.72 Source distribution

 

Copyright (c) 2000, 2013, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarks of theirrespective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clearthe current input statement.

 

mysql>

mysql>

mysql>

mysql> quit

 

 

 

 

 

 

4 PHP安装

 

1) 需要获取如下相关文件

-rw-r--r--  1 root   root    7519677 Mar 19  2014 httpd-2.2.27.tar.gz

-rw-r--r--  1 root   root    4984397 Oct  7 06:13 libiconv-1.14.tar.gz

-rw-r--r--  1 root   root    1335178 Feb 19  2007 libmcrypt-2.5.8.tar.gz

-rw-r--r--  1 root   root     471915 Nov 22  2008 mcrypt-2.6.8.tar.gz

-rw-r--r--  1 root   root     931437 Dec  8  2008 mhash-0.9.9.9.tar.gz

-rw-r--r--  1 root   root   15008639 Jul 11  2013 php-5.3.27.tar.gz

 

 

2首先安装所需要的安装插件,避免安装失败

 

[root@lamp ~]#

[root@lamp ~]# yum install zlib libxml libjpegfreetype libpng gd  curl libiconv  zlib-devel libxml2-devel libjpeg-develfreetype-devel libpng-devel gd-devel curl-devel opensshl-devel libxslt-devel -y

[root@lamp ~]#

[root@lamp ~]#

[root@lamp ~]# cd /home/oldboy/tools/

[root@lamp tools]# ll

 

 

3编译安装四个专用的PHP支持插件

 

3.1)libiconv-1.14

 

[root@lamp tools]#tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make

make install

cd ../

 

3.2)libmcrypt-2.5.8

 

[root@lamptools]# tar zxf libmcrypt-2.5.8.tar.gz

cd libmcrypt-2.5.8

./configure

make

make install

sleep 2

/sbin/ldconfig

cd libltdl/

./configure --enable-ltdl-install

make

make install

cd ../../

 

3.3)mhash-0.9.9.9

 

[root@lamptools]# tar zxf mhash-0.9.9.9.tar.gz

cd mhash-0.9.9.9/

./configure

make

make install

sleep 2

cd ../

 

rm -f /usr/lib64/libmcrypt.*

rm -f /usr/lib64/libmhash*

ln -s /usr/local/lib64/libmcrypt.la /usr/lib64/libmcrypt.la

ln -s /usr/local/lib64/libmcrypt.so /usr/lib64/libmcrypt.so

ln -s /usr/local/lib64/libmcrypt.so.4 /usr/lib64/libmcrypt.so.4

ln -s /usr/local/lib64/libmcrypt.so.4.4.8 /usr/lib64/libmcrypt.so.4.4.8

ln -s /usr/local/lib64/libmhash.a /usr/lib64/libmhash.a

ln -s /usr/local/lib64/libmhash.la /usr/lib64/libmhash.la

ln -s /usr/local/lib64/libmhash.so /usr/lib64/libmhash.so

ln -s /usr/local/lib64/libmhash.so.2 /usr/lib64/libmhash.so.2

ln -s /usr/local/lib64/libmhash.so.2.0.1 /usr/lib64/libmhash.so.2.0.1

ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config

 

 

 

3.4)mcrypt-2.6.8

 

 

[root@lamptools]#tar zxf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8/

/sbin/ldconfig

./configure LD_LIBRARY_PATH=/usr/local/lib

make

make install

cd ../

sleep 2

 

 

 

 

 

 

 

4)PHP软件的编译安装

 

 

 

[root@lamp php-5.3.27]# yum install openssl-devel-y

 

 

[root@lamptools]# rm -rf php-5.3.27

[root@lamptools]# tar xf php-5.3.27.tar.gz

[root@lamptools]# cd php-5.3.27

[root@lamp php-5.3.27]#

[root@lamp php-5.3.27]#

[root@lampphp-5.3.27]# ./configure \

>--prefix=/application/php5.3.27 \

>--with-apxs2=/application/apache/bin/apxs \

>--with-mysql=/application/mysql \

> --with-xmlrpc \

> --with-openssl \

> --with-zlib \

> --with-freetype-dir \

> --with-gd \

> --with-jpeg-dir \

> --with-png-dir \

> --with-iconv=/usr/local/libiconv \

> --enable-short-tags \

> --enable-sockets \

> --enable-zend-multibyte \

> --enable-soap \

> --enable-mbstring \

> --enable-static \

> --enable-gd-native-ttf \

> --with-curl \

> --with-xsl \

> --enable-ftp \

> --with-libxml-dir

 

 

[root@lamp php-5.3.27]#

[root@lamp php-5.3.27]#

[root@lampphp-5.3.27]# make && make install

[root@lampphp-5.3.27]# ln -s /application/php5.3.27/ /application/php

[root@lampphp-5.3.27]# ll /application/php/

[root@lampphp-5.3.27]# /application/apache/bin/apachectl -t

[root@lampphp-5.3.27]# /application/apache/bin/apachectl start

 

 

 

 

 

 

5)编辑测试文件

 

[root@lampphp-5.3.27]# cd /application/apache2.2.27/htdocs

[root@lamp htdocs]# ll

total 4

-rw-r--r--. 1 root root 44 Nov 21  2004 index.html

[root@lamphtdocs]# vi index.php

<?php

       phpinfo();

?>

[root@lamphtdocs]# vi 1.php

<?php

 

    echo"hello world!!!";

 

?>

[root@lamphtdocs]# vi mysql.php

<?php

         //$link_id=mysql_connect('主机名','用户','密码');

         $link_id=mysql_connect('localhost','root','888888')or mysql_error();

 

         if($link_id){

                   echo"mysql successful by oldboy !";

         }else{

                   echomysql_error();

         }

?>

 

 

5 apache结合php测试环境

 

 

 

 

[root@lamp htdocs]#

[root@lamp htdocs]# vi/application/apache/conf/httpd.conf

 

    AddTypeapplication/x-compress .Z

    AddTypeapplication/x-gzip .gz .tgz

    AddType application/x-httpd-php .php

 

<IfModule dir_module>

   DirectoryIndex index.html index.htmindex.php

</IfModule>

 

#ServerName www.example.com:80

ServerName 127.0.0.1:80

 

 

 

 

 

 

 

问题1

Can't connect to local MySQL server throughsocket 问题解决

解决方法:

http://www.linuxidc.com/Linux/2013-03/81331.htm

 

 

 

6 参考资料

 

         http://tslove.blog.51cto.com/9115838/1592742

         http://8802265.blog.51cto.com/8792265/1639875

相关文章推荐

LAMP环境搭建.

  • 2012年05月10日 21:49
  • 66KB
  • 下载

lamp环境搭建_自己整理完整版

  • 2016年01月04日 13:56
  • 444KB
  • 下载

centos6.3-64位搭建LAMP环境之安装php5.5.7

mysql和apache安装并且测试ok之后下一步就是安装php了。因为安装php的时候要往apache的配置文件里写东西,而且要把mysql集成进php,为了安全期间我把mysql和httpd都停掉...

LAMP环境搭建

  • 2014年08月21日 15:47
  • 16KB
  • 下载

简易环境搭建(LAMP)

  • 2013年09月25日 13:40
  • 44KB
  • 下载

Linux下最新版LAMP环境(源码版)搭建详细解读

LAMP的四个字母代表神马,我先解释申明下L:Linux 我用的Linux版本是 centos 7.0 A:Apache 我用的版本是 httpd-2.4.29 M:MySQL 我使用的版本是...

源代码搭建lamp环境

  • 2016年11月21日 14:58
  • 48.42MB
  • 下载

LAMP 服务器环境配置 搭建

  • 2011年03月07日 12:55
  • 113KB
  • 下载

centos7下lamp环境搭建

一,Apache:1,安装apache:yum -y install httpd 2,启动apache:systemctl start httpd.service 3,设置开机启动:systemc...
  • smm188
  • smm188
  • 2017年07月20日 12:30
  • 249

CentOS搭建lamp环境详资料

  • 2011年01月28日 21:56
  • 44KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:LAMP的环境的搭建
举报原因:
原因补充:

(最多只允许输入30个字)