2 months ago
How do I connect a normal php with a normal MYSQL deployed on Railway
neither PDO works nor MYSQLi works because they are not installed.. what could I do
In the phpinfo web page after deploying it on Railway it shows in the table for the part of MYSQL that API Extensions for MYSQL has no values. This means they are not installed
But on local host XAMPP it have them in its table as
API Extensions || mysqli,pdo_mysql
Under no means the way to install them is to write a custom docker file this is impossible please help IDK anything about docker and I tried with LLMs and its not working
just a basic PHP connection with MYSQL how can this be hard??
1 Replies
2 months ago
Hey, you can connect your php application to any MySQL database using its credentials. You can deploy both your application and MySQL database as two separate services and have them connect to each other using reference variables. Most commonly done using the DATABASE_URL environment variable that serves as the connection string to your MySQL database.
bro thnx so much for ur replay
yh exactly to do so it will either require PDO or MYSQLi which are ways to connect to the database from inside the PHP code itself… connection strings URLs are not used solely to connect to the database from PHP, atleast to my knowledge…
I actually eventually managed to get PDO installed and working by trying a lot with random LLM generated docker files
my concern now is installing JWT as my next step with the docker file and it is not going very smooth so far either and I guess I will suffer with it for a while also…
I guess I will suffer for every single new thing I am gonna install to PHP
I don't know why it is extremely difficult to actually get the basics up and running… there might be a standard way to install things to plain PHP files that I might be missing out on
2 months ago
It sounds like the pdo_mysql and mysqli PHP extensions aren't installed / enabled by default in the container image that you're pulling from, but you were able to work this out by editing the Dockerfile with the help of AI.
XAMMP installs a general purpose development environment and comes with many PHP extensions that may not be readily available in the slimmed down Docker image that you're using.
Are you pulling the official PHP Docker image? There's also a popular script called docker-php-extension-installer that you could use to more easily install the required extensions for your PHP project.
For JWT, does your project require firebase/php-jwt? This package can be installed using the PHP dependency manager Composer. Have you already tried performing a Composer installation from within your Dockerfile?
I don't have an active PHP project that I could use for further testing, but I ran a quick test of a Docker build and was able to install php-JWT this way:
FROM php:8.2-apache
RUN set -eux; \
apt-get update; \
apt-get install -y git unzip;
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
RUN /usr/bin/composer require --no-interaction firebase/php-jwt
EXPOSE 80
CMD ["apache2-foreground"]
And the logs from my build looked like this: #15 [stage-0 6/6] RUN /usr/bin/composer require --no-interaction firebase/php-jwt
#15 0.303 ./composer.json has been created
#15 0.311 Running composer update firebase/php-jwt
#15 0.314 Loading composer repositories with package information
#15 0.481 Updating dependencies
#15 0.485 Lock file operations: 1 install, 0 updates, 0 removals
#15 0.485 - Locking firebase/php-jwt (v6.11.1)
#15 0.485 Writing lock file
#15 0.485 Installing dependencies from lock file (including require-dev)
#15 0.486 Package operations: 1 install, 0 updates, 0 removals
#15 0.489 - Downloading firebase/php-jwt (v6.11.1)
#15 0.713 - Installing firebase/php-jwt (v6.11.1): Extracting archive
#15 1.040 1 package suggestions were added by new dependencies, use composer suggest to see details.
#15 1.040 Generating autoload files
#15 1.043 No security vulnerability advisories found.
#15 1.043 Using version ^6.11 for firebase/php-jwt
The official Docker docs also have a guide for installing composer with more advanced information.
I hope you found this helpful!
2 months ago
PHP data objects does seem to be the way to go when using rational databases with PHP. Although, I am not familiar with PHP, so take this with a grain of salt.
Database connection strings themselves are not tied to any application or programming language, it is rather just a string containing all the necessary information required to the database, such as the provider (MySQL, Postgres, …) user, password, domain, database name, etc.
You can look up the docs of the said library and follow the installation guide or perhaps use an alternative package manager for PHP. For example, Python's default package manager pip is rather unintuitive and people tend to use a different one such as uv. This may also be the case with PHP, although as I have said, I am not really familiar with PHP so this may not be the case with PHP.