错误“未定义符号:mysqlnd_connect”

错误“未定义符号:mysqlnd_connect”

我正在构建一个 VM,使用 Vagrant 2.1.2 开发现有的 PHP 5.6 应用程序。我的 VM 操作系统是 Ubuntu/Bionic64。此应用程序需要带有 mysqlnd 的 mysqli 扩展,以及附加 Vagrantfile 中所述的其他软件包。

我遇到的问题是,当 Apache2 启动时,PHP 会在错误日志中报告,并且在执行每个脚本时继续报告此问题。

[2019 年 1 月 14 日 21:48:24 UTC]PHP 警告:PHP 启动:无法加载动态库‘/usr/lib/php/20131226/mysql.so’-/usr/lib/php/20131226/mysql.so:未定义符号:mysqlnd_connect,位于第 0 行未知位置

[2019 年 1 月 14 日 21:48:24 UTC]PHP 警告:PHP 启动:无法加载动态库‘/usr/lib/php/20131226/mysqli.so’-/usr/lib/php/20131226/mysqli.so:未定义符号:mysqlnd_connect,位于第 0 行未知位置

我努力了:

  • 检查 /etc/php/5.6/cli 目录中的 .ini 文件,以确保 mysqlnd 具有较低的优先级(因此在 mysql 和 mysqli 之前加载)
  • 重命名 /usr/lib/php/20131226 目录中的 mysqli.so 文件,以确保 mysqli 最后加载
  • 在上述所有操作之间重新启动 Apache 服务

VAGRANT文件

# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = '2'
APP_NAME = 'app'

@script = <<-SCRIPT

apt-get update && apt-get upgrade
apt-get install -y software-properties-common
add-apt-repository ppa:ondrej/php
apt-get update

#################### PHP 5.6 ####################
apt-get install -y apt-utils php5.6
a2dismod php7.0
a2dismod php7.2
a2enmod php5.6

#################### APACHE2 ####################
apt-get install -y apache2 libapache2-mod-php

# Add ServerName to httpd.conf
echo "ServerName localhost" > /etc/apache2/httpd.conf

# Setup hosts file
VHOST=$(cat <<EOF
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/#{APP_NAME}/public_html
    ServerName localhost
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory />
        Options Indexes FollowSymLinks MultiViews Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
EOF
)
echo "${VHOST}" > /etc/apache2/sites-enabled/000-default.conf

# Enable mod_rewrite
a2enmod rewrite

# Put PHP into development configuration
mv /etc/php/5.6/apache2/php.ini /etc/php/5.6/apache2/php.ini.back
cp /usr/lib/php/5.6/php.ini-development /etc/php/5.6/apache2/php.ini

# Adjust php.ini file
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/' /etc/php/5.6/apache2/php.ini

# Enable PHP extensions in php.ini
###sed -i 's/;extension=php_curl.dll/extension=curl.so/' /etc/php/5.6/apache2/php.ini
sed -i 's/;extension=php_mysql.dll/extension=mysql.so/' /etc/php/5.6/apache2/php.ini
sed -i 's/;extension=php_mysqli.dll/extension=mysqli.so/' /etc/php/5.6/apache2/php.ini

# PHP will log errors here
sed -i 's:;error_log = php_errors.log:error_log = /home/#{APP_NAME}/public_html/log/error_log:' /etc/php/5.6/apache2/php.ini

#################### PHP Extensions ####################
apt-get install -y php5.6-mysql php5.6-mysqli php5.6-bz2 php5.6-cli php5.6-curl php5.6-intl php5.6-json php5.6-mbstring php5.6-opcache php5.6-soap php5.6-sqlite3 php5.6-xml php5.6-zip unzip php5.6-gd

# Restart apache
systemctl restart apache2.service

#################### MYSQL ####################
apt-get install -y mysql-server mysql-client-core-5.7

systemctl start mysql.service

# Reset root password
#/usr/bin/mysqladmin -u root password 'root'
mysqladmin -u root password 'root'

# Setup database from root user and setup the application user
mysql -uroot -proot -e "CREATE DATABASE IF NOT EXISTS app"
mysql -uroot -proot app < /home/#{APP_NAME}/public_html/db/schema.sql
mysql -uroot -proot app < /home/#{APP_NAME}/public_html/db/seed.sql
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* to 'vagrant'@'localhost' IDENTIFIED BY '*****'"
mysql -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* to 'vagrant'@'%' IDENTIFIED BY '*****'"
mysql -uroot -proot -e "FLUSH PRIVILEGES"

# Allow remote connections to mysql (don't do it like this in production)
MYSQLCONF=$(cat <<EOF

[mysqld]
bind-address        = 0.0.0.0
EOF
)
echo "${MYSQLCONF}" >> /etc/mysql/my.cnf

# Restart mysql
/etc/init.d/mysql restart

SCRIPT

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.box = 'ubuntu/bionic64'
    config.ssh.insert_key = false
    config.vm.network "forwarded_port", guest: 80, host: 8080
    config.vm.network "forwarded_port", guest: 443, host: 8081
    config.vm.network "forwarded_port", guest: 3306, host: 3307

    # We do not want Vagrant picking the root directory
    config.vm.synced_folder ".", "/vagrant", disabled: true
    config.vm.synced_folder ".", "/home/#{APP_NAME}/public_html"

    # Provision runs only on the first "Vagrant up" command
    config.vm.provision 'shell', privileged: true, inline: @script

    config.vm.provider "virtualbox" do |vb|
        vb.customize ["modifyvm", :id, "--memory", "2048"]
        vb.customize ['modifyvm', :id, "--natdnshostresolver1", "on"]
        #vb.customize ["modifyvm", :id, "--name", "domain.com"]
    end
end

相关内容