Centos7 install protobuf

1、 Update Centos7 download source
Remember to backup before updating! ! !
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
Reference: http://mirrors.aliyun.com/help/centos
163 Source reference: http://mirrors.163.com/.help/centos.html
2、 Install epel source
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-8.noarch.rpm
If the version is not the same, go here to find http://dl.fedoraproject.org/pub/epel/
rpm -ivh rpm epel-release-7-8.noarch.rpm
yum clean all
yum update
yum makecache
3、 Install PHP environment

Centos7 install LAMP+PHPmyadmin

4、 Install composer
curl -sS https://getcomposer.org/installer | php — –install-dir=/usr/local/bin/
mv /usr/local/bin/composer.phar /usr/local/bin/composer
5、 Install protobuf
yum install php-devel
git clone https://github.com/allegro/php-protobuf.git
cd php-protobuf
yum -y install gcc
yum -y install gcc-c++
yum install make
phpize
. /configure
make && make install
Installing shared extensions: /usr/lib64/php/modules/
composer install
vi /etc/php.ini
Finally add
extension=protobuf.so
7、 Install protoc
wget https://github.com/google/protobuf/releases/download/v2.6.1/protobuf-2.6.1.tar.gz
cd protobuf-2.6.1
. /configure
make
make install
Enter protoc --version
libprotoc 2.6.1
The installation is successful
8、 Test Case
touch foo.proto
Write the following

message Foo
{
required int32 bar = 1;
optional string baz = 2;
repeated float spam = 3;
}
generate
php /root/soft/php-protobuf/protoc-gen-php.php foo.proto
Write the case test.php

setBar(1);
$foo->setBaz('two');
$foo->appendSpam(3.0);
$foo->appendSpam(4.0);

$packed = $foo->serializeToString();

$parsedFoo =newFoo();try{
 $parsedFoo->parseFromString($packed);}catch(Exception $ex){die('Oops.. there is a bug in this example, '. $ex->getMessage());}
$parsedFoo->dump();

Execution case
php -f test.php
Foo {1: bar =>12: baz =>"two"3:spam(2)=>[0]=>3[1]=>4}

Recommended Posts

Centos7 install protobuf
1.5 Install Centos7
Centos6 install Python2.7.13
CentOS7.2 install Mysql5.7.13
CentOS install Redmine
Centos7 install Python 3.6.
CentOS 7 install Docker
CentOS7 install GlusterFS
CentOS 7.4 install Zabbix 3.4
CentOS7 install Docker
Centos6.5 install Tomcat
CentOS install Python 3.6
Vmware install CentOS6
centos7 install docker-ce 18.01.0
CentOS 7.2 install MariaDB
CentOS 7 install Hadoop 3.0.0
Centos7 install Python2.7
Centos 7.6 install seleniu
CentOS 7.3 install Zabbix3
Centos7 install LAMP+PHPmyadmin
CentOS install mysql
CentOS install openjdk 1.8
CENTOS6.5 install CDH5.12.1 (1)
CentOS install PHP
CentOS6 install mist.io
Centos7 install Docker
CentOS7 install mysql
centOs install rabbitMQ
CentOS 7 install MySQL 5.6
Centos7 install Nginx
CentOS6.5 install CDH5.13
Centos7 install docker18
Centos install Python3
centos7 install docker
CentOS install jdk
centos7 install nginx-rtmp
CentOS8 install MySQL8.0
Centos6.3 install KVM
CentOS install PostgreSQL 9.1
CentOS7 install mysql8
CentOS 7 install Java 1.8
CentOS8 install fastdfs6.06
CentOS 7 install Gitlab
Centos 7 install PostgreSQL
CentOS7 install MySQL8
CentOS 7 install Java 1.8
CentOS 6 install Docker
centos 6.5 install zabbix 4.4
Centos8 install Docker
CentOS6.8 install python2.7
CentOS install nodejs 8
CentOS6.5 install GNS3
centos 7.5 install mysql5.7.17
Centos7 install MySQL8.0-manual
CentOS7 install Kubernetes 1.16.3
VirtualBox install centos7
centos7 install lamp
Install centos7 and connect
Install Docker on Centos7
install LNMP on centos7.4
CentOS 8 install ZABBIX4.4 guide