Heim  >  Artikel  >  Datenbank  >  在 FreeBSD 10.0 上安装和配置 Nginx+PHP+APC+MySQL

在 FreeBSD 10.0 上安装和配置 Nginx+PHP+APC+MySQL

WBOY
WBOYOriginal
2016-06-07 16:41:311460Durchsuche

上月得知一位同事要退休,留下一些 BSD 机器需要接手(是的,在国外玩技术可以玩到退休~),接下来两个月讨论 FreeBSD/OpenBSD 的机会可能多一些。FreeBSD 10.0 发布的亮点不少,clang 替代了 gcc 成为默认编译器、大幅增强了对虚拟化的支持、下一代软件包

上月得知一位同事要退休,留下一些 BSD 机器需要接手(是的,在国外玩技术可以玩到退休~),接下来两个月讨论 FreeBSD/OpenBSD 的机会可能多一些。FreeBSD 10.0 发布的亮点不少,clang 替代了 gcc 成为默认编译器、大幅增强了对虚拟化的支持、下一代软件包管理工具 pkgng 替代了 pkg_add/pkg_delete 成为默认包管理工具、Linux 一直在虚拟化方面遥遥领先 BSD 阵营,这次的发行版本终于包括了 BSD 自己的虚拟化技术 bhyve,…

在 FreeBSD 下安装软件的传统方法是用 ports 源码安装,不过使用 ports 源码编译安装太耗时(尤其是各种库依赖多、大的时候),个人还是喜欢 pkg 这种软件包管理工具直接安装编译好的二进制软件包,不用自己编译,省时省力。

和 Linux 一样,FreeBSD 也能一行命令解决所有安装和软件包依赖问题(下面的输出要比 apt-get/yum 来的清新舒服吧~):

# pkg install nginx php55 php55-extensions pecl-APC mysql56-server
Updating repository catalogue
The following 23 packages will be installed:
	Installing nginx: 1.4.7,1
	Installing php5-session: 5.4.26
	Installing php5-xmlwriter: 5.4.26
	Installing php5-dom: 5.4.26
	Installing php5-xml: 5.4.26
	Installing php5-simplexml: 5.4.26
	Installing php5-ctype: 5.4.26
	Installing php5-posix: 5.4.26
	Installing php5-hash: 5.4.26
	Installing php5-filter: 5.4.26
	Installing php5-tokenizer: 5.4.26
	Installing php5-json: 5.4.26
	Installing php5-sqlite3: 5.4.26
	Installing php5-pdo: 5.4.26
	Installing php5-iconv: 5.4.26
	Installing php5-phar: 5.4.26
	Installing pecl-APC: 3.1.14_1
	Installing php5-xmlreader: 5.4.26
	Installing php5-pdo_sqlite: 5.4.26
	Installing php5-extensions: 1.7
	Installing mysql56-client: 5.6.16_1
	Installing mysql56-server: 5.6.16
The installation will require 149 MB more space
14 MB to be downloaded
Proceed with installing packages [y/N]: y

安装完后把服务加到系统启动文件里:

# vi /etc/rc.conf
...
nginx_enable="YES"
php_fpm_enable="YES"
mysql_enable="YES"

配置 MySQL:

# vi /usr/local/etc/my.cnf
[mysqld]
socket = /tmp/mysql.sock
skip-networking
skip-name-resolve
# service mysql-server start
# /usr/local/bin/mysqladmin -u root password 'password'

配置 PHP 和 PHP-FPM,这里不需要配啥,默认的配置就行:

# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
# vi /usr/local/etc/php.ini
# vi /usr/local/etc/php-fpm.conf
# service php-fpm start

配置 APC:

# echo 'apc.enabled="1"' >> /usr/local/etc/php.ini
# echo 'apc.shm_size="32M"' >> /usr/local/etc/php.ini
# service php-fpm restart

配置 Nginx:

# vi /usr/local/etc/nginx/nginx.conf
user  www;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /usr/local/www/nginx;
            index  index.html index.htm;
        }
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /usr/local/www/nginx-dist;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root   /usr/local/www/nginx;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }
}
# service nginx start

写个 phpinfo() 页面测试一下 Nginx/PHP/PHP-FPM/APC 组合是否能正常工作。如果一切正常的话访问 http://localhost/info.php 能看到 PHP 环境详细信息:

# vi /usr/local/www/nginx/info.php
<?php phpinfo(); ?>

对 NetBSD 感兴趣的同学可以参考:NetBSD 上安装和配置 Nginx+PHP+FastCGI+MySQL

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:HDFS文件命令Nächster Artikel:redis启动流程