Apache/MySQL/PHP/phpMyAdmin on FreeBSD

1. Introduction:

This article describes how to setup Apache, MySQL, PHP and phpMyAdmin on a server running FreeBSD. The article was written for the software versions below but is likely to work on newer versions without too much difficulty.

 2. Software:

Operating System:        FreeBSD 7.0 for i386      Download

Apache:                           2.2.8                                Installed from Ports Collection

MySQL Server:            5.0.51a                             Installed from Ports Collection

PHP & Extensions:        5.2.5                                Installed from Ports Collection

phpMyAdmin:              2.11.5                               Installed from Ports Collection

3. Before you begin:

This article assumes you have a working install of FreeBSD 6.2 for i386 logged in as root (or another user in the wheel group and you have used “su”) with the ports collection installed. You can use sysinstall, cvsup or portsnap to install the ports distribution if you have not already done so. See point 2 below.

Update your ports collection (portsnap fetch, portsnap extract.) (See the FreeBSD Handbook Section 4.5.1)

4. Installing MySQL:

(1)  Go to the mysql50-server port directory by typing the command:

                 cd /usr/ports/databases/mysql50-server

 (2) Build the port by typing: (This takes AGES – good time for some food.)

make BUILD_OPTIMIZED=yes BUILD_STATIC=yes

(3) Install by typing:

             make install clean

(4)Open /etc/rc.conf with your favourite text editor and add the line shown below. This will ensure mysql is enabled and starts on boot.

                mysql_enable=”YES”

 (5)Start mysql manually to avoid having to reboot now by typing:

         /usr/local/etc/rc.d/mysql-server start

 (6)Set a password for the MySQL root user by executing the command, subtituting your own password in place of new-password:

    /usr/local/bin/mysqladmin -uroot password ‘new-password’

  And you’re done! MySQL is installed.

5.Installing Apache

(1)Go to the apache22 port directory by typing the command:

cd /usr/ports/www/apache22

(2)Build and install the port by typing: (This takes a while, coffee time!)

make install clean

Note: You may want to disable the two DAV options if you don’t need them when prompted

(3)Open /etc/rc.conf with your favourite text editor and add the line shown below. This will ensure apache is enabled and starts on boot.

apache22_enable=”YES”

6.Installing PHP

(1)Go to the php5 port directory by typing the command:

cd /usr/ports/lang/php5

(2)Build and install the port by typing: (Just accept the default options, this takes a while, more coffee.)

make install clean

Make sure the APACHE (Build Apache module) option is ticked when configuring the build, leaving all other options as default, before selecting OK.

(3)Go to the php5-extentions meta port directory by typing the command:

cd /usr/ports/lang/php5-extentions

(4)Build and install the port by typing: (Just accept the defaults here, phpMyAdmin will install any other extensions required itself)

make install clean

(5)Install the php.ini file:

cp /usr/local/etc/php.ini-dist /usr/local/etc/php.ini

版本不同,只面的文件可能有所改变

php.ini-production对应于php.ini-recommended

php.ini-development对应于php.ini-dist

php.ini-development 开发用的,php.ini-produciton 生产机用的,如果做站的话,我觉得应该将php.ini-produciton改为php.ini,用php.ini-produciton可能会出现无法支持PHP,修改php.ini中的短标签开关short_open_tag=Off在作怪,改成On就行了

(6)Edit your Apache configuration file (/usr/local/etc/apache22/httpd.conf) and add the following lines to the end of the file:

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

 Note: You can add additional extenions other than .php (eg .phtml) seperated by spaces.

Note: The second line is optional, it will show colour highlighted PHP source for .phps files.

(7)You should also search for the line that reads:

DirectoryIndex index.html

and change it to read:

DirectoryIndex index.php index.html

Note: You may also add index.phtml or any other default page if you added additional extentions in the previous step.

(8)Enable language settings by searching for the line:

#Include etc/apache22/extra/httpd-languages.conf

and removing the # comment mark so it reads:

Include etc/apache22/extra/httpd-languages.conf

(9)Edit the language settings file (/usr/local/etc/apache22/extra/httpd-languages.conf) and add the following line at the end of the file:

AddDefaultCharset On

(10)Start Apache using the startup script:

/usr/local/etc/rc.d/apache22 start

And you’re done! Apache with PHP is installed.

安装Zend Optimizer

cd /usr/ports/devel/ZendOptimizer/

make install clean

===> ZendOptimizer-3.3.0.a cannot install: doesn’t work with PHP version : 5 (Doesn’t support PHP 5).

*** Error code 1

Stop in /usr/ports/devel/ZendOptimizer.

注:如果你用的是FreeBsd8.0版本的可能会出现上面的情况,这里可以使用使用pkg_add命令来安装Zend Optimizer.

#pkg_add -r ZendOptimizer

#rehash

执行结果将类似如下:

Fetching ftp://ftp.freebsd.org/pub/FreeBSD/ports/i386/packages-8.0-release/Latest/ZendOptimizer.tbz… Done.

pkg_add: warning: package ‘ZendOptimizer-3.3.0.a’ requires ‘libxml2-2.7.5’, but ‘libxml2-2.7.7’ is installed

pkg_add: warning: package ‘ZendOptimizer-3.3.0.a’ requires ‘php5-5.2.11’, but ‘php5-5.3.2’ is installed

 

********************************************************************************

 

You have installed the ZendOptimizer package.

 

Edit /usr/local/etc/php.ini and add:

 

[Zend]

zend_optimizer.optimization_level=15

zend_extension_manager.optimizer=”/usr/local/lib/php/20060613/Optimizer”

zend_extension_manager.optimizer_ts=”/usr/local/lib/php/20060613/Optimizer_TS”

zend_extension=”/usr/local/lib/php/20060613/ZendExtensionManager.so”

zend_extension_ts=”/usr/local/lib/php/20060613/ZendExtensionManager_TS.so”

 

NOTE: PHP should be compiled in non-debug mode (default).

 

********************************************************************************

虽然居然成功了,但也可能用phpinfo时候还是不行的![可惜最后还是不行,得到的教训是,不要用太新的版本,这样资料和环境的支持会很不完善。]

 

7.Installing phpMyAdmin

(1)Got to the phpmyadmin port directory by typing the command:

cd /usr/ports/databases/phpmyadmin

(2)Build and install the port by typing: (Just accept the default options)

make install clean

(3)phpMyAdmin is now installed in /usr/local/www/phpMyAdmin. To use it we need to create Alias and Directory entries in /usr/local/etc/apache22/httpd.conf. To do this, add the following lines to the <IfModule alias_module> section (just search for where all the other Alias commands are.)

Alias /phpmyadmin /usr/local/www/phpMyAdmin

(4)As /usr/local/www/phpMyadmin is outside of the Apache <DocumentRoot> you will have to make a <Directory> entry for it too. Add the following lines to the end of the <Directory> section: (just search for </Directory>)

<Directory “/usr/local/www/phpMyAdmin”>

Order allow,deny

Allow from all

</Directory>

 Note:You may prefer to put the Alias entry inside a <VirtualHost> entry if you are hosting multiple sites using name based virtual hosting and do not wish to enable phpMyAdmin on all the sites.

(5)Create a config directory for phpMyAdmin and make it globally read/write/executable by typing the commands:

cd /usr/local/www/phpMyAdmin

mkdir config

chmod 777 config

(6)Restart Apache so that the Alias and Directory entries take effect by typing:

/usr/local/etc/rc.d/apache22 restart

(7)Configure phpMyAdmin by going to http://hostname/phpmyadmin/scripts/setup.php in your browser and set at least the following:

  • Add Server
    • Change the “Authentication type” dropdown to http to have phpMyAdmin prompt you for a username and password.
    • Delete root from the “User for config” auth textbox so it is blank.
    • You can leave all other settings as they are (even if they are blank.)
    • Click the “Add” button to add the new server

Save the configuration using the Save button in the Configuration section.

(8)For the changes to take effect you must copy the generated config file from the phpMyAdmin/config directory to the phpMyAdmin directory by typing the following command: (Note the space dot at the end of the command)

cp config/config.inc.php .

(9)You can now delete the config directory you created earlier and reset the permissions on the config.inc.php file to read only typing the commands:

rm -rf config

chmod 444 config.inc.php

(10)That’s it! You can place your web site in /usr/local/www/data/ and access phpMyAdmin at http://hostname/phpmyadmin/ in your web browser and logging in using username root and the MySQL password you set earlier.

以上安装完,可能有所出入,特别是Apache22可能无法启动,以下两点是一些总结:

1:注意:apache22有个bug,不能启动FreeBSD自带的一个基于http端口过滤的模块。这个模块的作用很不错——检查HTTP请求是否完整,符合规则accpt一个Http进程,否则就扔掉。你会遇到如下提示

[Sat Jan 23 22:47:29 2010] [warn] (2)No such file or directory: Failed to enable the ‘httpready’ Accept Filter    解决方法是:

#kldload accf_http  或者将/boot/defaults/loader.conf==> accf_httpd_load=”YES”

2.apache22无法启动时,进入/var/logo查看httpd_error.log, 如果出现以下提示:

[alert] (EAI 8)hostname nor servname provided, or not known: mod_unique_id: unable to find IPv4 address of “shao  Configuration Failed

解决方法:进入/usr/local/etc/apache22    ee ./httpd.conf

将LoadModule unique_id_module libexec/apache2/mod_unique_id.so注释掉

然后启动/usr/local/etc/rc.d/apache22  start即可.

一个IP多个域名添加方法

在httpd.conf中去掉httpd-vhosts.conf那一栏注释,然后进入/usr/local/etc/apache22/extra/修改httpd-vhosts.conf网站域名对应的目录,还要加

<Directory “/usr/home/www/jpeps.com”>

Options FollowSymLinks

AllowOverride None

Order allow,deny

Allow from all

</Directory>

<IfModule dir_module>

DirectoryIndex index.html index.htm index.php

</IfModule>

添加php.ini 被禁用的函数(disable_functions)

passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen

评论

此博客中的热门博文

FreeBSD安装Pure-FTPd及user manager for PureFTPd

debian lighttpd php ssl

解决nginx出现File not found的问题