# 开启apache
sudo apachectl restart
sudo vim /etc/apache2/httpd.conf
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/opt/homebrew/etc/php/8.1/
To restart shivammathur/php/php after an upgrade:
brew services restart shivammathur/php/php
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
# sign
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so "marstau"
# install mcrypt
pecl install mcrypt-1.0.5
yum install -y curl
# if download failed, copy by hand.
curl -o php-7.2.9.tar.xz http://cn2.php.net/distributions/php-7.2.9.tar.xz
yum install -y tar xz
xz -d php-7.2.9.tar.xz
tar -xvf php-7.2.9.tar
cd php-7.2.9
# 编译 PHP 之前我们需要安装 PHP 编译工具和依赖:
yum install -y gcc autoconf gcc-c++ \
libxml2 libxml2-devel \
openssl openssl-devel \
bzip2 bzip2-devel \
libcurl libcurl-devel \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
gmp gmp-devel \
readline readline-devel \
libxslt libxslt-devel \
libmcrypt libmcrypt-devel \
mhash mhash-devel \
systemd-devel openjpeg-devel
# php-7.4.16
yum install -y libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel ncurses curl gdbm-devel db4-devel libXpm-devel libX11-devel gd-devel gmp-devel expat-devel xmlrpc-c xmlrpc-c-devel libicu-devel libmcrypt-devel libmemcached-devel
# 安装完编译工具和依赖后,我们需要为 FPM 分配一个运行用户和用户组(我们取名 php-fpm:php-fpm 并设置不予怒登录和不创建家目录):
groupadd php-fpm && useradd -s /sbin/nologin -g php-fpm -M php-fpm
php-7.4.16:
# sqlite3
sudo yum install sqlite-devel -y
wget https://github.com/kkos/oniguruma/releases/download/v6.9.5_rev1/onig-6.9.5-rev1.tar.gz -O onig-6.9.5.tar.gz
./configure --prefix=/usr --libdir=/lib64
# libzip
wget https://libzip.org/download/libzip-1.5.2.tar.gz -O libzip-1.5.2.tar.gz
tar xvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build && cd build
cmake ..
make && make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
# pcre2
wget https://github.com/PCRE2Project/pcre2/releases/download/pcre2-10.39/pcre2-10.39.tar.gz pcre2-10.39.tar.gz
tar xvf pcre2-10.39.tar.gz
cd pcre2-10.39
./configure
make && make install
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig
配置phpMore
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype-dir \
--enable-mbstring \
--with-libxml-dir=/usr \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--with-gd \
--with-pear \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--enable-zip \
--with-pcre-regex \
--with-jpeg-dir=/usr \
--with-png-dir=/usr \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd
# php7.4.16
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc \
--with-zlib-dir \
--with-freetype \
--enable-mbstring \
--with-libxml \
--enable-xmlreader \
--enable-xmlwriter \
--enable-soap \
--enable-calendar \
--with-curl \
--with-zlib \
--enable-gd \
--with-pear \
--with-pdo-sqlite \
--with-pdo-mysql \
--with-mysqli \
--with-mysql-sock \
--enable-mysqlnd \
--disable-rpath \
--enable-inline-optimization \
--with-bz2 \
--with-zlib \
--enable-sockets \
--enable-sysvsem \
--enable-sysvshm \
--enable-pcntl \
--enable-mbregex \
--enable-exif \
--enable-bcmath \
--with-mhash \
--with-zip \
--with-external-pcre \
--with-jpeg \
--with-openssl \
--enable-ftp \
--with-kerberos \
--with-gettext \
--with-xmlrpc \
--with-xsl \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd
make && make install
cp php.ini-development /usr/local/php/etc/php.ini
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
# add following:
error_log = /usr/local/php/var/log/php-fpm.log
pid = /usr/local/php/var/run/php-fpm.pid
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
cd ~/php-7.2.9
cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/
systemctl enable php-fpm
# add php to environment variable
vim /etc/profile
# add following:
export PATH=$PATH:/usr/local/php/bin/
source /etc/profile
php -v
create plus-test.php to test php, run php plus-test.php
:
<?php
declare(strict_types=1);
echo 'exec function: ', function_exists('exec') ? '1' : '0', PHP_EOL;
echo 'system function: ', function_exists('system') ? '1' : '0', PHP_EOL;
echo 'scandir function: ', function_exists('scandir') ? '1' : '0', PHP_EOL;
echo 'symlink function: ', function_exists('symlink') ? '1' : '0', PHP_EOL;
echo 'shell_exec function: ', function_exists('shell_exec') ? '1' : '0', PHP_EOL;
echo 'proc_open function: ', function_exists('shell_exec') ? '1' : '0', PHP_EOL;
echo 'proc_get_status function: ', function_exists('proc_get_status') ? '1' : '0', PHP_EOL;
# correct output:
exec function: 1
system function: 1
scandir function: 1
symlink function: 1
shell_exec function: 1
proc_open function: 1
proc_get_status function: 1
foreach ($items as $value) {
$value['reg'] = 10000;
}
修改为
foreach ($items as &$value) {
$value['reg'] = 10000;
}
方法同理
function fun(&$items){}
function foo($a, $b, ...$args)
{
$numargs = count($args);
echo "Number of arguments: $numargs<br />\n";
if ($numargs >= 2) {
echo "Second argument is: " . func_get_arg(1) . "<br />\n";
}
$arg_list = $args;
for ($i = 0; $i < $numargs; $i++) {
echo "Argument $i is: " . $arg_list[$i] . "<br />\n";
}
}
foo(1,2,3);
$file = 'log.txt';
$content = 'abc';
file_put_contents($file, $content.PHP_EOL,FILE_APPEND);
调用
$sender_io->on('connection', function($socket){
...
});
<?php
$arr = array('Hello','World!','I','love','Shanghai!');
echo implode(" ",$arr);
?>
var_dump($arr)
print_r($arr)
array array_splice ( array &$input , int $offset [, int $length = count($input) [, mixed $replacement = array() ]] )
数组会被重新索引
$arr = array('a','b','c','d');
array_splice($arr,1,1); // 第二个参数为索引,非数据
print_r($arr);
<?php
$array = array(0 => "a", 1 => "b", 2 => "c");
$array = array_diff($array, ["a", "c"]);
//└────────┘→ 你想删除的数组元素值values
?>
输出
Array (
[1] => b
)
<?php
$array = array(0 => "a", 1 => "b", 2 => "c");
unset($array[1]);
//↑ 你想删除的key
?>
输出
Array (
[0] => a
[2] => c
)
然后重排索引,使用array_values
$array = array_values($array);
/*
输出
array(2) {
[0]=>
string(1) "a"
[1]=>
string(1) "c"
}
*/
array_merge_recursive($dataArray, $dataArray2);
array_push()函数将数组当成一个栈,将传入的变量压入该数组的末尾,该数组的长度将随着入栈变量数目的增加而增加,返回数组新的单元总数。
语法格式:
int array_push ( array &$array , mixed $var [, mixed $... ] )
$names[] = 'lucy';
$names[] = 'lily';
// 等同于
array_push($names, 'lucy', 'lily');
无区别
count($arr);
sizeof($arr);
empty
$k = '10';
if ('10' == $k) {} // true
function a(){
if ('10' == $k) {} // false
}
function b(){
global $k;
if ('10' == $k) {} // true
}
$conn = new mysqli($host, $username, $password, $dbname);
if($conn->connect_errno){
die("数据库链接失败:".$conn->connect_error);
}
$sql = "select * from region";
$reslut =$conn->query($sql);
if($reslut) {
while($attr = $reslut->fetch_row()){
// ... $attr[0]
}
}
$conn->close();
failed to open error_log (/usr/local/php/var/log/php-fpm.log): Read-on...stem (30)
Moresystemctl restart php-fpm
启动失败
Solution:
打开 /usr/lib/systemd/system/php-fpm.service 把
ProtectSystem=true
改成
ProtectSystem=false
[Tue May 31 00:45:17.264533 2022] [so:error] [pid 2648] AH06665: No code signing authority for module at /opt/homebrew/opt/php/lib/httpd/modules/libphp.so specified in LoadModule directive.
httpd: Syntax error on line 191 of /private/etc/apache2/httpd.conf: Code signing absent - not loading module at: /opt/homebrew/opt/php/lib/httpd/modules/libphp.so
mac缺少freetype库
安装另一个版本php(带 freetype)
brew install php@7.1
修改为apache
启动
xxx.pid
in /workerman/Worker.php
Moreworkerman要在这个目录写一个pid文件记录workemran主进程pid 新建pid目录即可。
apache版本和PHP版本不兼容
// Converts it into a PHP object $data = json_decode($json); logger->info($data->p1)
#### json用json_decode转为数组
$obj_rs[“extend”] = (array)json_decode($obj_rs[“shop_extend”]);
#### AES加密解密[More](http://www.fairyland.live/wordpress/2017/03/16/php%E4%B8%8Ejavascript%E5%85%BC%E5%AE%B9%E7%9A%84aes%E5%8A%A0%E8%A7%A3%E5%AF%86/)
use phpseclib\Crypt\AES; $cipher = new AES(); // could use CRYPT_AES_MODE_CBC $cipher->setKey(‘amOWLGDgZCyrG4ARTDf64Qn3FEigIQhw’); // keys are null-padded to the closest valid size // longer than the longest key and it’s truncated $cipher->setKeyLength(256); // the IV defaults to all-NULLs if not explicitly defined $cipher->setIV(‘PPwFSQW0i7d3Unpa4ZmmILPcznV51AAa’); $deWorld = $cipher->decrypt(base64_decode($messageStr)); ```