您好,欢迎访问一九零五行业门户网

Linux下Apache+Mysql+PHP的安装与配置

(1)apache的安装与配置 思路:首先在官网下载apache源码,本系统下载版本为httpd-2.2.17.tar.gz,下面几步为在终端的配置命令 tar zxvf httpd-2.2.17.tar.gz cd httpd-2.2.17 ./configure --prefix=/usr/local/apache make make install service httpd sta
(1)       apache的安装与配置
思路:首先在官网下载apache源码,本系统下载版本为httpd-2.2.17.tar.gz,下面几步为在终端的配置命令
tar zxvf httpd-2.2.17.tar.gz
cd httpd-2.2.17
./configure --prefix=/usr/local/apache
make
make install
service httpd start
如果出现:
starting httpd: httpd: could not reliably determine the server's fully qualified domain name, using 222.31.76.227 for servername
                                                           [  ok  ]
说明安装成功!
如果希望apache开机自启动的话,可以通过以下命令在/etc/rc.d/rc.local加入自启动命令:
echo service httpd start>>/etc/rc.d/rc.local
测试apache
在/var/www/html目录下建立index.html文件
welcome to apache!!
保存后,在浏览器上输入http://xxx.xxx.xxx.xxx(web服务器的ip)查看结果
注意:iptables必须关闭或者将80端口加到iptables中
(2)       mysql-client的安装与配置
思路:由于mysql没有源码包可以下载,所以本系统使用mysql的二进制安装包,使用版本为mysql-5.5.10-linux2.6-x86_64.tar.gz,下面几步为在终端的配置命令(可直接粘贴)
tar zxvf mysql-5.5.10-linux2.6-x86_64.tar.gz
cd /usr/local
ln -s /home/software/mysql-5.5.10-linux2.6-x86_64 mysql
cd mysql/
vi install-binary
看到以下部分为安装步骤
to install and use a mysql binary distribution, the basic command
sequence looks like this:
shell> groupadd mysql
shell> useradd -r -g mysql mysql
shell> cd /usr/local
shell> tar zxvf /path/to/mysql-version-os.tar.gz
shell> ln -s full-path-to-mysql-version-os mysql
shell> cd mysql
shell> chown -r mysql .
shell> chgrp -r mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -r root .
shell> chown -r mysql data
# next command is optional
shell> cp support-files/my-medium.cnf /etc/my.cnf
shell> bin/mysqld_safe --user=mysql &
# next command is optional
shell> cp support-files/mysql.server /etc/init.d/mysql.server   //开机自启动(后面还需几步)
如果已经安装在安装操作系统时已经安装过mysql,那么前6步(高亮部分)目前已经完成
(需要注意的是 data目录下存放的就是一个又一个数据库,所以,必须将权限设置为mysql,否则,mysql本身进不去,配置就会失败)
chown -r mysql.mysql .
scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/
chown -r root .
chown -r mysql data
cp support-files/my-medium.cnf /etc/my.cnf
bin/mysqld_safe --user=mysql &
service mysqld start
若显示:
starting mysql..                                           [  ok  ]
则说明mysql已成功启用!
使用  mysql_install_db --user=mysql  创建新的mysql授权表,使用者为mysql
使用 mysqld_safe --user=mysql &     以用户名user_name或数字用户id user_id运行mysqld服务器。(本文中的“用户”指系统登录账户,而不是 授权表中的mysql用户)
让mysql自启动
cp support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
chkconfig --add mysqld
如果遇到以下问题:
启动mysql出错,提示:
starting mysqld daemon with databases from /usr/local/mysql/data
stopping server from pid file /usr/local/mysql/data/xmcncn.pid
061103 15:25:32  mysqld ended
解决方法:
vi /etc/my.cnf
看看[mysqld]下有没有
port  = 3306
添加上就可以了
touch /tmp/mysql.sock
killall -9 mysqld
/usr/local/mysql/bin/mysqld_safe -user=mysql &
成功启动
(3)php的安装与配置
首先,安装php前,以下包可能会需要安装:zlib-1.2.3.tar.gz、libpng-1.2.24.tar.gz、freetype-2.3.11.tar.gz、libtool-2.4.tar.gz、jpegsrc.v6b.tar.gz、autoconf-2.61.tar.gz、gd-2.0.35.tar.gz、libxml2-2.7.3.tar.gz
在官网下载php源码,本系统下载版本为php-5.3.6.tar,下面几步为在终端的配置命令(可直接粘贴)
cd /home/software/
tar -xvf php-5.3.6.tar
cd php-5.3.6
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-openssl-dir=/usr/lib/openssl --with-openssl
配置后若如下显示license,则说明成功,否侧可能还缺少上述的包。

checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... gnu/linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes

creating libtool
appending configuration tag cxx to libtool
generating files
updating cache ./config.cache
creating ./config.status

creating main/internal_functions.c
creating main/internal_functions_cli.c
+----------------------------------------------------------------------------------------+
| license:                                              |
| this software is subject to the php license, available in this     |
| distribution in the file license.  by continuing this installation  |
| process, you are bound by the terms of this license agreement.  |
| if you do not agree with the terms of this license, you must abort |
| the installation process at this point.                        |
+-----------------------------------------------------------------------------------------+
thank you for using php.
make
make test  //可以不做
make install
cp php.ini-development /etc/php.ini
vi /usr/local/apache/conf/httpd.conf
加入一句话:
addtype application/x-httpd-php .php
cd /var/www/html
vi index.php
新建php测试代码为:
重启apache,重启前要先修改/etc/selinux/config,将selinux=enforcing 改成selinux=disabled:
vi /etc/selinux/config
# this file controls the state of selinux on the system.
# selinux= can take one of these three values:
#       enforcing - selinux security policy is enforced.
#       permissive - selinux prints warnings instead of enforcing.
#       disabled - selinux is fully disabled.
selinux=disabled
# selinuxtype= type of policy in use. possible values are:
#       targeted - only targeted network daemons are protected.
#       strict - full selinux protection.
selinuxtype=targeted
service httpd restart
出现以下语句说明重启成功:
stopping httpd:                                            [  ok ]
starting httpd: httpd: could not reliably determine the server's fully qualified domain name, using 222.31.76.227 for servername
                                                         [  ok ]
在浏览器输入http://xxx.xxx.xxx.xxx/index.php,若显示phpinfo信息说明php配置成功。
若能显示phpinfo信息,但发现无法连接数据库(没有mysql的信息),说明php与mysql相连的模块包没有安装成功,可尝试下载安装php-mysql的rpm包(php-mysql-5.1.6-27.el5.x86_64.rpm),安装它还需先安装php-pdo的rpm包(php-pdo-5.1.6-27.el5.x86_64.rpm),pdo就是专门用于连接php和mysql的。
在以后的web端配置安装时,若phpinfo的基本信息能正常显示,但缺少某个模块功能,可单独下载其对应的rpm包,安装即可。
在/var/www/html下新建一个test.php,用于测试连接远程数据库:
web2
其它类似信息

推荐信息