lamp(apache2.2mysql5.0php5.3)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了lamp(apache2.2mysql5.0php5.3)相关的知识,希望对你有一定的参考价值。
一、下载源码包
[[email protected] ~]# mkdir -p /www/xiazai //新建文件夹
[[email protected] ~]# cd /www/xiazai //进入放置软件包目录
[[email protected] xiazai]# wget http://mirrors.sohu.com/apache/httpd-2.2.34.tar.gz下载apache
[[email protected] xiazai]# wget http://mirrors.sohu.com/mysql/MySQL-5.0/mysql-5.0.95-linux-x86_64-glibc23.tar.gz
http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.55-linux2.6-x86_64.tar.gz
[[email protected] xiazai]# wget http://mirrors.sohu.com/php/php-5.3.27.tar.gz
二、安装mysql
[[email protected] xiazai]# tar -zxvf mysql-5.0.95-linux-x86_64-glibc23.tar.gz //解压
1、把解压完的数据移动到[[email protected] xiazai]# mkdir -p /www/server
[[email protected] xiazai]# mv mysql-5.0.95-linux-x86_64-glibc23 /www/server/mysql //移动到mysql目录下
[[email protected] xiazai]# useradd -s /sbin/nologin -M mysql //建立用户
[[email protected] xiazai]# cd /www/server/mysql //进入mysql安装目录
[[email protected] mysql]# mkdir -p /www/data/mysqldata //新建数据库存放地址
[[email protected] mysql]# chown -R mysql:mysql /www/data/mysqldata //设置mysql数据库存放目录权限
[[email protected] mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/www/data/mysqldata
--user 定义数据库的所属主, --datadir 定义数据库安装到哪里,建议放到大空间的分区上,这个目录需要自行创建。这一步骤很关键,如果你看到两个 “OK” 说明执行正确
4、拷贝配置文件
[[email protected] mysql]# cp support-files/my-large.cnf /etc/my.cnf //拷贝配置文件
5、拷贝启动脚本文件并修改其属性
[[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected] mysql]# chmod 755 /etc/init.d/mysqld
6、修改启动脚本
[[email protected] mysql]# yum install vim*
[[email protected] mysql]# vim /etc/init.d/mysqld //编辑数据库主配置文件
需要修改的地方有 “datadir=/data/mysql” (前面初始化数据库时定义的目录)
basedir=/www/server/mysql
datadir=/www/data/mysqldata
7、把启动脚本加入系统服务项,并设定开机启动,启动mysql
[[email protected] mysql]# chkconfig --add mysqld
[[email protected] mysql]# chkconfig mysqld on
[[email protected] mysql]# service mysqld start
[[email protected] mysql]# netstat -lnp |grep mysql //查看端口是否运行
[[email protected] mysql]# echo "PATH=$PATH:/www/server/mysql/bin" >> /etc/profile
echo "PATH=$PATH:/www/wdlinux/apache_php-5.6.21/bin" >> /etc/profile
/www/wdlinux/apache_php-5.6.21/bin/
[[email protected] mysql]# source /etc/profile 设置变量开机加载
#/www/server/mysql/bin/mysqladmin -u root password 75dn289z //设置MySQL密码
8、测试
[[email protected] mysql]# shutdown -r now //重启
[[email protected] ~]# mysql -uroot -p
三、安装Apache
首先添加依赖应用
yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libpng libpng-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses curl openssl-devel gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel readline-devel libxslt-devel expat-devel xmlrpc-c xmlrpc-c-devel zlib-devel pcre pcre-devel apr apr-devel
yum install gcc zlib-devel openssl-deve
[[email protected] xiazai]# tar -zxvf httpd-2.2.32.tar.gz //解压缩包
2、进入目录
[[email protected] xiazai]# cd httpd-2.2.32
[[email protected] httpd-2.2.32]# mkdir -p /www/server新建安装目录
3、编译
[[email protected] httpd-2.2.31]# ./configure --prefix=/www/server/httpd --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,后面的参数同理。
如果这一步你出现了这样的错误 error: mod_deflate has been requested but can not be built due to prerequisite failures
解决办法 yum install -y zlib-devel
为了避免在make的时候出现错误,所以最好是提前先安装好一些库文件
[[email protected] httpd-2.2.31]## yum install -y pcre pcre-devel apr apr-devel
[[email protected] httpd-2.2.32]# echo $?
0
[[email protected] httpd-2.2.32]# make install
[[email protected] httpd-2.2.31]## echo $?
[[email protected] httpd-2.2.31]# vi /etc/init.d/httpd新建启动脚本
[[email protected] httpd-2.2.31]# chmod 775 /etc/init.d/httpd //设置权限
[[email protected] httpd-2.2.31]# chkconfig --add httpd
[[email protected] httpd-2.2.31]# chkconfig httpd on
http://note.youdao.com/noteshare?id=e4485bc811f68e4a70bb8f8be7b1f16b httpd启动脚本
四、安装PHP
[[email protected] httpd-2.2.31]# cd /www/xiazai/
下面我们来 添加 jpeg 格式文件的支持
wget http://y.w-jiahao.cn/by/la/jpegsrc.v8b.tar.gz
tar -zxvf jpegsrc.v8b.tar.gz
cd jpeg-8b
./configure --prefix=/www/server/jpeg --enable-shared --enable-static
make && make install
使用php mcrypt 前必须先安装Libmcrypt
libmcrypt源码安装方法:
cd /www/xiazai
wget http://y.w-jiahao.cn/by/la/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/www/server/libmcrypt
make
make install
1、解压
[[email protected] src]# tar -zxvf php-5.3.27.tar.gz
2、配置参数
[[email protected] xiazai]# cd php-5.3.27
[[email protected] php-5.3.27]# ./configure --prefix=/www/server/php --with-apxs2=/www/server/httpd/bin/apxs --with-config-file-path=/www/server/php/etc --with-mysql=/www/server/mysql --with-libxml-dir --with-gd --with-jpeg-dir=/www/server/jpeg--with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt=/www/server/libmcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir --with-gd --with-jpeg-dir=/usr/local/jpeg--with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --disable-ipv6
遇到如下错误
configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法 yum install -y libxml2-devel
configure: error: Cannot find OpenSSL‘s <evp.h>
解决办法yum install -y openssl openssl-devel
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决办法yum install -y bzip2 bzip2-devel
configure: error: png.h not found
解决办法 yum install -y libpng libpng-devel
configure: error: freetype.h not found.
解决办法yum install -y freetype freetype-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt
[[email protected] php-5.3.27]# echo $?
[[email protected] php-5.3.27]# make
报错:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1
解决办法
这是由于内存小于1G所导致.
在./configure加上选项:
--disable-fileinfo
有时候我们编译php的时候会出现以下错误:
make ***[libphp5.la] Error 1
处理方法:
安装两个rpm包#yum -y install libtool.x86_64 libtool-ltdl.x86_64 libtool-ltdl-devel.x86_64
然后make clean;make
[[email protected] php-5.3.27]# echo $?
[[email protected] php-5.3.27]# make install
[[email protected] php-5.3.27]# echo $? ///待续
3、拷贝配置文件
[[email protected] php-5.3.27]# cp php.ini-production /www/server/php/etc/php.ini 四、apache结合php
Apache主配置文件为:/www/server/httpd/conf/httpd.conf
[[email protected] php-5.3.27]# vi /www/server/httpd/conf/httpd.conf
找到
<IfModule dir_module>
x
DirectoryIndex index.html
</IfModule>
改为
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
找到AddType application/x-gzip .gz .tgz 在下面添加AddType application/x-httpd-php .php 314
找到#ServerName www.example.com:80改为ServerName localhost:80 102
#AllowOverride None改为 AllowOverride All
#Include conf/extra/httpd-vhosts.conf改为Include conf/extra/httpd-vhosts.conf
wq保存
六、测试PHP
[[email protected] conf]# curl localhost 查看是否正常显示It works!
测试php
[[email protected] conf]#echo "<?php phpinfo();?>" >/www/server/httpd/htdocs/index.php 添加php文档
http://note.youdao.com/noteshare?id=731fc872a408734d6b1b803a1a3ec193 httpd启动脚本
初次使用浏览器访问web服务的时候,可能无法访问,这是因为防火墙的缘故。请运行下面的命令
[[email protected] ~]# iptables -F 关闭防火墙
截图范:
==============================
curl组件安装
进入安装目录/usr/local/src/php-5.3.27/ext/curl
执行/www/server/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-curl=/usr/local/php/lib/php/extensions
make && make install
在php.ini添加路径
extension="/usr/local/php/lib/php/extensions/curl.so"
==============================================
Zend安装
换成:vim /www/server/php/etc/php.ini
[Zend]
zend_extension = /www/server/zujian/ZendGuardLoader.so
zend_loader.enable = 1
配置ionCube:
修改php.ini 在文件尾部添加以下代码:
[ionCube Loader]
zend_extension="/usr/local/ioncube/ioncube_loader_lin_php5.4.so"
#################################
php添加开启pdo_mysql扩展模块
/www/server/php/bin/phpize
./configure --with-php-config=/www/server/php/bin/php-config --with-pdo-mysql=/www/server/mysql
make
make install
手动开启PDO,在php-ini文件上开启,连接数据库用。mysql开启PDO, 在php.ini加上extension=pdo_mysql.so,extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613", 再重启php即可
mysqli安装
/www/server/php/bin/phpize
./configure --with-php-config=/www/server/php/bin/php-config --with-mysqli=/www/server/mysql/bin/mysql_config
make
make install
############################
Redis扩展安装
wget http://pecl.php.net/get/redis-3.0.0.tgz
mv redis-3.0.0.tgz redis-3.0.0.tar.gz
tar -zxvf redis-3.0.0.tar.gz
cd redis-3.0.0
/www/server/php/bin/phpize
./configure --with-php-config=/www/server/php/bin/php-config
以上是关于lamp(apache2.2mysql5.0php5.3)的主要内容,如果未能解决你的问题,请参考以下文章