您的位置:首页 > 运维架构 > Apache

实战 linux 下 mysql+apache+php+gd 的安装和配置

2012-06-05 20:20 866 查看
原创 服务器

第一:说明,软件说明,和安装的目的

架设基于linux下的网站应用服务器,使用其支持php网页格式,安装前请将系统自带的mysql、apache卸掉。

关于tomcat的安装请参看:http://jedy82.blog.51cto.com/425872/271984

关于tomcat和apache的整合请参看:http://jedy82.blog.51cto.com/425872/310398

第二:本例操作环境

所使用的系统环境为 redhat as 4.6 内核为 2.6.9-67 系统使用最小化安装

第三:所需软件包

mysql-5.1.51

httpd 2.0.61

jpeg-6b

libpng-1.2.25

zlib-1.2.3

freetype-2.1.10

gd-2.0.35

php-5.3.3

phpMyAdmin-3.3.8-all-languages.tar.gz


在软件的官网上都能下到。

第四:安装软件包。

#############################################################################################

1、install mysql-5.1.51

shell> groupadd -g 101 mysql

shell> useradd -u 101 -g mysql -M mysql

shell> tar -xvzf mysql.**.tar.gz

shell> cd mysql.**

shell> ./configure --prefix=/usr/local/mysql-5.1.51 --localstatedir=/usr/local/mysql-5.1.51/data --with-unix-socket-path=/tmp/mysql.sock --with-named-curses-libs=/usr/lib/libncursesw.so.5

shell> make

shell> make install

shell> ln -s /usr/local/mysql-5.1.51 /usr/local/mysql

shell> cp support-files/mysql.server /etc/rc.d/init.d/mysqld \\将mysql注册为服务

shell> ln -s /etc/rc.d/init.d/mysqld /etc/rc3.d/S85mysqld \\开机启动mysql

shell> ln -s /etc/rc.d/init.d/mysqld /etc/rc5.d/S85mysqld \\开机启动mysql

shell> vi /etc/my.cnf \\更改mysql的配置文件,解决中文乱码问题

##############################################################################################

增加以下两行

[client]

default-character-set=utf8

[mysqld]

default-character-set=utf8

##############################################################################################

shell> cd /usr/local/mysql

shell> bin/mysql_install_db --user=mysql

shell> chown -R root.mysql .

shell> chown -R mysql data

shell> bin/mysqld_safe --user=mysql &

shell> vi /etc/profile

PATH="$PATH":/usr/local/mysql/bin \\增加命令路径

export PATH ....(略)....

shell> vi /etc/man.config

MANPATH /usr/local/mysql/man \\增加MAN路径

shell> ps -aux | grep mysql \\查看mysql有没有启动

以下以服务方式启动mysql

shell> services mysqld stop

shell> ps -aux | grep mysql \\查看mysql有没有停止

shell> services mysqld start

shell> ps -aux | grep mysql \\查看mysql有没有启动

shell> mysqladmin -u root -h localhost password pass \\设置mysqlroot的密码为pass

#############################################################################################

##

#############################################################################################

2、install httpd 2.0.61

shell>tar -xzvf httpd.**.tar.gz

shell>cd httpd.**

shell> ./configure --prefix=/usr/local/src/httpd-2.0.61 --enable-rewrite=shared --enable-speling=shared --enable-module=so --enable-so

shell> make && make install

shell> cd /usr/local

shell> ln -s /usr/local/src/httpd-2.0.61 httpd

shell> cd httpd

shell> ln -s /var/www/html htdocs

shell> ln -s /usr/httpd-2.0.61/conf /etc/httpd/conf

shell> vi /usr/local/httpd/conf/httpd.conf

#User nobody

#Group #-1

User nobody

Group nobody

#User nobody

#Group #-1

User nobody

Group nobody

ServerName 127.0.0.1 修改这一行 \\设置httpd服务器名

####shell > cp /usr/local/httpd/bin/httpd /etc/rc.d/init.d/httpd ###### \\开机启动httpd 忽略这一行

shell> cp /usr/local/httpd/bin/apachect1 /etc/rc.d/init.d/httpd \\将apache注册为系统服务

shell> more /etc/rc.d/init.d/httpd

#!/bin/sh

# chkconfig: 35 70 30 \\自行添加

# description: Apache \\自行添加

接着注册该服务

shell> chkconfig --add httpd \\注册httpd服务

shell> ln -s /etc/rc.d/init.d/httpd /etc/rc3.d/S85httpd \\开机启动httpd

shell> ln -s /etc/rc.d/init.d/httpd /etc/rc5.d/S85httpd \\开机启动httpd

shell> service httpd start \\启动服务

shell> ps -aux | grep http \\查看服务有没有启动成功

shell> netstat -tlnp | grep 80 \\查看端口有没有启动

shell> vi /etc/profile

PATH="$PATH":/usr/local/httpd/bin \\增加命令路径

export PATH ....(略)....

shell> vi /etc/man.config

MANPATH /usr/local/httpd/man \\增加MAN路径

完成

#############################################################################################

##

#############################################################################################

3、安装函数库

A、安装jpeg-6b

shell> cd /usr/local/src

shell> tar -zxvf jpegsrc.v6b.tar.gz

shell> cd jpeg-6b

shell> ./configure

shell> make

##编译成功,但是在安装的时候报错,系统提示不能将文件拷贝到/usr/local/man/man1这个目录,于是建立目录以后安装成功:

shell> mkdir -pv /usr/local/man/man1

shell> make install

shell> make install-lib \\以前因为没有执行这一步安装导致在编译php时报错

#############################################################################################

##

#############################################################################################

B、libpng-1.2.25的安装配置

shell> cd ../

shell> tar -jxvf libpng-1.2.25.tar.bz2

shell> cd libpng-1.2.25

shell> cp scripts/makefile.gcmmx makefile \\makefile.gcmmx是针对MMX指令集优化的

shell> make && make install

#############################################################################################

##

#############################################################################################

C、zlib-1.2.3安装配置

shell> cd ../

shell> tar -zxvf zlib-1.2.3.tar.gz

shell> cd zlib-1.2.3

shell> ./configure --shared \\shared生成zlib的共享库文件

shell> make && make install

#############################################################################################

##

#############################################################################################

D、freetype-2.1.10安装配置

shell> cd ../

shell> tar -jxvf freetype-2.1.10.tar.bz2

shell> cd freetype-2.1.10

shell> ./configure

shell> make && make install

#############################################################################################

##

#############################################################################################

E.gd-2.0.35安装配置

shell> cd ../

shell> tar -jxvf gd-2.0.35.tar.gz

shell> cd gd-2.0.35

shell> ./configure

配置完成后,注意输出的信息是否如下:

** Configuration summary for gd 2.0.15:

Support for PNG library: yes

Support for JPEG library: yes

Support for Freetype 2.x library: yes

Support for Xpm library: no

Xpm库以前安装不成功,如果程序部门不常用用,一般PNG/JPEG/FREETYPE三个库打开支持就行

shell> make && make install

shell> cp gd.h /usr/local/lib \\编译PHP的时候会缺少这个文件出错

#############################################################################################

##

#############################################################################################

4、install php-5.3.3

shell> tar -zxvf php-5.3.3.tar.gz

shell> cd php-5.3.3

shell> ./configure --prefix=/usr/local/php-5.3.3 --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php-5.3.3 --enable-sockets --with-mysql=/usr/local/mysql/ --with-zlib-dir=/usr/local/lib --with-png-dir=/usr/local/lib --with-gd --enable-mbstring

shell> make

shell> make install

shell> ln -sv /usr/local/src/php-5.3.3 /usr/local/php

shell> cp php.ini-development /usr/local/php/php.ini \\ 这个路径与你刚刚在 ./configure 当中那个 --with-config-file-path 设定有关!

shell> vi /usr/local/php/php.ini

#############################################################

改 short_open_tag = Off register_globals = Off

short_open_tag = On register_globals = On \\ 改了这个之后才能支持 <? ?> 这种标签,这个和php-5.3 之前的版本的不同之处,改了这个之后我们才能进行下一步的测试。如果不改的话,会造成访问php网页时不出现任何页面,但也不报错

#############################################################

shell> vi /usr/local/httpd/conf/httpd.conf

#############################################################

# 找到底下两行:

LoadModule php5_module modules/libphp5.so <==大约在 231 行处

AddType application/x-httpd-php .php <==这一行可以在 847 行处自行增加!

DirectoryIndex index.html index.html.var index.php <==在这一行(在398 行 )改成如下:增加index.php

DirectoryIndex index.htm index.html index.html.var index.php

#############################################################

shell> service httpd stop

shell> service httpd start

shell> netstat -tln | grep 80

5.install phpmyadmin

[root@redhat webapps]# tar /software/zxvf phpMyAdmin-3.3.8-all-languages.tar.gz

[root@redhat webapps]# mv phpMyAdmin-2.11.2-all-languages /phpmyadmin

[root@redhat webapps]# cd /phpmyadmin/

[root@redhat phpmyadmin]# cp ./libraries/config.default.php ./config.inc.php

[root@redhat phpmyadmin]# vi config.inc.php

$cfg['Servers'][$i]['auth_type'] = 'http'; //修改后 约在177行

安装完成

第五:测试

建一个测试文件 index.php 内容如下:

shell > more index.php

<?

phpinfo()

?>

只有在 php.ini 里改为 short_open_tag = On register_globals = On 才能使用 <? ?>

在浏览器里输入http://localhost/应该出现php的信息内容,测试说明成功

在浏览器里输入http://localhost/phpmyadmin 弹出phpmyadmin的登陆信息,输入前面设置的mysql用户名和密码 root/pass进入phpmyadmin

第六:常见错误

#############################################################################################

OK,基本的安装已经完成,如果重新起动APACHE出现:/usr/local/apache2/bin/apachectl start Syntax error on line 232 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

###

###关闭SELINUX

###

shell> vi /etc/selinux/config

#SELINUX=enforcing

SELINUX=disabled

shell> vi /etc/sysconfig/selinux

#SELINUX=enforcing

SELINUX=disabled

如果你碰到其他类似提示:

cannot restore segment prot after reloc: Permission denied

哪应该是SELinux的问题,可以考虑把它关闭。

#############################################################################################

#############################################################################################

##

#############################################################################################
本文出自 “jedy 网络技术&linux学习” 博客,请务必保留此出处http://jedy82.blog.51cto.com/425872/888815
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: