在linux上面LAMP安装
一、 Apache安装
1. download httpd 2.2.16
- # mkdir -p /usr/local/apache2
生成/usr/local/apache2目录
2. ./configure \
- --prefix=/usr/local/apache2 \
- --enable-so \
- --enable-mods-shared=all \
- --with-included-apr \
- --enable-proxy=shared \
- --enable-cache=shared \
- --enable-file-cache=shared \
- --enable-disk-cache=shared \
- --enable-mem-cache=shared
- if compile error show zlib not found, then use command check:
- rpm -qa | grep -i zlib
- if zlib is already installed, zlib-devel is needed to be installed:
- yum install zlib-devel
- we can use ./configure -help | grep mpm to see module options. After installation, we can use httpd -l to see compiled modules.
- make
- make install
- # vi /usr/local/apache2/conf/httpd.conf
设置DocumentRoot 的路径
保存退出,现在就这么简单配置apache。
- # /usr/local/apache2/bin/apachectl -k start
启动apahce
用浏览器查看,得到It works,说明apache已经配置成功了。
- # /usr/local/apache2/bin/apachectl -k stop
停止apache
- # /usr/local/apache/bin/apachectl restart
重启Apache
把httpd 添加到系统的启动项里
- # cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
- # chmod 700 /etc/rc.d/init.d/httpd
- # vi /etc/rc.d/init.d/httpd
在第三行后增加
- # Comments to support chkconfig on RedHat Linux
- # chkconfig: 2345 90 90
- # description:http server
注意:没有这几行,在使用chkconfig时会提示你:service httpd does not support chkconfig。
- chkconfig –add httpd
- chkconfig –level 345 httpd on
这样,在运行级别345上httpd就可以自动启动了。
二、Mysql的安装
- # cd /root
- # tar -zvxf mysql-5.1.32-linux-i686-glibc23.tar.gz
- # mkdir -p /usr/local/mysql (省略也可)
- # cp -r mysql-5.1.32-linux-i686-glibc23/* /usr/local/mysql
- # cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
添加mysql用户及用户组
- # groupadd mysql
- # useradd -g mysql mysql
修改mysql目录权限
- # chown -R root /usr/local/mysql
- # chgrp -R mysql /usr/local/mysql
- # chown -R mysql /usr/local/mysql/data
生成mysql系统数据库
- # /usr/local/mysql/scripts/mysql_install_db --user=mysql&
启动mysql服务
- # /usr/local/mysql/bin/mysqld_safe --user=mysql&
如出现 Starting mysqld daemon with databases from /usr/local/mysql/data
代表正常启动mysql服务了, 按Ctrl + C 跳出
修改 mysql 的 root 密码
- # /usr/local/mysql/bin/mysqladmin -u root -p password "wengdo"
wengdo 这里可以换为你自己的密码
把你编译目录的一个脚本COPY过去
- # cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
- # chkconfig --add mysqld
用ntsysv设置使mysql每次启动都能自动运行 。
好了,至此mysql安装完毕,你可以这样起动你的mysql服务
- # /etc/rc.d/init.d/mysqld start
下面这步比较关键,
- # ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
- # ln -s /usr/local/mysql/include/mysql /usr/include/mysql
大家可以不做这步,大可以在编译其他软件的时候自定义myslq的库文件路径,但我还是喜欢把库文件链接到默认的位置,这样你在编译类似PHP,Vpopmail等软件时可以不用指定mysql的库文件地址。
三、安装GD库
(如果你用系统自带的GD库,可以省略这一步)
安装 jpeg6
建立目录:
- # mkdir -p /usr/local/jpeg6
- # mkdir -p /usr/local/jpeg6/bin
- # mkdir -p /usr/local/jpeg6/lib
- # mkdir -p /usr/local/jpeg6/include
- # mkdir -p /usr/local/jpeg6/man
- # mkdir -p /usr/local/jpeg6/man1
- # mkdir -p /usr/local/jpeg6/man/man1
- # cd /root
- # tar -zvxf jpegsrc.v6b.tar.gz
- # cd jpeg-6b
- # ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
- # make
- # make install
安装libpng
- # cd /root
- # tar -zvxf libpng-1.2.35.tar.gz
- # cd libpng-1.2.35
- mkdir -p /usr/local/libpng
- # ./configure --prefix=/usr/local/libpng
- # make
- # make install
安装 freetype
- # cd /root
- # tar -zvxf freetype-2.3.9.tar.gz
- # cd freetype-2.3.9
- # mkdir -p /usr/local/freetype
- # ./configure --prefix=/usr/local/freetype
- # make
- # make install
安装zlib
安装curl
安装GD库
- # cd /root
- # tar -zvxf gd-2.0.35.tar.gz
- # mkdir -p /usr/local/gd2
- # cd gd-2.0.35
- # ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6/ --with-png=/usr/local/lib/ --with-zlib=/usr/local/lib/ --with-freetype=/usr/local/freetype/ --enable-m4_pattern_allow
- # make
- # make install
四、安装PHP5
php5必须有libxml2支持!
安装libxml2
- # cd /root
- # tar -zxvf libxml2-2.6.19.tar.gz
- # cd libxml2-2.6.19
- # mkdir -p /usr/local/libxml2
- # ./configure --prefix=/usr/local/libxml2
- # make
- # make install
安装php5
- # cd /root
- # tar -zvxf php-5.2.9.tar.gz
- # mkdir -p /usr/local/php
- # cd php-5.2.9
- # ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs
- --with-mysql=/usr/local/mysql/
- --with-curl=/usr/local/curl --enable-ftp
- --with-libxml-dir=/usr/local/libxml2
- --with-gd=/usr/local/gd2/
- --with-jpeg-dir=/usr/local/jpeg6/
- --with-zlib-dir=/usr/local/zlib/
- --with-png-dir=/usr/local/libpng/
- --with-freetype-dir=/usr/local/freetype/
- --enable-mbstring
- # make
- # make install
- # cp php.ini-dist /usr/local/php/lib/php.ini (别忘记了)
其中./configure 后的
- --prefix=/usr/local/php
- --with-apxs2=/usr/local/apache2/bin/apxs
- --with-mysql=/usr/local/mysql/
- --with-libxml-dir=/usr/local/libxml2
是必要的选项
- --with-gd=/usr/local/gd2/
- --with-jpeg-dir=/usr/local/jpeg6/
- --with-png=/usr/local/lib
- --with-zlib-dir=/usr/lib
- --with-freetype-dir=/usr/local/freetype
这是让PHP支持GD库的配置选项
- --with-curl=/usr/local/curl 支持CURL库
- --enable-ftp 打开FTP库函数支持
- --enable-soap --with-xsl=/usr/local/libxslt --enable-xslt
让PHP支持SOAP, 上面这些一般用得少, 可以去掉
五、安装 ZendOptimizer
- # cd /root
- # tar -zxvf ZendOptimizer-3.3.0a-linux-glibc21-i386.tar.gz
- # cd ZendOptimizer-3.3.0a-linux-glibc21-i386
- # ./install.sh
然后出现图形界面,按提示Next
六、配置一些信息
配置 httpd.conf 让apache支持PHP
- # vi /usr/local/apache2/conf/httpd.conf
找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容
- AddType application/x-httpd-php .php
- AddType application/x-httpd-php-source .phps
重启apache
- # /usr/local/apache2/bin/apachectl restart
在你设置的目录里建一内容为 PHP文件, 输入URL地址查看PHP配置是否正确