a year ago
I am running a php web application and I would like to track error in my new relic dashboard, how do I do that? Because it seems like I need access to the php.ini
0 Replies
a year ago
for ease of use, you would want to use a Dockerfile so that it's easy to copy in your own php.ini into the container.
a year ago
nope, nixpacks and a Dockerfile are separate things
a year ago
nixpacks tries to determine the app and what the app needs to run and builds an image automatically for you (or for railway in this case)
a Dockerfile is a text file with what is essentially just a list of commands that you write yourself, that tell the builder how to build an image and run your application.
you will get far more flexibility out of a Dockerfile than you would nixpacks. since you then control nearly everything that's run during build.
a year ago
that's correct, it's either one or the other
a year ago
there would be absolutely no shortage of examples for Dockerfiles that run php apps with a modified php.ini file, and since Dockerfiles are in no way exclusive to Railway, so as long as you follow some best practices you'll have what you need up and running in no time
Because I kinda developed my application using the nixpacks way, so if I have to write Dockerfile myself then I'll have to figure a lot of things
a year ago
like I said, it's essentially a file with a list of commands that tell the builder what to run during build and how to run your app, as long as you understand the php ecosystem you will have no difficulties
a year ago
watch some YouTube videos, read some articles, look at some examples, you'll pick it up in no time!
a year ago
sounds good!
a year ago
happy to help!
Um a little bit more help, here's my dockerfile
# Stage 1: Build the application with Node.js and Composer
FROM node:18 AS build-stage
# Set the working directory
WORKDIR /app
# Install PHP and PostgreSQL extension
RUN apt-get update && \
apt-get install -y php php-pgsql
# Copy package.json and pnpm-lock.yaml
COPY package.json pnpm-lock.yaml ./
# Install pnpm
RUN npm install -g pnpm
# Install Node.js dependencies using pnpm
RUN pnpm install
# Copy Composer files
COPY composer.json composer.lock ./
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Install PHP dependencies
RUN composer install
# Copy the application code to the container
COPY src/ /app/src
# Stage 2: Set up the PHP and Nginx environment
FROM php:8.1-fpm
# Install Nginx
RUN apt-get update && apt-get install -y nginx
# Install PostgreSQL extension for PHP
RUN apt-get install -y libpq-dev && docker-php-ext-install pdo pdo_pgsql pgsql
# Copy Nginx configuration file
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
# Copy the PHP application from the build stage
COPY --from=build-stage /app /var/www/html
# Set the working directory
WORKDIR /var/www/html
# Expose port 80
EXPOSE 80
# Start Nginx and PHP-FPM
CMD ["sh", "-c", "php-fpm -D && nginx -g 'daemon off;'"]
Now it works on my PC when I use docker run --env-file .env -p 8080:80 my-php-nginx-app
, but it doesn't work when I run on railway
@Brody really need your help 😭 Now the issue is it's serving the nginx example page rather than my actual website, but whenever I try running the docker in my PC it's working perfectly. What could be the issue?
a year ago
you need to copy your site files into the location of the serve folder
a year ago
Custom php.ini in nixpacks will come hopefully soon, I'll do it when I have any free time
a year ago
So probably in a couple weeks 😅
Copied, here's my Nginx config file:
events {
worker_connections 4096; # Default: 1024
}
http {
server {
listen 80;
listen [::]:80;
server_name localhost;
root /var/www/html/src;
location ~ /\.ht {
deny all;
}
client_max_body_size 10M;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";
index index.php;
charset utf-8;
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.php;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
location /sso/organization/ {
rewrite ^/sso/organization/(.+)$ /sso/organization/update.php?id=$1 last;
}
location /sso/event/ {
rewrite ^/sso/event/(.+)$ /sso/event/update.php?id=$1 last;
}
location /portal/organization/ {
rewrite ^/portal/organization/(.+)$ /portal/organization/?id=$1 last;
}
location /portal/event/ {
rewrite ^/portal/event/(.+)$ /portal/event/update.php?id=$1 last;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
error_page 404 /notfound.php;
}
}
Now I have to add PORT
variable into my deployment and in the docs mentioned its not recommended to do so. But whenever I try using variable like ${PORT}
it doesnt work. How do I fix it?
No worries, it will helps in my future project, I already started writing DockerFile :D
a year ago
nginx does not provide a native way to listen on the PORT environment variable, for this you will have to set a static port in your nginx config file and in the service variables
a year ago
have you followed their docs