1、什么是LAMP
LAMP=linux+apache+mysql+php
Apache是一种web服务器。mysql是一种小型数据库。php是一种语言,可以写网站程序。
静态网页和动态网页的区别是否涉及数据库。
rpm包类似于windows的.exe程序,依赖平台redhat、centos。源码包大多是C语言写的,是看得见的、可以更改,且不依赖于平台。
2、安装mysql(按顺序安装)
(1)下载mysql-5.1.40-linux-i686-icc-glibc23.tar.gz 二进制免编译包
[root@localhost ~]# cd /usr/local/src/ //默认将安装包放在此目录[root@localhost src]# wget http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gz //下载32位mysql免编译包--2014-04-16 09:13:27-- http://syslab.comsenz.com/downloads/linux/mysql-5.1.40-linux-i686-icc-glibc23.tar.gzResolving syslab.comsenz.com... 180.153.5.50Connecting to syslab.comsenz.com|180.153.5.50|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 123633020 (118M) [application/octet-stream]Saving to: “mysql-5.1.40-linux-i686-icc-glibc23.tar.gz”100%[======================================>] 123,633,020 190K/s in 12m 44s2014-04-16 09:26:21 (158 KB/s) - “mysql-5.1.40-linux-i686-icc-glibc23.tar.gz” saved [123633020/123633020]
(2)解压mysql免编译包
[root@localhost src]# tar zxvf mysql-5.1.40-linux-i686-icc-glibc23.tar.gz
(3)将解压目录移到并改名为/usr/local/mysql
[root@localhost src]# mv mysql-5.1.40-linux-i686-icc-glibc23 /usr/local/mysql
(4)创建mysql用户,不能登录
[root@localhost src]# useradd -s /sbin/nologin mysql
(5)创建存放数据的目录/data/mysql
[root@localhost src]# cd /usr/local/mysql/[root@localhost mysql]# mkdir -p /data/mysql
(6)更改/data/mysql属性
[root@localhost mysql]# chown -R mysql:mysql /data/mysql
(7)初始化数据库
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlInstalling MySQL system tables...ERROR: 1004 Can't create file '/tmp/#sql52f_1_0.frm' (errno: 13)#出现这种问题,解决方法如下:[root@localhost mysql]# chmod -R 777 /tmp再重新初始化[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlInstalling MySQL system tables...OKFilling help tables...OK //出现两个ok就是初始化成功
(8)定义配置文件
[root@localhost support-files]# ls //配置文件模板binary-configure my-huge.cnf mysqld_multi.serverconfig.huge.ini my-innodb-heavy-4G.cnf mysql-log-rotateconfig.medium.ini my-large.cnf mysql.serverconfig.small.ini my-medium.cnf ndb-config-2-node.inimagic my-small.cnf[root@localhost support-files]# cp my-huge.cnf /etc/my.cnfcp: overwrite `/etc/my.cnf'? y//mysql配置文件默认放在/etc/my.cnf
(9)修改配置文件
[root@localhost support-files]# vim /etc/my.cnfkey_buffer_size = 128M //128M实验环境足够用了#log-bin=mysql-bin //主生成二进制文件,从读取二进制文件
(10)定义启动脚本并添加到服务
[root@localhost support-files]# cp mysql.server /etc/init.d/mysqld//拷贝文件到/etc/init.d目录下[root@localhost support-files]# chmod 755 /etc/init.d/mysqld //修改权限[root@localhost support-files]# chkconfig --add mysqld //添加服务[root@localhost support-files]# chkconfig --list |grep mysqldmysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off//查看服务,0-6表示运行级别,off和on表示所在的运行级别此服务的开启还是关闭。
(11)指定datadir
[root@localhost support-files]# vim /etc/init.d/mysqlddatadir=/data/mysql
(12)启动mysql
[root@localhost mysql]# /etc/init.d/mysqld startStarting MySQL.. SUCCESS! //启动成功
(13)mysql日志
[root@localhost mysql]# cd /data/mysql/[root@localhost mysql]# lsibdata1 ib_logfile1 localhost.localdomain.pid testib_logfile0 localhost.localdomain.err mysql
3、安装Apache
(1)下载httpd-2.2.16.tar.gz源码包
[root@localhost src]# wget http://syslab.comsenz.com/downloads/linux/httpd-2.2.16.tar.gz
(2)校验源码包
[root@localhost src]# md5sum httpd-2.2.16.tar.gz7f33f2c8b213ad758c009ae46d2795ed httpd-2.2.16.tar.gz
(3)解压源码包
[root@localhost src]# tar zxvf httpd-2.2.16.tar.gz
(4)编译安装
[root@localhost httpd-2.2.16]# ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre#报错1;checking for zlib location... not foundchecking whether to enable mod_deflate... configure: error: mod_deflate has been requested but can not be built due to prerequisite failures#解决方法:[root@localhost httpd-2.2.16]# yum list |grep zlibzlib.i686 1.2.3-29.el6 @anaconda-CentOS-201303020136.i386/6.4jzlib.i686 1.0.7-7.5.el6 basejzlib-demo.i686 1.0.7-7.5.el6 basejzlib-javadoc.i686 1.0.7-7.5.el6 basezlib-devel.i686 1.2.3-29.el6 basezlib-static.i686 1.2.3-29.el6 base[root@localhost httpd-2.2.16]# yum -y install zlib-devel[root@localhost httpd-2.2.16]# ./configure --prefix=/usr/local/apache2 --with-included-apr --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --with-pcre //再配置[root@localhost httpd-2.2.16]# make && make install //编译安装
最好去官网下载指定的包
(5)启动apache
[root@localhost ~]# /usr/local/apache2/bin/apachectl starthttpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName解决方法:[root@localhost ~]# vim /usr/local/apache2/conf/httpd.confServerName localhost[root@localhost ~]# netstat -anpt |grep httpdtcp 0 0 :::80 :::* LISTEN 7521/httpd
4、安装php
(1)下源码包php-5.3.27.tar.gz
[root@client src]# wget http://am1.php.net/distributions/php-5.3.27.tar.gz
(2)解压php
[root@localhost src]# tar zxvf php-5.3.27.tar.gz
(3)配置php
[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
报错1:
configure: error: xml2-config not found. Please check your libxml2 installation.
解决1:
[root@localhost php-5.3.27]# yum list |grep libxml2libxml2.i686 2.7.6-8.el6_3.4 @anaconda-CentOS-201303020136.i386/6.4libxml2.i686 2.7.6-14.el6 baselibxml2-devel.i686 2.7.6-14.el6 baselibxml2-python.i686 2.7.6-14.el6 baselibxml2-static.i686 2.7.6-14.el6 base[root@localhost php-5.3.27]# yum install -y libxml2-devel
报错2:
configure: error: Cannot find OpenSSL's
解决2:
[root@localhost php-5.3.27]# yum list |grep opensslopenssl.i686 1.0.1e-16.el6_5.7 @updateskrb5-pkinit-openssl.i686 1.10.3-15.el6_5.1 updatesopenssl-devel.i686 1.0.1e-16.el6_5.7 updatesopenssl-perl.i686 1.0.1e-16.el6_5.7 updatesopenssl-static.i686 1.0.1e-16.el6_5.7 updatesopenssl098e.i686 0.9.8e-17.el6.centos.2 base[root@localhost php-5.3.27]# yum install -y openssl-devel
报错3:
checking for BZip2 in default path... not foundconfigure: error: Please reinstall the BZip2 distribution
解决3:
[root@localhost php-5.3.27]# yum list |grep bzip2bzip2.i686 1.0.5-7.el6_0 @anaconda-CentOS-201303020136.i386/6.4bzip2-libs.i686 1.0.5-7.el6_0 @anaconda-CentOS-201303020136.i386/6.4bzip2-devel.i686 1.0.5-7.el6_0 base[root@localhost php-5.3.27]# yum install -y bzip2-devel
报错4:
configure: error: jpeglib.h not found.
解决4:
[root@localhost php-5.3.27]# yum list |grep jpeglibjpeg-turbo.i686 1.2.1-3.el6_5 updateslibjpeg-turbo-devel.i686 1.2.1-3.el6_5 updateslibjpeg-turbo-static.i686 1.2.1-3.el6_5 updatesopenjpeg.i686 1.3-10.el6_5 updatesopenjpeg-devel.i686 1.3-10.el6_5 updatesopenjpeg-libs.i686 1.3-10.el6_5 updates[root@localhost php-5.3.27]# yum install -y libjpeg-turbo-devel
报错5:
configure: error: png.h not found.
解决5:
[root@localhost php-5.3.27]# yum list |grep pngdvipng.i686 1.11-3.2.el6 baselibpng.i686 2:1.2.49-1.el6_2 baselibpng-devel.i686 2:1.2.49-1.el6_2 baselibpng-static.i686 2:1.2.49-1.el6_2 base[root@localhost php-5.3.27]# yum install -y libpng-devel
报错6:
configure: error: freetype.h not found.
解决6:
[root@localhost php-5.3.27]# yum list |grep freetypefreetype.i686 2.3.11-14.el6_3.1 basefreetype-demos.i686 2.3.11-14.el6_3.1 basefreetype-devel.i686 2.3.11-14.el6_3.1 base[root@localhost php-5.3.27]# yum install -y freetype-devel
报错7:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决7:
[root@localhost php-5.3.27]# rpm -ivh "http://www.lishiming.net/data/p_w_upload/forum/month_1211/epel-release-6-7.noarch.rpm"Retrieving http://www.lishiming.net/data/p_w_upload/forum/month_1211/epel-release-6-7.noarch.rpmwarning: /var/tmp/rpm-tmp.CBYMdI: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEYPreparing... ########################################### [100%] 1:epel-release ########################################### [100%][root@localhost php-5.3.27]# yum install -y libmcrypt-devel
(4)编译安装
[root@localhost php-5.3.27]# make && make install
5、apache支持php配置
(1)添加配置
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.confDirectoryIndex index.html index.php AddType application/x-httpd-php .php //支持php
(2)检测配置文件是否有错
[root@localhost ~]# /usr/local/apache2/bin/apachectl -tSyntax OK
(3)编辑测试页
[root@localhost ~]# vim /usr/local/apache2/htdocs/1.php
(4)测试
[root@localhost php-5.3.27]# curl localhost/1.phpwellcome to php ![root@localhost php-5.3.27]#
扩展学习
1、什么是扩展模块
apxs是一个为Apache HTTP服务器编译和安装扩展模块的工具,用于编译一个或多个源程序或目标代码文件为动态共享对象,使之可以用由mod_so提供的LoadModule指令在运行时加载到Apache服务器中。在Apache的配置文件中西东增加一行配置文件。
编译二进制文件的时候,所加载的一些模块,所有的可执行文件都会依赖一些包或库,这些库是由一些小模块。加载库的两种形式,一是所有模块全部直接编译进二进制文件中,但文件会越来越大,耗费资源。二是暂时编译进去一些常用的模块到二进制文件中,不常用的以扩展模块的形式加载。需要指定扩展模块的路径。
2、添加扩展模块
(1)Apache安装扩展模块 - mod_status
[root@localhost generators]# /usr/local/apache2/bin/apxs -i -a -c -n statuts mod_status.c [root@localhost generators]# vim /usr/local/apache2/conf/httpd.confLoadModule deflate_module modules/mod_deflate.soLoadModule expires_module modules/mod_expires.soLoadModule rewrite_module modules/mod_rewrite.soLoadModule php5_module modules/libphp5.soLoadModule statuts_module modules/mod_status.so #自动添加
(2)PHP扩展模块安装 - memcache
[root@localhost src]# wget http://www.lishiming.net/data/p_w_upload/forum/memcache-2.2.3.tgz[root@localhost src]# tar -zxvf memcache-2.2.3.tgz[root@localhost src]# cd memcache-2.2.3[root@localhost memcache-2.2.3]# /usr/local/php/bin/phpizeConfiguring for:PHP Api Version: 20090626Zend Module Api No: 20090626Zend Extension Api No: 220090626Cannot find autoconf. Please check your autoconf installation and the$PHP_AUTOCONF environment variable. Then, rerun this script.[root@localhost memcache-2.2.3]# yum install m4[root@localhost memcache-2.2.3]# yum install autoconf[root@localhost memcache-2.2.3]# /usr/local/php/bin/phpizeConfiguring for:PHP Api Version: 20090626Zend Module Api No: 20090626Zend Extension Api No: 220090626[root@localhost memcache-2.2.3]# ./configure --with-php-config=/usr/local/php/bin/php-config[root@localhost memcache-2.2.3]# make && make install[root@localhost memcache-2.2.3]# cp /usr/local/src/php-5.3.27/php.ini-development /usr/local/php/etc/php.ini[root@localhost memcache-2.2.3]# vim /usr/local/php/etc/php.iniextension = memcache.so
3、常用技巧
(1)查看Apache编译参数
[root@localhost etc]# cat /usr/local/apache2/build/config.nice#! /bin/sh## Created by configure"./configure" \"--prefix=/usr/local/apache2" \"--with-included-apr" \"--enable-deflate=shared" \"--enable-expires=shared" \"--enable-rewrite=shared" \"--with-pcre" \"$@"
(2)查看Apache加载的
[root@localhost modules]# /usr/local/apache2/bin/apachectl -M
(3)重新加载配置文件
[root@localhost modules]# /usr/local/apache2/bin/apachectl gracefulhttpd not running, trying to start
(4)查看mysql的配置参数
[root@localhost modules]# cat /usr/local/mysql/bin/mysqlbug|grep configure# This is set by configureCONFIGURE_LINE="./configure '--prefix=/usr/local/mysql' '--localstatedir=/usr/local/mysql/data' '--libexecdir=/usr/local/mysql/bin' '--with-comment=MySQL Community Server (GPL)' '--with-server-suffix=' '--enable-thread-safe-client' '--enable-local-infile' '--enable-assembler' '--with-pic' '--with-fast-mutexes' '--with-client-ldflags=-static' '--with-mysqld-ldflags=-static' '--with-zlib-dir=bundled' '--with-big-tables' '--with-readline' '--with-embedded-server' '--with-partition' '--with-innodb' '--without-ndbcluster' '--with-archive-storage-engine' '--with-blackhole-storage-engine' '--with-csv-storage-engine' '--without-example-storage-engine' '--with-federated-storage-engine' '--with-extra-charsets=complex' 'CC=icc -static-intel -static-libgcc' 'CFLAGS=-g -O3 -unroll2 -ip -mp -restrict' 'CXX=icpc -static-intel -static-libgcc' 'CXXFLAGS=-g -O3 -unroll2 -ip -mp -restrict'"
(5)查看php编译参数
[root@localhost modules]# /usr/local/php/bin/php -i |headphpinfo()PHP Version => 5.3.27System => Linux localhost.localdomain 2.6.32-358.el6.i686 #1 SMP Thu Feb 21 21:50:49 UTC 2013 i686Build Date => Apr 16 2014 11:23:29Configure Command => './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'Server API => Command Line InterfaceVirtual Directory Support => disabledConfiguration File (php.ini) Path => /usr/local/php/etcLoaded Configuration File => /usr/local/php/etc/php.ini
(6)查看php的加载模块
[root@localhost modules]# /usr/local/php/bin/php -m[PHP Modules]bz2Corectypedatedomereg
(7)查看php.ini文件在那里
[root@localhost modules]# /usr/local/php/bin/php -i |grep 'Configuration File'Configuration File (php.ini) Path => /usr/local/php/etcLoaded Configuration File => /usr/local/php/etc/php.ini
(8)查看extension_dir路径
[root@localhost modules]# /usr/local/php/bin/php -i |grep 'extension_dir'PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in Unknown on line 0extension_dir => /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626 => /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626sqlite3.extension_dir => no value => no value
(9)查看php依赖的库
[root@localhost modules]# ldd /usr/local/php/bin/php linux-gate.so.1 => (0x00d51000) libcrypt.so.1 => /lib/libcrypt.so.1 (0x001a6000) librt.so.1 => /lib/librt.so.1 (0x003ec000)