Linux下安装Apache2+Mysql5+PHP5(LAMP的搭建)
一、Linux下安装LAMP:安装mysql
- # tar -zvxf mysql-5.0.45-linux-i686-glibc23.tar.gz
- # mkdir -p /usr/local/mysql
- # cp -r mysql-5.0.45 /usr/local/mysql (修改解压缩后的文件名为mysql-5.0.45)
- # cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql //开机启动mysql(之前将复制过去的文件夹全部剪贴放在父文件夹mysql下面,并将之前的mysql-5.0.45文件夹删掉。)
- # 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即可
启动数据库
- /usr/local/mysql/bin/mysqld_safe --user=root& //在后台启动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 "123456"
Mysql修改密码,
/路径/mysql/bin/mysqladmin –u –root password 密码
再次登录:/路径/mysql/bin/ mysql –u root -p
#p#
二、Linux下安装LAMP:安装GD库(让PHP支持GIF,PNG,JPEG)
a.安装 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/Software/
- # tar -zvxf jpegsrc.v6b.tar.gz
- # cd jpeg6 (进入解压的文件夹,名称可能不一样,并不影响结果。)
- # ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
- # make
- # make install
b. 安装zlib
- # cd /root/Software/
- # tar -zxvf zlib-1.2.3.tar.gz
- # cd zlib.1.2.3
- # mkdir /usr/local/zlib
- # ./configure --prefix=/usr/local/zlib
- # make
- # make install
c. libpng包
- # cd /root/Software/
- # tar -jvxf libpng-1.2.37.tar.bz2
- # cd libpng-1.2.37 (进入解压的文件夹,名称可能不一样)
- # ./configure --prefix=/usr/local/libpng
- # make
- #> make install
d. 安装 freetype
- # cd /root/Software/
- # tar -zvxf freetype-2.1.9.tar.gz
- # cd freetype-2.1.9
- # mkdir -p /usr/local/freetype
- # ./configure --prefix=/usr/local/freetype
- # make
- # make install
e.安装GD库
- # cd /root/Software/
- # tar -zvxf gd-2.0.33.tar.gz
- # mkdir -p /usr/local/gd2
- # cd gd-2.0.33
- # ./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg6 --with-zlib-dir=/usr/local/zlib --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype
- # make
- # make install
e.安装Curl库
- # cd /root/Software/
- # tar -zxf curl-7.15.3.tar.gz
- # mkdir -p /usr/local/curl
- #cd curl-7.15.3
- # ./configure --prefix=/usr/local/curl
- # make
- # make install
#p#
三、Linux下安装LAMP:安装apache2
- # cd /roo/Software/
- # tar -zvxf httpd-2.2.6.tar.gz
- # cd httpd-2.2.6
- # mkdir -p /usr/local/apache2
- # ./configure --prefix=/usr/local/apache2 --enable-modules=so --enable-rewrite
- # make
- # make install
- # /usr/local/apache2/bin/apachectl -k start //启动apahce
用浏览器查看 http://localhost ,得到it works,说明apache已设置成功了.
- # /usr/local/apache2/bin/apachectl -k stop //停止apache
#p#
四、Linux下安装LAMP:安装php5,php5(必须有libxml2支持)
- a. 安装libxml2
- # cd /root/Software/
- # tar -zvxf libxml2-2.6.27.tar.gz
- # cd libxml2-2.6.27
- # mkdir -p /usr/local/libxml2
- # ./configure --prefix=/usr/local/libxml2
- # make
- # make install
启动
b.安装 libxslt (可选安装)
- # cd /root/Software/
- # tar -zvxf libxslt-1.1.24.tar.gz
- # mkdir -p /usr/local/libxslt
- # cd libxslt-1.1.24
- # ./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
- # make
- # make install
c.安装php5
- # cd /root/Software/
- # tar -zvxf php-5.2.5.tar.gz
- # mkdir -p /usr/local/php5
- # cd php-5.2.5
- # ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --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-trace-vars --with-mysql=/usr/local/mysql --enable-mbstring=all --with-curl=/usr/local/curl --enable-mbregex --with-config-file-path=/usr/local/php5 --enable-ftp --enable-soap --with-xsl=/usr/local/libxslt
- # make
- # make install
- # cp php.ini-dist /usr/local/php5/php.ini
#p#
五:Linux下安装LAMP:重新设置apache2让他支持php
- # cd /usr/local/apache2/conf
- # vim httpd.conf
在LoadModule php5_module modules/libphp5.so
添加AddType application/x-httpd-php .php
在DirectoryIndex中添加 index.php
OK,基本的安装已完成.
重新起动APACHE:
- # /usr/local/apache2/bin/apachectl start
将apache和mysql服务添加到启动项的方法:
1. 打开或者用vi编辑 /etc/rc.d/rc.local
2. 在文本中添加以下两行:
- /usr/local/apache2/bin/apachectl start
- /usr/local/mysql/bin/mysqld_safe --user=root &
好了,web环境apache2+mysql5+php5就配置完成了。他们已经能开始工作了。
其中apache2、mysql和php.ini的详细设置请参阅其它文档。
【编辑推荐】