码迷,mamicode.com
首页 > 其他好文 > 详细

LAMP 环境搭建实例

时间:2017-01-10 00:12:36      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:lamp 环境搭建实例


一、LAMP搭建前的准备

LAMP是四套软件的缩写,分别指的是L-Linux,A-Apache,M-Mysql,P-php,利用这四套软件搭建的web的运行环境。
搭建前需要需要下载好软件
#cd /home/soft
apache :

http://mirrors.cnnic.cn/apache/httpd/httpd-2.2.31.tar.gz
mysql:

32位 :http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.31-linux-glibc2.5-i686.tar.gz
64位 :http://mirrors.sohu.com/mysql/MySQL-5.1/mysql-5.1.73-linux-x86_64-glibc23.tar.gz
php :

wget ‘http://cn2.php.net/get/php-5.4.45.tar.bz2/from/this/mirror‘ -O php-5.4.45.tar.bz2
软件镜像下载地址http://mirrors.sohu.com/,搜狐镜像,阿里镜像,网易镜像可以下载各种开源软件
安装扩展库
yum install -y epel-release
安装库文件
yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libtiff-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel fontconfig-devel zlib zlib-devel libevent-devel gcc gcc-c++ flex bison bzip2-devel libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
关闭selinux    

暂时关闭:setenforce 0
永久关闭:vim /etc/selinux/config  修改SELINUX=disabled  ##需要重启生效

关闭防火墙

iptables -F 

service iptables stop


二、Apache安装 


1 )编译

# 解压软件包
[[email protected] soft]# tar -zxvf httpd-2.2.31.tar.gz

# 进入软件目录
[[email protected] soft]# cd httpd-2.2.31

# 执行编译参数
[[email protected] httpd-2.2.16]#./configure \--prefix=/usr/local/apache2 \--with-included-apr \--enable-so \--enable-deflate=shared \--enable-expires=shared \--enable-rewrite=shared \--with-pcre

# 开始编译安装软件

[[email protected] httpd-2.2.16]# make                      

[[email protected] httpd-2.2.16]# make install

输入 echo$?  显示0则编译安装无误

2 )修改配置

[[email protected] ~]#  vim /usr/local/apache2/conf/httpd.conf
..................上面省略.....................
# at a local disk.  If you wish to share the same ServerRoot for multiple
# httpd daemons, you will need to change at least LockFile and PidFile.
#
ServerRoot "/usr/local/apache2"           # apache 程序目录
#Listen 12.34.56.78:80
Listen 80                         # 监听端口
ServerAdmin [email protected]           # 管理员邮箱地址
ServerName localhost:80                # 默认ServerName www.example.com:80 

DocumentRoot "/usr/local/apache2/htdocs/"   # 网站文件存储的位置,文件监听目录
                                
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all     

# 默认为Deny from all,拒绝访问,修改为Allow from all,允许访问,否则访问网站时会403提示

3 )启动apache

# 修改配置 ,检测是否OK
[[email protected] ~]# /usr/local/apache2/bin/apachectl -t
Syntax OK
[[email protected] ~]# /usr/local/apache2/bin/apachectl start

[[email protected] ~]# ps aux|grep httpd        #检测httpd的启动
root     25675  0.0  0.2   5680  2148 ?        Ss   10:20   0:00 /usr/local/apache2/bin/httpd -k start
daemon   25880  0.0  0.1   5680  1568 ?        S    10:20   0:00 /usr/local/apache2/bin/httpd -k start
root     25886  0.0  0.0   4622  769ts/4    S+   10:23  0:00 grep httpd
[

[[email protected] ~]# netstat -nlp |grep httpd   # 端口检测

tcp   0    0 :::80     :::*       LISTEN      25675/httpd     


[[email protected] ~]# curl -I localhost    # 网站状态访问检测

HTTP/1.1 200 OK
Date: Tue, 28 Apr 2016 12:52:42 GMT
Server: Apache/2.2.16 (Unix) DAV/2
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "12a8-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Content-Type: text/html
在浏览器中输入IP地址,如果显示 It works! 代表成功!


三、mysql安装

# 解压mysql
[[email protected] soft]# tar -zxvf mysql-5.1.73-linux-x86_64-glibc23.tar.gz

# 文件程序移动到指定的安装路径
[[email protected] soft]# mv mysql-5.1.73-linux-x86_64-glibc23 /usr/local/mysql

# 创建mysql用户,shell状态为/sbin/nologin
[[email protected] mysql]# useradd -s /sbin/nologin mysql

# 创建数据库存储目录,更改目录权限
[[email protected] mysql]#cd /usr/local/mysql
[[email protected] mysql]# mkdir -p /data/mysql
[[email protected] mysql]# chown -R mysql:mysql /data/mysql/

# 进入/usr/local/mysql,初始化mysql库,当有2个OK,代表初始化成功

# 这里要注意,需要修改/etc/hosts,将主机名字,添加到文件
[[email protected] mysql]# vi /etc/hosts  加入  192.168.1.6 localhost
[[email protected]localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
Installing MySQL system tables...
OK
Filling help tables...
OK

# 拷贝启动脚本,更改权限
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# chmod 755 /etc/init.d/mysqld

# 修改启动脚本
[[email protected] mysql]# vim /etc/init.d/mysqld

basedir=/usr/local/mysql
datadir=/home/data/mysql

# 拷贝mysql配置文件

[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf
cp: overwrite `/etc/my.cnf‘? y

# 将mysqld加到服务列表里
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld on
[[email protected] mysql]# service mysqld start
Starting MySQL... SUCCESS!
启动成功 用/usr/local/mysql/bin/mysql 进入数据库


四、php安装

# 解压软件
[[email protected] php-5.3.28]# tar -jxvf php-5.4.45.tar.bz2
[[email protected] php-5.3.28]#cd  php-5.4.45
# 进入php文件目录,编辑参数
[[email protected] php-5.3.28]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
# 执行编译安装
[[email protected] php-5.3.28]# make
[[email protected] php-5.3.28]# make install

五、php与apache的组合

修改apache的配置文件 
[[email protected] ~]# vim /usr/local/apache2/conf/httpd.conf
    DirectoryIndex index.html index.htm index.php   添加index.htm和index.php
     AddType application/x-compress .Z
     AddType application/x-gzip .gz .tgz
     AddType application/x-httpd-php .php     加上这一行,增加对php的解析
    #说明:要想支持php脚本解析,必须要加上对应的类型

    LoadModule php5_module  modules/libphp5.so  开启php5_module 
保存后
检测 /usr/local/apache2/bin/apachectl -t
启动 /usr/local/apache2/bin/apachectl  restart
查看是否启动:
[[email protected] ~]# netstat -lnp |grep httpd

tcp       0     0 :::80      :::*   LISTEN      7867/httpd

# 编写php解析测试文件
[[email protected] ~]# vim /usr/local/apache2/htdocs/test.php
<?php
phpinfo();
?>        

在浏览器里输入192.168.1.6/test.php地址,显示php界面,代表解析php成功


本文出自 “实用Linux知识技能分享” 博客,请务必保留此出处http://superleedo.blog.51cto.com/12164670/1890429

LAMP 环境搭建实例

标签:lamp 环境搭建实例

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!