在外企做服务器开发, 目前是项目经理, 管理两个server开发的项目。不做嵌入式好久了。
全部博文(197)
分类: LINUX
2007-02-13 11:07:20
【原创】如何安装配置Linux(Redhat9.0) + apache2+MySQL(5)+php5+Zend(3.2.0)
咱们的NAS上面,需要run这个环境 ,所以必须把他架设起来。
仔细查阅了一些资料,关于最新的比较少, 一般都是MySQL4 和 apache1.3的 ,照着作难免有些问题, 不过咱们都是程序员,这点小问题还算不了什么的 。
我装的都是最新版本的, 有些也是需要注意的。 尤其是apache2 的 configure命令加的参数与 1.3的不同 。
windows下的就不说了。 就说Linux下配置。
顺序,mysql 5.0-> apache2 -> php5 ->Zend
我的版本:
httpd-2.0.59
mysql-5.0.27
php-5.2.0
ZendOptimizer-3.2.0-linux-glibc21-i386 对于php5.0必须用Zend 3.2.0 , 否则run不起来。
可以到我的samba下载:
\\boblinux\tmp\Linux_apache2_mysql_php5_Zend
---------------------------
开始了:
mysql :
默认的charset设置成GBK 吧
CODE:
configure --with--charset=gbk --with-extra-charsets="gbk gb2312 big5 utf8" #这些应该就足够了
make
make install
完事之后, 必须运行 :
CODE:
mysql_install_db
最后 运行
CODE:
mysqld_safe --user=root & 即可
修改密码:初始的root密码是空的
mysqladmin -u root -p password 1234
enter password:
把密码修改为1234,由于初始密码为空,所以enter password直接回车就行
测试一下新的密码:
mysql -u root -p
enter password:1234
(其实上面的形式也可以这样:mysql -uroot -p1234亦可)
如果顺利的话就能进入mysql。
你可以执行mysql 命令 来操作你的MySQL Server 。 可以看看 “MySQL相关”l里面的帖子
基本的命令:
举个例子:(不感兴趣的,可以略过这里,直接看apache2)
CODE:
# mysql/client/mysql -uroot -p123456
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 837 to server version: 5.0.27
Cannot read termcap database;
using dumb terminal settings.
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs_molyx_board260 |
| discusz_bbs |
| mysql |
| nas_blog |
| test |
| viart_nas |
| wiki_database |
| wiki_new_database |
| wikidb_nas-gbk |
| wikidb_nas-zh-cn |
| wikidb_nas2 |
| wikidb_pc_windows |
+--------------------+
13 rows in set (0.36 sec)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select * from user;
+-----------+-------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+-----------+-------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| bobnas | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
| bobnas | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
| localhost | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 |
| % | admin | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 |
+-----------+-------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
5 rows in set (0.04 sec)
--------------------
apache :
注意apache的安装是DSO方式的, 就是动态链接的意思。
CODE:
cd httpd-2.0.59/
./configure --enable-so --enable-mods-shared=most
make
make install
默认的安装路径是 /usr/local/apache2
配置文件在 /usr/local/apache2/conf/httpd.conf
主要就是修改这个:
CODE:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/usr/local/apache2/htdocs"
#DocumentRoot "/work/www-tt/phpcms"
#改成你自己的路径。
CODE:
//我发现通过源码包安装 ,并没有这些行, 你要自己加上:否则,httpd就说配置文件出错
#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
LoadModule php5_module modules/libphp5.so #这句最关键了, 要加在php5的动态链接库,才能支持php5
注意这个写法, 与php4不同。
#
#bob add
#
LoadModule access_module modules/mod_access.so
LoadModule actions_module modules/mod_actions.so
LoadModule alias_module modules/mod_alias.so
LoadModule asis_module modules/mod_asis.so
LoadModule auth_module modules/mod_auth.so
#LoadModule auth_anon_module modules/mod_auth_anon.so
#LoadModule auth_dbm_module modules/mod_auth_dbm.so
#LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cern_meta_module modules/mod_cern_meta.so
LoadModule cgi_module modules/mod_cgi.so
#LoadModule dav_module modules/mod_dav.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
LoadModule dir_module modules/mod_dir.so
LoadModule env_module modules/mod_env.so
#LoadModule expires_module modules/mod_expires.so
#LoadModule file_cache_module modules/mod_file_cache.so
#LoadModule headers_module modules/mod_headers.so
LoadModule imap_module modules/mod_imap.so
LoadModule include_module modules/mod_include.so
#LoadModule info_module modules/mod_info.so
#LoadModule isapi_module modules/mod_isapi.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule mime_module modules/mod_mime.so
#LoadModule mime_magic_module modules/mod_mime_magic.so
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule negotiation_module modules/mod_negotiation.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule setenvif_module modules/mod_setenvif.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule status_module modules/mod_status.so
#LoadModule unique_id_module modules/mod_unique_id.so
LoadModule userdir_module modules/mod_userdir.so
#LoadModule usertrack_module modules/mod_usertrack.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule ssl_module modules/mod_ssl.so
--
CODE:
还有查找这一行 ,
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents. The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
DirectoryIndex index.php index.html index.html.var #把php放前面,优先html解析
查找:
CODE:
#here is key for php parser ,bob
AddType application/x-httpd-php .php #否则无法解析php文件
AddType application/x-httpd-php-source .phps
基本上就这些了
---------------------------
php5
编译:
CODE:
cd php-5.2.0
./configure --with-mysql=usr/local --with-apxs2=/usr/local/apache2/bin/apxs
make
make install
配置方面,就比较简单了 :
主要是配置php.ini ,如果你发现/usr/local/lib/没有php.ini ,你就可以从源码包里面copy一个php.ini-dist 到/usr/local/lib/ 改名成php.ini 即可
注意:
默认是这样的: extension_dir = "./" 如果你要加载一些module ,而这些module不在当前目录,一定要修改这里
-----------------------
Zend
更简单了, 下载 ZendOptimizer-3.2.0-linux-glibc21-i386
执行 ./install.sh 会弹出窗口,让你输入 php的安装路径什么的,都是默认就好了。
安装成功后 , 默认会建立 /usr/local/Zend 目录 ,而且会把php.ini 从/usr/local/lib/php.ini 移动 到 /usr/local/Zend/etc/下面 。 /usr/local/lib/php.ini 链接到 /usr/local/Zend/etc/php.ini
php.ini 会增加下面几行:
CODE:
[Zend]
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.2.0
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.2.0
zend_optimizer.version=3.2.0
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so
---------------------------
那怎么知道 php就支持 Zend 了呢?
CODE:
重启 apache : /usr/local/apache2/bin/apachectl restart
#shell > php -v
PHP 5.2.0 (cli) (built: Dec 18 2006 14:47:43)
Copyright (c) 1997-2006 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2006 Zend Technologies
with Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by Zend Technologies
with Zend Optimizer v3.2.0, Copyright (c) 1998-2006, by Zend Technologies
看到这两行:
CODE:
with Zend Extension Manager v1.0.11, Copyright (c) 2003-2006, by Zend Technologies
with Zend Optimizer v3.2.0, Copyright (c) 1998-2006, by Zend Technologies
说明已经支援 Zend Optimizer 了
=====================================
对于Zend的一种替换选择, 由于Zend是商业开发的, 所以无法得到源码,如果想要在NAS上获得php代码的提速, 可以使用 eaccelerator来作为一种替代的做法, 具体的可以参考下面的 链接,
http://bobnas:8080/Discuz_GBK-bbs/viewthread.php?tid=19&extra=page%3D1
++++++++++++++++++++++++++++++++
此时你的apache+MySQL+php5+Zend 环境已经建立起来了。