发布于 2015-12-12 09:25:46 | 387 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的PHP设计模式,程序狗速度看过来!

PHP开源脚本语言

PHP(外文名: Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。语法吸收了C语言、Java和Perl的特点,入门门槛较低,易于学习,使用广泛,主要适用于Web开发领域。PHP的文件后缀名为php。


PHP7

PHP7都出了,自然我是要安装的,上次写的那个编译开发环境并没有针对性的说PHP,就这次说清楚吧。

Download

$ wget http://cn2.php.net/get/php-7.0.0.tar.gz/from/this/mirror
$ mv mirror php7.tar.gz
$ tar -zxvf php7.tar.gz
$ cd php7

libxml

$ sudo apt-get install libxml2-dev

OpenSSL

$ sudo apt-get install libcurl4-openssl-dev

mcrypt

$ sudo apt-get install curl libmcrypt-dev

GD

configure: error: png.h not found.

$ sudo apt-get install libpng12-dev

configure

$ ./configure --enable-debug --with-mysql --with-gd --with-curl --prefix=/opt/php7 --enable-fpm --enable-cgi --with-openssl --enable-mbstring --with-mcrypt --with-pdo-mysql --with-mysql-sock=/var/run/mysqld/mysqld.sock
$ make -j 4
$ sudo make install

PATH

$ cd ~
$ vim .zshrc # 或者其他的.bashrc什么的

加入以下内容在最后一行:

$PATH=$PATH:/opt/php7/bin;

php-fpm

这个步骤比较长,得有点儿耐心

首先找个php.ini文件,然后放到/opt/php7/lib里面,然后

给两个文件改名

$ suo cp /opt/php7/etc/php-fpm.conf.default /opt/php7/etc/php-fpm.conf
$ suo cp /opt/php7/etc/php-fpm.d/www.conf.default /opt/php7/etc/php-fpm.d/www.conf

然后调整里面的东西

先给个pid取消注释

$ sudo vim /opt/php7/etc/php7-fpm.conf
[...]
pid = run/php-fpm.pid
[...]

改一下用户组和用户

$ sudo vim /opt/php7/etc/php7-fpm.d/www.conf
user = YourUsername
group = YourGroup

然后创建文件:

$ sudo vim /etc/init.d/php7-fpm

写入以下内容,注意一些文件名

#! /bin/sh
### BEGIN INIT INFO
# Provides:          php7-fpm
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts php7-fpm
# Description:       starts the PHP FastCGI Process Manager daemon
### END INIT INFO
php_fpm_BIN=/opt/php7/sbin/php-fpm
php_fpm_CONF=/opt/php7/etc/php-fpm.conf
php_fpm_PID=/opt/php7/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF"
wait_for_pid () {
        try=0
        while test $try -lt 35 ; do
                case "$1" in
                        'created')
                        if [ -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                        'removed')
                        if [ ! -f "$2" ] ; then
                                try=''
                                break
                        fi
                        ;;
                esac
                echo -n .
                try=`expr $try + 1`
                sleep 1
        done
}
case "$1" in
        start)
                echo -n "Starting php-fpm "
                $php_fpm_BIN $php_opts
                if [ "$?" != 0 ] ; then
                        echo " failed"
                        exit 1
                fi
                wait_for_pid created $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        stop)
                echo -n "Gracefully shutting down php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -QUIT `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed. Use force-exit"
                        exit 1
                else
                        echo " done"
                       echo " done"
                fi
        ;;
        force-quit)
                echo -n "Terminating php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -TERM `cat $php_fpm_PID`
                wait_for_pid removed $php_fpm_PID
                if [ -n "$try" ] ; then
                        echo " failed"
                        exit 1
                else
                        echo " done"
                fi
        ;;
        restart)
                $0 stop
                $0 start
        ;;
        reload)
                echo -n "Reload service php-fpm "
                if [ ! -r $php_fpm_PID ] ; then
                        echo "warning, no pid file found - php-fpm is not running ?"
                        exit 1
                fi
                kill -USR2 `cat $php_fpm_PID`
                echo " done"
        ;;
        *)
                echo "Usage: $0 {start|stop|force-quit|restart|reload}"
                exit 1
        ;;
esac

赋权:

$ sudo chmod 755 /etc/init.d/php7-fpm
$ sudo vim /lib/systemd/system/php7-fpm.service

然后写入下面的内容:

[Unit]
Description=The PHP 7 FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/opt/php7/var/run/php-fpm.pid
ExecStart=/opt/php7/sbin/php-fpm --nodaemonize --fpm-config /opt/php7/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target

试试fpm

试试看行不行:

$ php -v
$ sudo /etc/init.d/php-fpm start

没有出错就对了,出错了请在下面留言,我看看怎么回事。

好了,到这里其实已经没有问题了。但是剩下的Nginx也得稍微调整一下

$ sudo vim /etc/nginx/site-available/default

改成这样

fastcgi_pass 127.0.0.1:9000

重启服务,走起!

$ sudo service nginx restart
$ sudo service php7-fpm restart

Swoole

按照他们的指导做就行了

$ git clone https://github.com/swoole/swoole-src.git
$ cd swoole-src
$ phpize
$ ./configure
$ make && sudo make install

在php.ini里面写上扩展

$ sudo vim /opt/php7/lib/php.ini

随便找个地方,不过我还是建议放到extension那边,大概第900行左右

extension=swoole.so

检查一下

试试看swoole有没有安装好

$ php -m | grep swoole

有输出就是没问题,没输出就是有问题。

References



相关阅读 :
linux下安装编译PHP7
Linux下安装PHP zip扩展过程
Linux下安装PHP MSSQL扩展
如何在php下安装编译IMAP支持P
Linux下编译安装php libevent扩展实例
linux下apache2.2.4+mysql5.0.77+php5.2.8安装精简
Linux下 php5 MySQL5 Apache2 phpMyAdmin ZendOptimizer安装与配置
linux下apache+mysql+php+ssl安装攻略
Linux下PHP Oracle数据库扩展安装方法及php连接oracle数据库示例
Linux下PHP安装mcrypt扩展模块方法
Linux下动态安装PHP扩展的一般方法
LINUX下用PHPIZE安装PHP GD扩展
最新网友评论  共有(0)条评论 发布评论 返回顶部
月排行榜

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  服务