LAMP安装笔记

实验环境:CENTOS6.4,

 

一、MYSQL安装

1、下载mysql/usr/local/src/

#cd /usr/local/src/

#wgethttp://syslab.comsenz.comdownloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

2、解压,并把数据移动到/usr/local/mysql

# tar zxvf/usr/local/src/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz

 

3、建立mysql用户

# useradd -s /sbin/nologin mysql

 

4、初始化数据库

# cd /usr/local/mysql

# mkdir -p/data/mysql

#chown -R mysql:mysql/data/mysql

# ./scripts/mysql_install_db --user=mysql--datadir=/data/mysql

注意:--user 定义数据库的所属主, --datadir 定义数据库安装到哪里.如果您看到两个OK说明执行正确

 

5拷贝启动配置、脚本文件并修改其属性

# cpsupport-files/my-large.cnf /etc/my.cnf

# cp support-files/mysql.server  /etc/init.d/mysqld

# chmod 755/etc/init.d/mysqld

 

6、修改启动脚本

# vim/etc/init.d/mysqld

需要修改的地方有datadir=/data/mysql(前面初始化数据库时定义的目录)

 

7、把启动脚本加入系统服务项,并设定开机启动,启动mysql

# chkconfig --addmysqld

# chkconfig mysqld on

# service mysqldstart

如果启动不了,请到/data/mysql/ 下查看错误日志,这个日志通常是主机名.err.

# ps aux |grep mysqld检查mysql是否启动的命令

 

二、安装Apache

1、下载Apache/usr/local/src

# cd /usr/local/src/

# wget  http://httpd.apache.org/dev/dist/httpd-2.2.24.tar.bz2

 

2、解压

# tar jvxfhttpd-2.2.24.tar.bz2

 

3、配置编译参数

# cd httpd-2.2.24

# yum install -y zlib-devel

# yum install -y pcre pcre-devel aprapr-devel

# ./configure \

--prefix=/usr/local/apache2\

--with-included-apr \

--enable-so \

--enable-deflate=shared\

--enable-expires=shared\

--enable-rewrite=shared\

--with-pcre

注意:--prefix 指定安装到哪里, --enable-so 表示启用DSO [1] --enable-deflate=shared 表示共享的方式编译deflate,后面的参数同理。

 

4、安装

# make

# make install

 

三、PHP安装

1、下载php/usr/local/src,并解压

# cd /usr/local/src

# wgethttp://cn2.php.net/distributions/php-5.3.27.tar.gz

# tar zxfphp-5.3.27.tar.gz

 

2、安装必要的软件包

# yum install -y libxml2-devel

#yum install -yopenssl openssl-devel

# yum install -y bzip2 bzip2-devel

# yum install -y libpng libpng-devel

# yum install -y libjpeg libjpeg-devel

#yum install -yfreetype freetype-devel

注意:因为centos6.x 默认的yum源没有libmcrypt-devel

#wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz

#tar -zxvflibmcrypt-2.5.8.tar.gz

#cd libmcrypt-2.5.8

#./configure

#make

#make install说明:libmcript默认安装在/usr/local

 

3、配置编译参数

# cd 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

4、编译和安装

#make

#make install

5、拷贝配置文件

#cpphp.ini-production /usr/local/php/etc/php.ini

 

 

四、apache结合php

Apache主配置文件为:/usr/local/apache2/conf/httpd.conf

#vim/usr/local/apache2/conf/httpd.conf

1AddType application/x-gzip .gz .tgz在该行下面添加:AddType application/x-httpd-php .php

2DirectoryIndex index.html改为DirectoryIndex index.html index.htm index.php

3ServerName www.example.com:80修改为:ServerName localhost:80

 

五、测试LAMP是否成功

启动apache之前先检验配置文件是否正确:

#/usr/local/apache2/bin/apachectl-t

如果有错误,请继续修改httpd.conf,如果是正确的则显示为Syntax OK

启动apache的命令为:

/usr/local/apache2/bin/apachectlstart

查看是否启动:

# netstat -lnp |grephttpd

tcp        0     0 :::80     :::*  LISTEN      7667/httpd如果有显示这行,则启动了。

# curl localhost

<html><body><h1>Itworks!</h1></body></html>只有显示这样才正确。

测试是否正确解析php:

#vim/usr/local/apache2/htdocs/1.php写入:

<?php

    info();

?>

#curl localhost/1.php

 


 

几个常用的技巧:

查看apache编译参数:cat /usr/local/apache2/build/config.nice

查看apache价值的模块:/usr/local/ apache2/bin/apachectl �CM

测试apache配置文件是否正确:/usr/local/ apache2/bin/apachectl �Ct

更改配置文件后,重新加载apache/usr/local/ apache2/bin/apachectl graceful

查看mysql编译参数cat/usr/local/mysql/bin/mysqlbug | grep configure

查看php编译参数/usr/local/php/bin/php -i |head

查看php加载模块/usr/local/php/bin/php �Cm

查看php.ini在哪里 /usr/local/php/bin/php �Ci|grep ‘ConfigurationFile’

查看extension_dir路径:/usr/local/php/bin/php �Ci|grep ‘extension_dir’


你可能感兴趣的:(linux,mysql,用户,local,数据库安装)