linux apache mysql php (lamp)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux apache mysql php (lamp)相关的知识,希望对你有一定的参考价值。

一、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 下
[[email protected] ~]#cd /soft
[[email protected] soft]#tar jxvf httpd-2.2.31.tar.bz2    //解压apache的压缩包
[[email protected] soft]#cd httpd-2.2.31     //定位到httpd-2.2.31 文件夹下
[[email protected] httpd-2.2.31]#ls     //查看显示httpd-2.2.31 文件夹下内容
[[email protected] httpd-2.2.31]#./configure --help | more    //查看安装apache配置参数
[[email protected] httpd-2.2.31]#./configure  --prefix=/usr/local/apache  --enable-so    //  配置apache路径
[[email protected] httpd-2.2.31]#make     //编译apache
[[email protected] httpd-2.2.31]#make install    //安装apache
[[email protected] httpd-2.2.31]#cd /usr/local/apache   //进入apache的目录     
[[email protected] apache]#  cd conf/
[[email protected] conf]#cp -a httpd.conf httpd.conf-     //备份apache配置文件
[[email protected] conf]#chkconfig  --list httpd     //查看httpd服务是否已存在
[[email protected] conf]#chkconfig httpd off    //关闭系统自带了httpd的服务,如果存在httpd服务   
[[email protected] conf]#service httpd status    //查看自带httpd服务状态
[[email protected] 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注释去掉即可

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

三、php部署配置

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

[[email protected] src]# tar zxf php-5.3.27.tar.gz

[[email protected] src]# cd php-5.3.27 [[email protected] 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

[[email protected] php-5.3.27]# make

[[email protected] php-5.3.27]# make install

[[email protected] 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

[[email protected] ~]# curl localhost

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

出现以上显示表示apache成功

然后测试能不能解析php

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

写入

<?php

   echo "php 解析测试";

?>

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

[[email protected] htdocs]# curl localhost/ceshi.php
php解析测试[[email protected] htdocs]#


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


本文出自 “小屁孩儿” 博客,谢绝转载!

以上是关于linux apache mysql php (lamp)的主要内容,如果未能解决你的问题,请参考以下文章

Centos7編譯安裝LAMP平臺

lamp

Linux安装部署LAMP(Apache+MySQL+PHP)

搭建LAMP架构— 1手工编译安装Apache

Linux下PHP+MYSQL+APACHE配置方法

Lamp(linux+apache+mysql+php)环境搭建