FreeBSD+MySQL+PHP(PKG_add)完整版

本文网址:http://bbs.bitscn.com/72493 复制

搭建起来FreeBSD+MySQL+PHP的环境!
作者:北纬42度 文章来源:PROWORK.COM.CN
标题: [原创] FreeBSD 6.0 新手上路 (一)

用了3天时间才搭建起来FreeBSD+MySQL+PHP的环境,事实再一次证明了北纬是个笨蛋。此文所有的软件安装都是以编译源码包的方式来安装的,如果你已经比较熟悉FreeBSD或者用PORTS的方式来安装,那么你可以跳过此文,以免浪费你的时间。文中若有错误欢迎各位朋友指正,如要转载请注明出处及作者。

除了 FreeBSD 6.0 的安装盘,我们还需要以下软件包:
Apache-2.2.0.tar.gz
MySQL-4.1.18.tar.gz
PHP-4.4.2.tar.gz
FreeBSD 6.0 的安装这里就不再多说了,我使用的是最小安装(mini)
一、安装Apache
1、解压缩httpd-2.2.0.tar.gz ,生成一个httpd-2.2.0的目录
tar zxvf httpd-2.2.0.tar.gz
2、进入httpd-2.2.0目录,编译前先对其进行配置
./cnfigure –enable-so –prefix=/usr/local/apache2
./configure详细参数可由 ./configure –help获得
如果此步骤没有什么错误的话那么我们可以继续下一步安装,如果出现错误多数是因为没有安装perl造成的。
3、make编译
4、make install 编译并安装。
3-4步没有什么可写的,只是时间漫长。如果用手工安装源码包的话那么
./configure
make
make install
这三步是必不可少的。
5、编译完成后运行一下我们的Apache看看是否能正常运行了
/usr/local/apache2/bin/apacheclt -k start
一般来说只要编译不出错那么Apache的安装就算完成了,httpd.conf我们暂时先不配置它,到后面PHP安装完成之后一起配置。
二、安装MySQL
MySQL的安装要稍微的麻烦一些,跟Apache相比。不过还是少不了./configure、make、make install
1、解压缩mysql-4.1.18.tar.gz ,并产生一个mysql-4.1.18目录
tar zxvf mysql-4.1.18.tar.gz
2、进入mysql-4.1.18.tar.gz目录,进行编译前配置
./configure –prefix=/usr/local/mysql –localstatedir=/usr/local/mysql/var
–prefix=/usr/local/mysql
这个参数用来指定MySQL的安装目录
–localstatedir=/usr/local/mysql/var
这个参数用来指定MySQL的存储目录
3、老规矩,./configure之后就是make、make install。这里就没什么可说的了,漫长的等待。
4、编译完成之后还得做一些设置才能使MySQL数据库能运行起来
· 建立mysql权限数据库
script/mysql_install_db
我是在这个/usr/local/mysql/bin目录下执行的命令
· 设置一个用户组用于执行MySQL
添加一个mysql组:
pw groupadd mysql -g xxx
添加一个mysql用户,属mysql组,并且不允许登陆:
pw useradd mysql -u xxx -g xxx -s /sbin/nologin
修改 /usr/local/mysql 目录属主及其属组为mysql
chown -R mysql:mysql /usr/local/mysql
· 启动MySQL服务,指定执行mysqld的用户为mysql,并且在后台运行
/usr/local/mysql/bin/mysqld_safe –user=mysql &
三、安装PHP
1、还是先解压缩PHP-4.4.2.tar.gz这个文件
tar zxvf PHP-4.4.2.tar.gz
2、进入PHP-4.4.2目录进行编译前的配置
./configure –with-apxs2=/usr/local/apache2/bin/apxs –with-mysql
–prefix=/usr/local/php
需要注意的是 –with-mysql 这个参数一定要有,否则不支持mysql数据库
如果./configure能够顺利完成的话会显示:Thank you for using PHP.
3、make 、make install 这里不讲了,千篇一律。
4、安装完成后将源码目录中的php.ini-recommended复制到/usr/local/lib/,并重命名为php.ini
(我的PHP-4.4.2.tar.gz是在/home下解压缩的,那么php.ini这个文件自然也就在这里了)
cp /home/php-4.4.2/php-ini.recommended /usr/local/lib/php.ini
好了,现在我们回头来配置Apache和PHP,使他们相互支持。
打开httpd.conf文件
vi /usr/local/apache2/conf/httpd.conf
添加以下两句
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
然后查找是否有这一句:
LoadModule php4_module modules/libphp4.so
如果没有,自行添加一下。
下面写一个test.php来测试php以及php连接数据库。
代码:
$hostname = “你的主机名”;
$database = “数据库名”;
$username = “用户名”;
$password = “密码”;
$connection =
mysql_pconnect(“$hostname”,”$username”,”$password”,”$database”);
if($connection = ture)
{
echo “

Connection is Successful
!

“;
}
else
echo “

Connection is Unsuccessful !

“;
?>
如果出现以下问题:
Warning: mysql_pconnect(); Client does not support authentication protocol
requested by server; consider upgrading MySQL client in
/usr/local/apache2/htdocs/mysql.php on line 11
请参阅MYSQL 新版出现” Client does not support authentication
protocol”一文。此文中有较为详细的中/英文说明。
好了,写的差不多了,本人文笔不好,希望大家不要笑话我,如果文中有误,欢迎各位朋友指正 。同时感谢PROWORK.COM.CN众多朋友的支持。 ^_^

Client does not support authentication protocol
=================================================================================
标题: MYSQL 新版出现” Client does not support authentication protocol
MYSQL 帮助:
A.2.3 Client does not support authentication protocol
MySQL 4.1 and up uses an authentication protocol based on a password
hashing algorithm that is incompatible with that used by older clients. If
you upgrade the server to 4.1, attempts to connect to it with an older
client may fail with the following message:
shell> mysql
Client does not support authentication protocol requested
by server; consider upgrading MySQL client
To solve this problem, you should use one of the following approaches:
Upgrade all client programs to use a 4.1.1 or newer client library.
When connecting to the server with a pre-4.1 client program, use an
account that still has a pre-4.1-style password.
Reset the password to pre-4.1 style for each user that needs to use a
pre-4.1 client program. This can be done using the SET PASSWORD statement
and the OLD_PASSWORD() function:
mysql> SET PASSWORD FOR
-> ‘some_user’@’some_host’ = OLD_PASSWORD(‘newpwd’);
Alternatively, use UPDATE and FLUSH PRIVILEGES:
mysql> UPDATE mysql.user SET Password = OLD_PASSWORD(‘newpwd’)
-> WHERE Host = ‘some_host’ AND User = ‘some_user’;
mysql> FLUSH PRIVILEGES;
Substitute the password you want to use for “newpwd” in the preceding
examples. MySQL cannot tell you what the original password was, so you’ll
need to pick a new one.
Tell the server to use the older password hashing algorithm:
Start mysqld with the –old-passwords option.
Assign an old-format password to each account that has had its password
updated to the longer 4.1 format. You can identify these accounts with the
following query:
mysql> SELECT Host, User, Password FROM mysql.user
-> WHERE LENGTH(Password) > 16;
For each account record displayed by the query, use the Host and User
values and assign a password using the OLD_PASSWORD() function and either
SET PASSWORD or UPDATE, as described earlier.
For additional background on password hashing and authentication, see
section 5.5.9 Password Hashing in MySQL 4.1.
例子:
SET PASSWORD FOR 用户名@localhost = OLD_PASSWORD(‘密码’);
——————————————————————————————–
仅适合MySQL4.1及更高版本。(FreeBSD6.0+Apache2.2+MySQL4.1+PHP4)
先看一段代码(用于测试PHP连接MySQL数据库):
代码:
$hostname = “UNIX.workgroup”;
$database = “sqltest”;
$username = “root”;
$password = “123456”;
$connection =
mysql_pconnect(“$hostname”,”$username”,”$password”,”$database”);
if($connection = ture)
{
echo “

Connection is Successful
!

“;
}
else
echo “

Connection is Unsuccessful !

“;
?>
执行的时候报告错误:
Warning: mysql_pconnect(); Client does not support authentication protocol
requested by server; consider upgrading MySQL client in
/usr/local/apache2/htdocs/mysql.php on line 11
解决办法:
1、确定mysql client是4.1或更高版本,如果不是那么把Client升级至4.1或更高版本
2、使用以下两种方法中任意一种(任选其一)
方法A:
mysql> SET PASSWORD FOR
-> ‘some_user’@’some_host’ = OLD_PASSWORD(‘newpwd’);
方法B:
mysql> UPDATE mysql.user SET Password = OLD_PASSWORD(‘newpwd’)
-> WHERE Host = ‘some_host’ AND User = ‘some_user’;
mysql> FLUSH PRIVILEGES;
NND!还是中文看起来舒服。红色部分根据实际情况自行修改。
本文来自: 中国网管论坛(bbs.bitsCN.com) 详细出处参考:http://bbs.bitscn.com/72493

]]>

© 版权声明
THE END
喜欢就支持以下吧
点赞0
分享