继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

linux apache mysql php (lamp)

慕勒551688
关注TA
已关注
手记 250
粉丝 39
获赞 133

一、mysql centos6.7 二进制安装5.6

  1. 查看系统版本
      cat /etc/redhat-release

    2.下载 mysql 5.6包

    3.添加用户和组


    groupadd mysql
    useradd -g mysql mysql

    4.安装mysql到/usr/local/mysql 下
    cd /usr/local
    tar zxvf mysql……………………
    5.修改就压后文件名为mysql
    mv mysql………… mysql
    6.修改mysql的各级文件夹和文件的创建者、创建组为mysql 注意点点...
    cd mysql
    chwon -R mysql .
    chgrp -R mysql .
    7.至此mysql已经安装完了,但还需要初始化,初始化mysql表  test表 infaumation 表等
    #scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    8.修改配置文件
    cp support-files/mysql.server /etc/init.d/mysqld   
    cp my.cnf /etc/mycnf
    vi /etc/my.cnf
    basedir = /usr/local/mysql
    datadir = /usr/local/mysql/data
    port = 3306
    server_id = 1
    9。启动mysql服务
    ln -s /usr/local/mysql/bin/mysql /usr/bin
    service mysqld start
    mysql> SELECT user,host,password FROM mysql.user;
    +------+-----------+----------+
    | user | host      | password |
    +------+-----------+----------+
    | root | localhost |          |
    | root | 10-4-5-9  |          |
    | root | 127.0.0.1 |          |
    | root | ::1       |          |
    |      | localhost |          |
    |      | 10-4-5-9  |          |
    +------+-----------+----------+
    6 rows in set (0.00 sec)
     
    mysql> UPDATE mysql.user set password = PASSWORD('gechong') WHERE user = 'root';
     
    mysql> DROP USER ''@localhost;
     
    mysql> FLUSH PRIVILEGES;

    chkconfig --add mysqldd
    chkconfig mysqld on
    service mysqld start

二、apache部署安装 (防火墙80端口)

下载httpd-2.2.31.tar.bz2  把httpd-2.2.31.tar.bz2放到/soft 下
[root@localhost ~]#cd /soft
[root@localhost soft]#tar jxvf httpd-2.2.31.tar.bz2    //解压apache的压缩包
[root@localhost soft]#cd httpd-2.2.31     //定位到httpd-2.2.31 文件夹下
[root@localhost httpd-2.2.31]#ls     //查看显示httpd-2.2.31 文件夹下内容
[root@localhost httpd-2.2.31]#./configure --help | more    //查看安装apache配置参数
[root@localhost httpd-2.2.31]#./configure  --prefix=/usr/local/apache  --enable-so    //  配置apache路径
[root@localhost httpd-2.2.31]#make     //编译apache
[root@localhost httpd-2.2.31]#make install    //安装apache
[root@localhost httpd-2.2.31]#cd /usr/local/apache   //进入apache的目录     
[root@localhost apache]#  cd conf/
[root@localhost conf]#cp -a httpd.conf httpd.conf-     //备份apache配置文件
[root@localhost conf]#chkconfig  --list httpd     //查看httpd服务是否已存在
[root@localhost conf]#chkconfig httpd off    //关闭系统自带了httpd的服务,如果存在httpd服务   
[root@localhost conf]#service httpd status    //查看自带httpd服务状态
[root@localhost conf]#/usr/local/apache/bin/apachectl -k start    //linux启动apache命令

  

****************************************************************************************************

遇到错误httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName          将里面的#ServerName localhost:80注释去掉即可

****************************************************************************************************           
[root@localhost conf]#netstat -an | grep :80    //查看linux80端口是否开启
[root@localhost conf]#ps -aux | grep httpd     //linux下查看apache进程
[root@localhost conf]#cd ../..
[root@localhost local]#cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/apache //拷贝apache启动脚本
[root@localhost local]#vi /etc/rc.d/init.d/apache    // 这里是编辑apache启动脚本
  在开头的#!/bin/sh  下面加上
              #chkconfig: 2345  85  15
[root@localhost local]#chkconfig --add apache    //添加apache服务
[root@localhost local]#chkconfig --list apache    //列出apache服务
[root@localhost local]#service apache stop    //停止apache服务
[root@localhost local]#netstat -an | grep :80     //查看linux的80端口是否关闭
[root@localhost local]#ps -aux | grep httpd     //查看是否存在httpd服务,若果之前自带httpd服务启动的话会导致新添加的apache服务启动失败
[root@localhost local]#service apache start    //启动apache服务
打开你的服务器ip地址,看看是否出现了apache的默认首页,如果出现的话,那么恭喜你linux下安装apache已经成功了

三、php部署配置

官网下载phphttp://www.php.net/downloads.php

[root@localhost src]# tar zxf php-5.3.27.tar.gz

[root@localhost src]# cd php-5.3.27[root@localhost php-5.3.27]# ./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

[root@localhost php-5.3.27]# make

[root@localhost php-5.3.27]# make install

[root@localhost php-5.3.27]# cp php.ini-production /usr/local/php/etc/php.ini


****************************************************************************************************遇到相应安装包错误时,查找资料,自行安装。bzip2 bzip2-devel libpng libpng-devel freetype freetype-devel

****************************************************************************************************

四、apache和php的结合

  apache的主配置文件/usr/local/apache/conf/httpd.conf

vim /usr/local/apache/conf/httpd.conf

309     AddType application/x-compress .Z
310     AddType application/x-gzip .gz .tgz

在310行下面添加

AddType application/x-httpd-php .php

在167行找到

<IfModule dir_module>   

DirectoryIndex index.html

</IfModule>

修改成如下

<IfModule dir_module>   

DirectoryIndex index.html index.htm index.php

</IfModule>

五、测试lamp

重启apache

/etc/init.d/apache restart

使用curl测试apache

[root@localhost ~]# curl localhost

<html><body><h1>It works!</h1></body></html>

出现以上显示表示apache成功

然后测试能不能解析php

vim /usr/local/apache/htdocs/ceshi.php

写入

<?php

   echo "php 解析测试";

?>

出现下面的信息表示解析成功

[root@localhost htdocs]# curl localhost/ceshi.php
php解析测试[root@localhost htdocs]#


至此最基本的lamp搭建完成,具体的配置文件继续研究


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP