今天有个需求,需要测试open-telementry-php的SDK。
一、源码安装Apache
PHP: Unix 系统下的 Apache 2.x - Manual
cd httpd-2_x_NN
./configure --enable-so
make
make install
解决办法:
1、下载所需要的软件包
wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip
2、解决APR not found报错
tar -zxf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure --prefix=/usr/local/apr
make && make install
3、解决APR-util not found问题
tar -zxf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/bin/apr-1-config
make && make install
4、解决pcre问题
unzip -o pcre-8.10.zip
cd pcre-8.10
./configure --prefix=/usr/local/pcre
make && make install
重新配置
./configure --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
make -j8
make install
OK!
现在已经将 Apache 2.x.NN 安装在 /usr/local/apache2。本安装支持可装载模块 和标准的 MPM prefork。之后,可以使用如下命令启动 Apache 服务器:
/usr/local/apache2/bin/apachectl start
如果成功,可以停止 Apache 服务器并继续安装 PHP:
/usr/local/apache2/bin/apachectl stop
二、源码安装php
PHP: Unix 系统下的 Apache 2.x - Manual
现在需要配置并编译 PHP。在这里可以用各种各样的参数来自定义 PHP,例如启动哪些扩展功能包的支持等。用 ./configure --help 命令可以列出当前可用的所有参数。在此例中,将给出一个在有 MySQL 支持的 Apache 2 上进行配置的范例。
1、首先要安装libxml
libxml-2.0 >= 2.9.0)
安装libxml
apt-get install libxml2-dev
apt-get install libxml2
2 、安装openssl
wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz
sudo tar -xf openssl-1.1.1b.tar.gz
cd openssl-1.1.1b
./config --prefix=/usr/local/ssl --openssldir=/usr/local/ssl shared zlib
./config shared zlib
sudo make
sudo make test
3、PHP8.0.13,
不能用8.1,否则composer2.1.14后面获取依赖项时无法运行
./configure --with-apxs2=/usr/local/apache2/bin/apxs --with-pdo-mysql --with-openssl --with-zlib
make -j8
make install
php --version
备注:这里一定要加--with-openssl否则后面的无法使用composer
请注意,除非明确有提示,否则“make install”命令将安装 PEAR、各种 PHP 工具诸如 phpize,并安装 PHP CLI 等等。
4、配置 php.ini
cp php.ini-development /usr/local/lib/php.ini
编辑 httpd.conf 文件以调用 PHP 模块。LoadModule 表达式右边的路径必须指向系统中的 PHP 模块。以上的 make install 命令可能已经完成了这些,但务必要检查。
/usr/local/apache2/conf/httpd.conf
#PHP 8 版本: 在153行
LoadModule php_module modules/libphp.so
#PHP 7 版本:
LoadModule php7_module modules/libphp7.so
还需要添加文件类型映射:
<IfModule mime_module>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
AddType application/x-httpd-php .php
重启HTTP
/usr/local/apache2/bin/apachectl restart
会报告一个错误,
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
需要在httpd.conf中设置ServerName
建立一个网页文件在:
/usr/local/apache2/htdocs
添加测试页面:
<html>
<head>
<title>PHP 测试</title>
</head>
<body>
<?php echo '<p>Hello World</p>'; ?>
<?php phpinfo(); ?>
</body>
</html>
需要更改此文件的权限为可执行文件,
在浏览器访问即可;
5、安装GRPC扩展
wget http://pecl.php.net/get/grpc-1.42.0.tgz
tar -xzvf grpc-1.42.0.tgz
cd grpc-1.42.0
phpize
#which php-config
./configure --with-php-config=/usr/local/bin/php-config
make
make install
vim /usr/local/lib/php.ini
#添加extension=grpc
php -m
#查看扩展是否安装成功
6、安装PROTOBUF: http://pecl.php.net/get/protobuf
wget http://pecl.php.net/get/protobuf
tar -xzvf protobuf-3.19.1.tgz
cd protobuf-3.19.1
phpize
#which php-config
./configure --with-php-config=/usr/local/bin/php-config
make -j8
make install
vim /usr/local/lib/php.ini
#添加extension=protobuf
php -m
#查看扩展是否安装成功
7、建立项目目录
我喜欢配置一个子目录,就是配置虚拟目录
比如添加目录,当前的测试项目路径:/usr/local/soft/testphp/
在php.conf中添加如下部分:子目录名为test,映射到/usr/local/soft/testphp/,并设置目录权限
Alias /test/ "/usr/local/soft/testphp/"
<Directory "/usr/local/soft/testphp">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
访问路径下的测试文件,如果可以显示就是正确了;
http://localhost/test/hello.php
三、安装composer
https://www.jianshu.com/p/2db933f19458
使用方法
https://www.runoob.com/w3cnote/composer-install-and-usage.html
1、 下载
curl -sS https://getcomposer.org/installer | php
如果要让composer在任意目录下都可执行,
将下载的composer.phar移动至/usr/local/bin,命名为composer即可
cp composer.phar /usr/local/bin/composer
composer --version
# 当前版本2.1.14
2、配置
不要配置composer使用国内镜像库,使用官方默认的库,如果不能访问,使用中国移动的热点
composer config -g -l
composer config repo.packagist composer https://repo.packagist.org
备注:网络上其他一些相关的源
composer config repo.packagist composer https://mirrors.aliyun.com/composer/
composer config repo.packagist composer https://mirrors.cloud.tencent.com/composer 不行
composer config repo.packagist composer https://packagist.org
// 默认使用此源可以
composer config -g -l
composer config repo.packagist composer https://repo.packagist.org
composer https://packagist.org
phpcomposer https://packagist.phpcomposer.com
aliyun https://mirrors.aliyun.com/composer
tencent https://mirrors.cloud.tencent.com/composer
huawei https://mirrors.huaweicloud.com/repository/php
laravel-china https://packagist.laravel-china.org
cnpkg https://php.cnpkg.org
sjtug https://packagist.mirrors.sjtug.sjtu.edu.cn
#设置当前项目源
composer config repo.packagist composer https://mirrors.aliyun.com/composer/
# 取消当前项目配置 composer config --unset repos.packagist
#设置全局项目源 composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
# 取消全局配置 composer config -g --unset repos.packagist
四、配置open-telementry-php
地址:https://github.com/open-telemetry/opentelemetry-php
官方手册写的方法有些问题,下载了依赖项之后,autoload似乎有问题,运行时候找不到相关的类
合适的方法是用git clone项目文件,
1)拷贝到php项目目录根节点
2) 更改composre.json,根节点添加属性
"minimum-stability": "dev"
3)直接更新依赖项
composer update
正常情况下,会下载依赖项,并生成vendor目录,
4)测试运行
方法一:
命令行直接运行
cd /usr/local/soft/testphp/examples
php ./GettingStarted.php
方法二:
在浏览器中访问。
真是慌张的一天。

本文详细介绍了如何在Ubuntu18.04上通过源码安装Apache和PHP8.0,包括解决依赖问题、安装GRPC和Protobuf扩展,以及配置Open-Telemetry-PHP。过程中提到了不能使用PHP8.1和特定的composer版本,以及Apache的配置与测试。
717

被折叠的 条评论
为什么被折叠?



