之前自己在 Gentoo 系统里安装过 apache php mysql ,但基本都是按照教程一步步走的。
后来,想按照自己的感觉安装下,顺便学习学习 emerge , 或者主要还是学习 emerge 了。于是出现了此篇博文。
一 安装 apahce
1.先看看 要安装 apache 都有那些 USE 变量要配置
# emerge -pv apache These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] dev-libs/apr-1.4.5 USE="urandom uuid -doc -older-kernels-compatibility -static-libs" 738 kB [ebuild N ] dev-libs/apr-util-1.3.12 USE="berkdb gdbm ldap sqlite -doc -freetds -mysql -odbc -postgres -static-libs" 594 kB [ebuild N ] app-admin/apache-tools-2.2.21 USE="ssl" 5,201 kB [ebuild N ] www-servers/apache-2.2.21-r1 USE="ldap ssl -debug -doc (-selinux) -static -suexec -threads" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -asis -auth_digest -authn_dbd -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -proxy_scgi -reqtimeout -substitute -version" APACHE2_MPMS="-event -itk -peruser -prefork -worker" 63 kB Total: 4 packages (4 new), Size of downloads: 6,594 kB
从结果输出来看:有4个包要安装,且都是[ebuild N ] (new install)
其中,第2个软件包 apt-util 的USE变量 postgres (mysql同理)是没有激活的,需要激活(因为后面还要用到,可以写进 /etc/make.conf 的 USE ), 此文一律没有写进 /etc/make.conf 的 USE另外,apache 的 USE 激活的有 ldap ssl , 其他的都是未激活的。
APACHE2_MODULES 就比较多了,我也不知道都需要那些, 等到以后需要时再重新编译吧 。
2. 设置 USE 变量,准备安装
运行:USE="postgres" emerge -pv 看看(emerge 命令前的 USE 变量只在此命令中起作用,可以称作“临时”变量吧):
# USE="postgres" emerge -pv apache These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] dev-libs/apr-1.4.5 USE="urandom uuid -doc -older-kernels-compatibility -static-libs" 738 kB [ebuild N ] app-admin/eselect-postgresql-1.0.10 4 kB [ebuild N ] dev-db/postgresql-base-9.1.3 USE="ldap nls pam readline ssl zlib -doc -kerberos -pg_legacytimestamp -threads" LINGUAS="-af -cs -de -en -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_CN -zh_TW" 15,222 kB [ebuild N ] dev-libs/apr-util-1.3.12 USE="berkdb gdbm ldap postgres sqlite -doc -freetds -mysql -odbc -static-libs" 594 kB [ebuild N ] app-admin/apache-tools-2.2.21 USE="ssl" 5,201 kB [ebuild N ] www-servers/apache-2.2.21-r1 USE="ldap ssl -debug -doc (-selinux) -static -suexec -threads" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -asis -auth_digest -authn_dbd -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -proxy_scgi -reqtimeout -substitute -version" APACHE2_MPMS="-event -itk -peruser -prefork -worker" 63 kB Total: 6 packages (6 new), Size of downloads: 21,819 kB结果显示:有6个软件包要安装,且都是[ebuild N ] (new install)。
其中,新增加的两个软件包都是 postgresql 数据库的,而且 LINGUAS 貌似也需要设置(没有任何语言是激活的)
运行:USE="postgres" LINGUAS="en zh_CN" emerge -pv apache 再看看结果
# USE="postgres" LINGUAS="en zh_CN" emerge -pv apache These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] dev-libs/apr-1.4.5 USE="urandom uuid -doc -older-kernels-compatibility -static-libs" 738 kB [ebuild N ] app-admin/eselect-postgresql-1.0.10 4 kB [ebuild N ] dev-db/postgresql-base-9.1.3 USE="ldap nls pam readline ssl zlib -doc -kerberos -pg_legacytimestamp -threads" LINGUAS="en zh_CN -af -cs -de -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_TW" 15,222 kB [ebuild N ] dev-libs/apr-util-1.3.12 USE="berkdb gdbm ldap postgres sqlite -doc -freetds -mysql -odbc -static-libs" 594 kB [ebuild N ] app-admin/apache-tools-2.2.21 USE="ssl" 5,201 kB [ebuild N ] www-servers/apache-2.2.21-r1 USE="ldap ssl -debug -doc (-selinux) -static -suexec -threads" APACHE2_MODULES="actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias -asis -auth_digest -authn_dbd -cern_meta -charset_lite -dbd -dumpio -ident -imagemap -log_forensic -proxy -proxy_ajp -proxy_balancer -proxy_connect -proxy_ftp -proxy_http -proxy_scgi -reqtimeout -substitute -version" APACHE2_MPMS="-event -itk -peruser -prefork -worker" 63 kB Total: 6 packages (6 new), Size of downloads: 21,819 kB从上面的结果来看,由于改变了USE 而 新增加了两个和postgresql有关的软件包 。
3 开始安装
运行:USE="postgres" LINGUAS="en zh_CN" emerge apache 开始安装(直接去掉上一条命令的参数 -pv )
# USE="postgres" LINGUAS="en zh_CN" emerge apache等待(大约10分钟)..... 提示成功!
4. 检验apache 是否安装成功
启动 apache 服务
# /etc/init.d/apache2 start * Caching service dependencies ... [ ok ] * Starting apache2 ... apache2: Could not reliably determine the server's fully qualified domain name, using 125.76.232.12 for ServerName
有个提示:Could not reliably detemine the server's fully ......, 解决方法如下:
编辑: /etc/apache2/httpd.conf, 添加:
ServerName localhost:80 # 当然,我的机器名就不是 localhost 了
显示: It works ! 表示成功,否则请回滚 !
5(可选,仅供参考)更改 apache 默认主目录 /var/www/localhost/htdocs 为其他目录
编辑:/etc/apache2/vhosts.d/default_vhost.include
DocumentRoot "/var/www/" # This should be changed to whatever you set DocumentRoot to. <Directory "/var/www/">
二 安装 Postgres
1.启动 postgresql (好像安装apache时安装了postgres), 但 /etc/init.d/ 目录下找不到 postgresql 相关内容 !
网上找了找,在 http://www.gentoo.org/doc/en/postgres-howto.xml 发现原来没安装 postgres-server (安装apache的时候安装的postgresql-base是干嘛的?)
运行 emerge -pv postgresql-server 看看 USE 要配置不
# emerge -pv postgresql-server These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] dev-db/postgresql-server-9.1.3 USE="nls pam xml -doc -perl -pg_legacytimestamp -python (-selinux) -tcl -uuid" LINGUAS="-af -cs -de -en -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_CN -zh_TW" 3 kB Total: 1 package (1 new), Size of downloads: 3 kB结果显示:如上!
我无语了,才仅仅 3 kB .... 设置 USE (我要用到 python ) 和 LIGNUAS 看看吧 。
# USE="python" LINGUAS="en zh_CN" emerge -pv postgresql-server These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] dev-db/postgresql-server-9.1.3 USE="nls pam python xml -doc -perl -pg_legacytimestamp (-selinux) -tcl -uuid" LINGUAS="en zh_CN -af -cs -de -es -fa -fr -hr -hu -it -ko -nb -pl -pt_BR -ro -ru -sk -sl -sv -tr -zh_TW" 3 kB Total: 1 package (1 new), Size of downloads: 3 kB
运行: USE="python" LINGUAS="en zh_CN" emerge postgresql-server 安装postgresql-server (上条命令去掉参数 -pv )
USE="python" LINGUAS="en zh_CN" emerge postgresql-server等待(大约3分钟) ... ... OK
完成时有如下提示:
* If you have users and/or services that you would like to utilize the * socket, you must add them to the 'postgres' system group: * usermod -a -G postgres <user> * * Before initializing the database, you may want to edit PG_INITDB_OPTS * so that it contains your preferred locale in: * /etc/conf.d/postgresql-9.1 * * Then, execute the following command to setup the initial database * environment: * emerge --config =dev-db/postgresql-server-9.1.3 >>> Auto-cleaning packages...
按照提示编辑 /etc/conf.d/postgresql-9.1 (可以直接使用默认,不做任何更改,遇到问题了再改)
# 配置文件位置 PGDATA="/etc/postgresql-9.0/" # 数据存放目录/to be created DATA_DIR="/var/lib/postgresql/9.0/data" # 可选 选项 PG_INITDB_OPTS="--locale=en_US.UTF-8"按照提示,运行:emerge --config =dev-db/postgresql-server-9.1.3
# emerge --config =dev-db/postgresql-server-9.1.3 ........ * The autovacuum function, which was in contrib, has been moved to the main * PostgreSQL functions starting with 8.1, and starting with 8.4 is now enabled * by default. You can disable it in the cluster's: * /etc/postgresql-9.1/postgresql.conf * * The PostgreSQL server, by default, will log events to: * /var/lib/postgresql/9.1/data/postmaster.log * * You should use the '/etc/init.d/postgresql-9.1' script to run PostgreSQL * instead of 'pg_ctl'.然后,继续安装上条命令完成时的提示:
启动数据库:/etc/init.d/postgresql-9.1 start
# /etc/init.d/postgresql-9.1 start * Caching service dependencies ... [ ok ] * /var/run/postgresql: creating directory * /var/run/postgresql: correcting owner * Starting PostgreSQL ... [ ok ]
2. 测试 postgresql
# psql -U postgres psql (9.1.3) Type "help" for help. postgres=# \l List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+----------+----------+-------------+-------------+----------------------- postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres + | | | | | postgres=CTc/postgres (3 rows) postgres=#
OK, 搞定 !
三 安装 php
1.按照惯例,先看看都有啥约束条件:
# emerge -pv php These are the packages that would be merged, in order: Calculating dependencies - !!! Problem resolving dependencies for dev-lang/php ... done! !!! The ebuild selected to satisfy "php" has unmet requirements. - dev-lang/php-5.3.10::gentoo USE="berkdb bzip2 cli crypt ctype exif fileinfo filter gdbm hash iconv ipv6 json ldap (multilib) nls phar posix readline session simplexml spell sqlite ssl tokenizer truetype unicode xml zlib -apache2 -bcmath -calendar -cdb -cgi -cjk -curl -curlwrappers -debug -doc -embed -enchant -firebird -flatfile -fpm (-frontbase) -ftp -gd -gmp -imap -inifile -intl -iodbc -kerberos -kolab -ldap-sasl -libedit -mhash -mssql -mysql -mysqli -mysqlnd -oci8-instant-client -odbc -pcntl -pdo -pic -postgres -qdbm -recode -sharedmem -snmp -soap -sockets -sqlite3 -suhosin (-sybase-ct) -sysvipc -threads -tidy -wddx -xmlreader -xmlrpc -xmlwriter -xpm -xsl -zip" The following REQUIRED_USE flag constraints are unsatisfied: truetype? ( gd ) exif? ( gd ) The above constraints are a subset of the following complete expression: truetype? ( gd ) cjk? ( gd ) exif? ( gd ) xpm? ( gd ) gd? ( zlib ) simplexml? ( xml ) soap? ( xml ) wddx? ( xml ) xmlrpc? ( any-of ( xml iconv ) ) xmlreader? ( xml ) xsl? ( xml ) ldap-sasl? ( ldap ) kolab? ( imap ) mhash? ( hash ) phar? ( hash ) mysqlnd? ( any-of ( mysql mysqli pdo ) ) qdbm? ( !gdbm ) readline? ( !libedit ) recode? ( !imap !mysql !mysqli ) sharedmem? ( !threads ) !cli? ( !cgi? ( !fpm? ( !apache2? ( !embed? ( cli ) ) ) ) )报错了,结果显示:一个叫 gd 的东东出问题了。
这个么,设置USE变量即可,如下所示(另外设置了其他USE):
# USE="apache2 cgi curl gd pdo postgres sockets" emerge -pv php These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild NS ] dev-db/sqlite-2.8.16-r5 [3.7.7.1] USE="nls -doc -tcl" 959 kB [ebuild N ] dev-libs/oniguruma-5.9.2 528 kB [ebuild N ] dev-libs/libmcrypt-2.5.8-r2 1,304 kB [ebuild N ] app-admin/eselect-php-0.6.2 2 kB [ebuild N ] x11-libs/libXpm-3.5.9 USE="-static-libs" 375 kB [ebuild N ] x11-libs/libXaw-1.0.9 USE="-doc -static-libs" 636 kB [ebuild N ] media-libs/t1lib-5.1.2 USE="X -doc -static-libs" 1,829 kB [ebuild N ] app-text/aspell-0.60.6.1 USE="nls" LINGUAS="-af -be -bg -br -ca -cs -cy -da -de -el -en -eo -es -et -fi -fo -fr -ga -gl -he -hr -is -it -la -lt -nl -no -pl -pt -pt_BR -ro -ru -sk -sl -sr -sv -uk -vi" 1,835 kB [ebuild N ] app-dicts/aspell-en-6.0.0 179 kB [ebuild N ] dev-lang/php-5.3.10 USE="apache2 berkdb bzip2 cgi cli crypt ctype curl exif fileinfo filter gd gdbm hash iconv ipv6 json ldap nls pdo phar posix postgres readline session simplexml sockets spell sqlite ssl tokenizer truetype unicode xml zlib -bcmath -calendar -cdb -cjk -curlwrappers -debug -doc -embed -enchant -firebird -flatfile -fpm (-frontbase) -ftp -gmp -imap -inifile -intl -iodbc -kerberos -kolab -ldap-sasl -libedit -mhash -mssql -mysql -mysqli -mysqlnd -oci8-instant-client -odbc -pcntl -pic -qdbm -recode -sharedmem -snmp -soap -sqlite3 -suhosin (-sybase-ct) -sysvipc -threads -tidy -wddx -xmlreader -xmlrpc -xmlwriter -xpm -xsl -zip" 11,441 kB Total: 10 packages (9 new, 1 in new slot), Size of downloads: 19,083 kB结果显示:有10个软件包要安装。其中,第1个[ ebuild NS ] dev-db/sqlite-2.8.16-r5 [3.7.7.1] 的意思是:系统中已经安装 sqlite- 3.7.7.1 ,现在又要安装 sqlite-2.8.16-r5 。两个软件包将在系统中共存,美其名曰:SLOT
2.运行:USE="apache2 cgi curl gd pdo postgres sockets" emerge php 安装 PHP
USE="apache2 cgi curl gd pdo postgres sockets" emerge php
配置 apache 支持php, 编辑/etc/conf.d/apache2 向 APACHE2_OPTS 追加 -D PHP5
APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D LANGUAGE -D PHP5"
更改默认执行 index.index 为默认执行 index.php, 编辑 /etc/apache2/modules.d/00_default_settings.conf
<IfModule dir_module> DirectoryIndex index.php index.html index.html.var </IfModule>
在 www (有可能不是此目录)目录下创建 index.php,添加以下内容:
<?php phpinfo(); ?>
# /etc/init.d/apache2 restart #或 rc-service apache2 restart
浏览器键入地址,看看行不。 不行请回滚!
5. 安装 pear(可选,我要用到)
按照惯例,先看看情况:
# emerge -pv pear These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] dev-php/PEAR-PEAR-1.9.3 289 kB [ebuild N ] dev-php/PEAR-Structures_Graph-1.0.4 30 kB [ebuild N ] dev-php/PEAR-Console_Getopt-1.3.1 5 kB [ebuild N ] dev-php/PEAR-Archive_Tar-1.3.7 18 kB [ebuild N ] dev-php/PEAR-XML_Util-1.2.1-r2 18 kB [ebuild N ] dev-php/pear-1.9.3 0 kB Total: 6 packages (6 new), Size of downloads: 358 kB结果没啥可解释的,去掉 -pv 安装吧:
6. PHP 配置
运行:php --ini 看看 php 配置文件位置:
# php --ini Configuration File (php.ini) Path: /etc/php/cli-php5.3 Loaded Configuration File: /etc/php/cli-php5.3/php.ini Scan for additional .ini files in: /etc/php/cli-php5.3/ext-active Additional .ini files parsed: (none)
四 安装 ZendFramework
1.惯例,先看看:
# emerge -pv ZendFramework These are the packages that would be merged, in order: Calculating dependencies... done! [ebuild N ] dev-php/ZendFramework-1.11.6 USE="cli -doc -examples -minimal" 19,660 kB Total: 1 package (1 new), Size of downloads: 19,660 kB
没啥要设置的,运行 emerge ZendFramework 安装即可
2. 创建 Zend 工程 zf
# cd /var/www # 进入网站主目录(你的可能不是此目录) nehc www # zf create project zf Creating project at /var/www/zf Note: This command created a web project, for more information setting up your VHOST, please see docs/README Testing Note: PHPUnit was not found in your include_path, therefore no testing actions will be created.结果显示:两条提示。
五 配置v-host
1.Gentoo 系统 emerge 安装的 apache vhost 配置文件:/etc/apache2/vhosts.d/00_default_vhost.conf
编辑:/etc/apache2/vhosts.d/00_default_vhost.conf
<VirtualHost *:80> # 这个是系统默认的 ServerName localhost Include /etc/apache2/vhosts.d/default_vhost.include <IfModule mpm_peruser_module> ServerEnvironment apache apache </IfModule> </VirtualHost> <VirtualHost *:80> # 这个是为工程 zf 创建的, 仅供参考 ServerName cc.zf.com ServerAdmin [email protected] DocumentRoot "/var/www/zf/public" <Directory "/var/www/zf/public"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
2. 启用 vhost
编辑: /etc/hosts ,写入如下内容
10.65.10.80 cc.zf.com
重启 apache ,浏览器输入 cc.zf.com 看看可以不
附图:
六 Apache 配置
参考: https://calomel.org/apache_server.html