网站首页linux
编译安装PHP8.2及yaf,swoole,redis等扩展
发布时间:2016-05-10 22:04:37编辑:slayer.hover阅读(9134)
基于阿里云vps, 安装php8.2到/www/server/php/82目录下。
首先编译安装openResty.
#yum -y install pcre-devel openssl openssl-devel
#wget https://openresty.org/download/openresty-1.13.6.2.tar.gz
#tar -zxvf openresty-1.13.6.2.tar.gz
#cd openresty-1.13.6.2
#./configure --prefix=/opt/openresty --with-luajit
#make && make install
一、下载编译安装php8.2:
1.添加www用户组
groupadd www
2.添加www用户
useradd -g www www
3.预先安装所有可能会用到的包.
yum -y install pcre pcre-devel gcc gcc-c++ openssl openssl-devel libicu-devel autoconf libjpeg \
libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel \
glibc glibc-devel glib2 glib2-devel ncurses ncurses-devel curl curl-devel krb5-devel libidn \
libidn-devel openldap openldap-devel nss_ldap jemalloc-devel cmake boost-devel bison automake \
libevent libevent-devel gd gd-devel libtool* libmcrypt libmcrypt-devel mcrypt mhash libxslt \
libxslt-devel readline readline-devel gmp gmp-devel libcurl libcurl-devel openjpeg-devel
在./configure时可能会出现的报错,如:configure: error: Cannot find ldap libraries in /usr/lib
解决方法执行拷贝文件:
#cp -frp /usr/lib64/libldap* /usr/lib/
4.下载php7.4源码,编译&&安装
a>#wget https://www.php.net/distributions/php-8.2.22.tar.gz
b>#tar -zxvf php-8.2.22.tar.gz
c>#cd php-8.2.22
d>#./configure \
--prefix=/www/server/php/82 \
--with-config-file-path=/www/server/php/82/etc \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--disable-rpath \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--enable-ftp \
--enable-gd \
--enable-gd-jis-conv \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--disable-fileinfo \
--enable-opcache \
--with-pear \
--enable-maintainer-zts \
--with-ldap=shared \
--without-gdbm
其它的未找到库文件之类的报错,按错误提示挨个安装:(如果有的话)
yum install -y libxslt libxslt-devel libxml2 libxml2-devel pcre-devel bzip2 bzip2-devel
报错error: Package requirements (sqlite3 > 3.7.4) were not met
No package 'sqlite3' found
解决:
yum install libsqlite3x-devel -y
报错error: Package requirements (oniguruma) were not met
No package 'oniguruma' found
解决:
yum install oniguruma-devel -y
最终不在报错,则继续编译安装:
e>#make -j8
超长时间的等待.......
f>#make install
完工, 拷贝配置文件:
#cp ./php.ini-production /www/server/php/82/etc/php.ini
#cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm
#cp /usr/local/php/etc/php-fpm.conf.default /www/server/php/82/etc/php-fpm.conf
#cp /usr/local/php/etc/php-fpm.d/www.conf.default /www/server/php/82/etc/php-fpm.d/www.conf
至此,php8.2.22已经成功安装到/usr/local/php目录下。
二、配置php8.2的php-fpm:
编辑php7-fpm文件, 并对照更新下面几行,主要是php-fpm的运行文件、配置文件、pid的路径要一一对应。
#vim /etc/init.d/php8-fpm
prefix=/www/server/php/82
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
b>#chmod 777 /etc/init.d/php8-fpm
c>启动php8-fpm
#/etc/init.d/php8-fpm start
三、配置更新nginx,使用php8-fpm解析php文件。
a>#vim /usr/local/nginx/conf/nginx.conf
修改此段,fastcgi_pass unit:/tmp/php8-cgi.sock; 使php8解析器工作:
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php8-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
b>重新启动nginx
四、安装redis
a>安装redis服务器
#yum install redis
b>安装redis的php扩展
#wget -c https://pecl.php.net/get/redis-4.2.0.tgz
#tar zxvf redis-4.2.0.tgz
#cd redis-4.2.0
#/www/server/php/82/bin/phpize
#./configure --with-php-config=/www/server/php/82/bin/php-config
#make
#make install
此编译过程中,出了点意外,报个library.lo不是合法的libtool库文件什么什么的,
网上找了一圈,解决方法是清除之前编译的可执行文件及配置文件, 重新编译:
#make clean
#make && make install
在php.ini中添加redis.so
#vim /www/server/php/82/etc/php.ini
extension=redis.so
五、安装PHP的yaf扩展
a>下载
#wget http://pecl.php.net/get/yaf-3.0.7.tgz
b>解压、编译、安装,步骤同上面的redis扩展
#tar -zxvf yaf-3.0.7.tgz
#cd yaf-3.0.7
#/www/server/php/82/bin/phpize
#./configure --with-php-config=/www/server/php/82/bin/php-config
#make && make install
在php.ini中添加yaf.so
#vim /www/server/php/82/etc/php.ini
extension=yaf.so
六、安装PHP的swoole扩展
a>下载
#git clone https://gitee.com/swoole/swoole.git
b>解压、编译、安装,步骤同上:
#cd swoole
#/www/server/php/82/bin/phpize
#./configure --with-php-config=/www/server/php/82/bin/php-config
#make && make install
在php.ini中添加swoole.so
#vim /www/server/php/82/etc/php.ini
extension=swoole.so
七、安装PHP的msgpack扩展
a>下载
#wget http://pecl.php.net/get/msgpack-2.0.1.tgz
b>解压、编译、安装,步骤同上:
#tar -zxvf msgpack-2.0.1.tgz
#cd msgpack-2.0.1
#/www/server/php/82/bin/phpize
#./configure --with-php-config=/www/server/php/82/bin/php-config
#make && make install
在php.ini中添加msgpack.so
#vim /www/server/php/82/etc/php.ini
extension=msgpack.so
八、安装mysql数据库(MariaDB)
使用阿里云的10.4版本,更新mariaDB yum源,直接在shell下执行
cat <<EOF > /etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://mirrors.aliyun.com/mariadb/yum/10.4/centos7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
enabled=1
gpgcheck=1
EOF
a>#yum install mariadb-server mariadb #安装MariaDB
b>#systemctl start mariadb #启动MariaDB
c>#systemctl stop mariadb #停止MariaDB
d>#systemctl restart mariadb #重启MariaDB
e>#systemctl enable mariadb #设置开机启动
MariaDB修改root密码和以往的方式不太一样, 使用下面的命令:
MariaDB> SET PASSWORD FOR root@localhost = PASSWORD("your_password");
MariaDB> flush privileges;
九、最后重启一下php8-fpm, 启动redis server, 上面安装的就全部生效了。
a>service php8-fpm restart
b>service redis start
完工。
评论