Reputation: 3
Currently I'm working on deploying a php (symfony)/MySQL application on cloud foundry. After deployment, when I connect in SSHto launch commands doctrines for the creation of the schema of the database I have this problem
vcap@5nkjb8jdl87:~/app$ ./php/bin/php app/console doctrine:schema:create --env=prod
Fatal error: Class 'PDO' not found in /home/vcap/app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php on line 172
[Symfony\Component\Debug\Exception\ClassNotFoundException] Attempted to load class "PDO" from the global namespace.Did you forget a "use" statement?
doctrine:schema:create [--dump-sql] [--em [EM]] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interactio
-shell] [--process-isolation] [-e|--env ENV] [--no-debug] [--] <command>
vcap@5nkjb8jdl87:~/app$ ./php/bin/php -m
[PHP Modules]
bcmath
calendar
Core
ctype
date
dom
ereg
filter
hash
iconv
intl
json
libxml
mhash
mysqlnd
pcre
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
[Zend Modules]
vcap@5nkjb8jdl87:~/app$
How to activate the php PDO module in ClI ? Thank you for your help cdt
Upvotes: 0
Views: 704
Reputation: 15041
When you SSH into an application using cf ssh
the system unfortunately does not automatically configure the environment for you. This causes things like PHP to function in different ways (often by failing) because environment variables that affect how PHP functions and where it looks for configuration are not set.
What you need to do to make things the same as when your application runs is to source the environment configuration first. The process for doing this is documented here.
However before doing that please keep in mind that executing the .profile.d
and .profile
scripts can have side-effects. This is because both of these can be extended by your application. This is typically done as a way to run commands prior to your application starting. Make sure that these scripts are safe to run prior to executing the following commands! If parts are not safe, then do not run them. Just execute the commands that are safe.
For reference here, the process boils down to running these commands:
export HOME=/home/vcap/app
export TMPDIR=/home/vcap/tmp
cd /home/vcap/app
source /home/vcap/app/.profile.d/*.sh
source /home/vcap/app/.profile
This sources the .profile.d
& .profile
scripts which initialize the environment.
UPDATE:
A slightly easier way to do this is to run cf ssh myapp -t -c "/tmp/lifecycle/launcher /home/vcap/app bash ''"
. This will open a bash shell and it lets the lifecycle launcher handle sourcing & setting up the environment.
Hope that helps!
Upvotes: 0
Reputation: 1743
you need to install php-mysql
apt-get install php-mysql
if you are using php7
apt-get install php7.0-mysql
find your php.ini file and search for pdo_mysql
;extension=php_pdo_mysql.so
remove ;
extension=pdo_mysql.so
Save the file and restart service and verify.
Upvotes: 1