Linux下源码编译安装apache2,PHP5,mysql5

作者:简简单单 2013-11-18

#apache

 代码如下 复制代码
./configure --prefix=/usr/local/apache --enable-modules=so --enable-rewrite
make
make install
cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
cd /etc/rc.d/init.d
#vi httpd
#在文件首部#!/bin/bash行下,加入以下几行
# chkconfig: 2345 50 40
# description: This is a Internet www Server
#说明一下,直接调用chkconfig是不行的,必须加上以上两行。
#description是描述这个服务用的,一定要写上对服务的描述,而且不可以是中文的,
#chkconfig: 第一组数字是系统运行级2345表示的是将要设为启动的系统运行级别
#第二个数字是优先级,00优先级最高,当然考虑到依赖性,你的服务的优先级不宜过高
#如果,比自己依赖的服务的优先级更高,那么您的服务将无法正常启动
#第三组数字就是杀死服务的优先级
chkconfig --add httpd
 
#mysql
 代码如下 复制代码
./configure --prefix=/usr/local/mysql --localstatedir=/mydata/web/mysql --with-charset=utf8 --with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
#创建mysql用户和用户组
groupadd mysql
useradd -g mysql mysql
chown -R root /usr/local/mysql
chgrp -R mysql /usr/local/mysql
chown -R mysql /var/mysql
#初始化权限数据库,并不需要启动mysql
scripts/mysql_install_db --user=mysql
#启动mysql, "&"是后台运行
/usr/local/mysql/bin/mysqld_safe --user=mysql&
#更改root密码
/usr/local/mysql/bin/mysqladmin -u root -p password "123456"
#设置为开机自启动
cd /etc/rc.d/init.d
cp /usr/local/mysql/share/mysql/ mysql.server mysqld
chmod +x mysqld
chkconfig --add mysqld
 
#PHP
 代码如下 复制代码
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-apxs2=/usr/local/apache/bin/apxs --with-gd --with-zlib --with-png --with-freetype-dir --with-config-file-path=/usr/local/php/etc --enable-gd-native-ttf --with-ttf --enable-memory-limit --enable-zend-multibyte --disable-ipv6 --disable-path-info-check --with-iconv --disable-debug --with-mail --enable-mbregex --with-curl --enable-mbstring=all --enable-zip --enable-exif --with-jpeg-dir=/usr/lib64/
make
make install
#配置apache
 代码如下 复制代码
# vi /usr/local/apache/conf/httpd.conf
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
#开放80端口

 代码如下 复制代码
#iptables -A INPUT -i eth0 -p TCP --dport 80 -j ACCEPT

四 、整合apache 与php

 代码如下 复制代码
# vi /usr/local/apache2/conf/httpd.conf

在最后一行加上:

 代码如下 复制代码
AddType application/x-httpd-php .php

查找:(设置 WEB 默认文件)

 代码如下 复制代码
DirectoryIndex index.html

替换为:

 代码如下 复制代码
DirectoryIndex index.php index.html index.htm //在 WEB 目录不到默认文件,httpd 就会执行 /var/www/error/noindex.html

找到这一段:

 代码如下 复制代码
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none

更改为AllowOverride all
允许apache rewrite

保存httpd.conf,退出。

 代码如下 复制代码

# /usr/local/apache2/bin/apachectl restart //重启 Apache

五、 测试

 代码如下 复制代码
vi /usr/local/apache2/htdocs/test.php

新增加下面一行,并保存。

 代码如下 复制代码

# chmod 755 /usr/local/apache2/htdocs/phpinfo.php

用浏览器打开 http://locahost/test.php

或者 http://本机ip/test.php
(如ip为192.168.4.2 则 http://192.168.4.2/test.php)

当看到php页面时表示成功!

相关文章

精彩推荐