一删除apache+php+mysql:
判断是不是rpm安装如:rpm -q php 返回php版本,则是rpm安装,用 rpm -e php --nodeps 即可彻底删除系统自带的php
如果不返回PHP版本则是二进制安装,直接删除目录就可以!同理apache mysql也一样!
二安装apache
下载httpd-2.2.4.tar.gz
tar xzvf httpd-2.2.4.tar.gz
cd httpd-2.2.4
./configure --prefix=/usr/local/apache2 --enable-so --enable-mods-shared=all --enable-cgi --enable-rewrite --enable-deflate --with-mpm=worker
make
make install
三安装mysql
# chmod 755 mysql-5.0.45-linux-i686-glibc23.tar.gz //设置mysql-5.0.45-linux-i686-glibc23.tar.gz属性为755
# tar xzvf mysql-5.0.45-linux-i686-glibc23.tar.gz //解压
# cp -r mysql-5.0.45-linux-i686-glibc23 /usr/local //
# cd /usr/local/mysql //在/usr/local下
# mv mysql-5.0.45-linux-i686-glibc23 mysql //把mysql-5.0.45-linux-i686-glibc23命名为mysql
# cd mysql //
# groupadd mysql // 建立mysql组
# useradd mysql -g mysql //建立mysql用户并且加入到mysql组中
# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
在 support-files目录下有4个模版文件,我们选择其中一个座位Mysql的配置文件,覆盖/etc/my.cnf(系统默认的配置,其中设置了性能参数和Mysql的一些路径参数)
# cd /usr/local/mysql 进入mysql目录
# ./scripts/mysql_install_db --user=mysql //初试化表并且规定用mysql用户来访问。初始化表以后就开始给mysql和root用户设定访问权限
# chown -R root //设定root能访问/usr/local/mysql
# chown -R mysql data //设定mysql用户能访问/usr/local/mysql/data 里面存的是mysql的数据库文件.这个目录是在/etc/my.cnf中有配置,在mysql_install_db时产生。
# chown -R mysql data/ //设定mysql用户能访问/usr/local/mysql/data/mysql下的所有文件
# chgrp -R mysql //设定mysql组能够访问/usr/local/mysql
# ./usr/local/mysql/bin/mysqld_safe --user=mysql & 运行mysql 如果没有问题的话,应该会出现类似这样的提示:
[1] 42264
# Starting mysqld daemon with databases from /usr/local/mysql/var
如果出现 mysql ended这样的语句,表示Mysql没有正常启动,你可以到log中查找问题,Log文件的通常在/etc/my.cnf中配置。大多数问题是权限设置不正确引起的。
# /usr/local/mysql/bin/mysqladmin -u root password yourpassword //默认安装密码为空,为了安全你必须马上修改.
# cp support-files/mysql.server /etc/rc.d/init.d/mysqld 设置使mysql每次启动都能自动运行
# chmod 700 /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig --level 345 mysqld on
# service mysqld start //启动mysqld服务
# netstat -atln //查看3306端口是否打开。要注意在防火墙中开放该端口。
四安装php
1. 安装zlib (安装libpng和gd前需要先安装zlib),
# tar zxvf zlib-1.2.3.tar.gz
# cd zlib-1.2.3
# ./configure
# make;make install
2. 安装libpng,
# tar zxvf libpng-1.2.12.tar.gz
# cd libpng-1.2.12
# ./configure
# make;make install
3. 安装freetype,
# tar zxvf freetype-2.2.1.tar.gz
# cd freetype-2.1.10
# ./configure --prefix=/usr/local/freetype
# make;make install
4. 安装jpeg,
# tar zxvf jpegsrc.v6b.tar.gz
# cd jpeg-6b
# mkdir /usr/local/jpeg
# mkdir /usr/local/jpeg/bin
# mkdir /usr/local/jpeg/lib
# mkdir /usr/local/jpeg/include
# mkdir /usr/local/jpeg/man
# mkdir /usr/local/jpeg/man/man1
# ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static
# make;make install
5. 安装gd
# tar zxvf gd-2.0.35.tar.gz
# cd gd-2.0.35
# ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --with-png --with-zlib
//编译过程中会看到如下信息
** Configuration summary for gd 2.0.33:
Support for PNG library: yes
Support for JPEG library: yes
Support for Freetype 2.x library: yes
Support for Fontconfig library: no
Support for Xpm library: no
Support for pthreads: yes
//可以看到png 、 jpeg 、 freetype都已经安装上了
# make
# make install
6. 正式安装php
# tar zxvf php-5.2.3.tar.gz
# cd php-5.2.3
# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql --with-gd=/usr/local/gd --with-zlib --with-libpng --with-jpeg=/usr/local/jpeg --with-freetype=/usr/local/freetype --enable-sockets --with-iconv --enable-mbstring --enable-track-vars --enable-force-cgi-redirect --with-config-file-path=/usr/local/php5/etc
# make
# make install
7.整合php和apache
cp php.ini-dist /usr/local/php5/etc/php.ini
vi /usr/local/php5/etc/php.ini
将extension=php_mysql.dll前面的#去掉
注意在/usr/local/apache2/conf/httpd.conf加上下代码使apache执行PHP
AddType application/x-httpd-php .php
AddType application/x-httpd-php3 .php3
AddType application/x-httpd-php4 .php4
AddType application/x-httpd-php-source .phps
8. 安装ZendOptimizer
# tar zxvf ZendOptimizer-3.0.1-linux-glibc21-i386.tar.gz
# cd ZendOptimizer-3.0.1-linux-glibc21-i386
# ./install.sh
附:软件下载地址:
apache 2.2.4
mysql 5.0.22:
php 5.2.9:
zlib 1.2.3:
libpng 1.2.23:
freetype 2.3.5:
jpeg: gd 2.0.35: ===========================================================
类似提示错误:
httpd: Syntax error on line 104 of /usr/local/apache2/conf/httpd.conf: Cannot load /usr/local/apache2/modules/libphp5.so into server: /usr/local/apache2/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
解决方法:
1 关闭SELINUX
#vim /etc linux/config
找到SELINUX=enforcing 修改成
#SELINUX=enforcing
添加SELINUX=disabled 重启
2
2.不关闭SELINUX的方法:(从网上看到的)
# setenforce 0
# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so
# service httpd restart
# setenforce 1
=======================================
配置 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
改ServerName 127.0.0.1:80 和去#
重启apache
# /usr/local/apache2/bin/apachectl restart
在/usr/local/apache2/htdocs目录里建一内容为:
的PHP文件,命名为index.php, 输入URL地址:,查看PHP配置是否正确
如果不正确,可以重启机子在试