[Fri Jul 27 03:08:18.935217 2018] [:error] [pid 11] [client 172.18.0.1:54146] PHP Fatal error: Cannot redeclare CreateUniqeSlugOfuser() (previously declared in /var/www/public_html/livesite/application/helpers/MY_url_helper.php:111) in /var/www/public_html/livesite/application/helpers/my_url_helper.php on line 111
Above is the error, I thought maybe this was a simple rename the file in my directory to MY_url_helper with the uppercase but this did not fix the error as some sites have said. As it stands I have no idea how to fix this but I do have some clues.
I'm not a code igniter expert, I took on this project from another developer, but it currently works on their server. It does not work on my server however. Seeing as the issue is probably with autoloading, what could be the thing I'm doing wrong? Could a different version in PHP be causing this issue?
Another hunch is maybe it's some cache I have to change? I'm not sure though... any ideas are appreciated.
I will say after changing the file name the error still thinks I'm using the lowercase version? I know it's reading the file cause I can throw phpinfo in the file and it seems to trigger hence the image I uploaded as a result of that.
Update:: Did echo CI_VERSION command to find this (2.2.0). Maybe this version is not compatible with PHP 7.0?
php56 is for sure the version on the other server... I will see if I can get a docker image of this somehow.
Well 5.6 still error.
Dockerfile
FROM php:5.6-apache
MAINTAINER Joe Astrahan <jastrahan#poolservice.software>
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y \
bzip2 curl git less mysql-client sudo unzip zip \
libbz2-dev libfontconfig1 libfontconfig1-dev \
libfreetype6-dev libjpeg62-turbo-dev libpng-dev libzip-dev && \
rm -rf /var/lib/apt/lists/*
RUN docker-php-ext-install bz2 && \
docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/ \
--with-jpeg-dir=/usr/include/ && \
docker-php-ext-install gd && \
docker-php-ext-install iconv && \
docker-php-ext-install opcache && \
docker-php-ext-install pdo_mysql && \
docker-php-ext-install zip
RUN curl -sS https://getcomposer.org/installer \
| php -- --install-dir=/usr/local/bin --filename=composer
# Set environment variables for Apache so we know its user and group names
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
# Configure Apache SSL and Standard Virtualhosts
COPY config/apache_default.conf /etc/apache2/sites-available/000-default.conf
COPY config/apache_default-ssl.conf /etc/apache2/sites-available/default-ssl.conf
COPY config/run /usr/local/bin/run
# Configure SSL Directories & Create Temporary SSL Keys
RUN mkdir /etc/apache2/ssl
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt -subj "/C=US/ST=Florida/L=Fort Lauderdale/O=Pool Service Software LLC/OU=IT Department/CN=dev.poolservice.software.local"
RUN chmod +x /usr/local/bin/run
RUN a2enmod rewrite
#Configure SSL On Apache2 & Headers Mod
RUN a2enmod ssl
RUN a2enmod headers
RUN service apache2 restart
RUN a2ensite default-ssl.conf
RUN service apache2 restart
#Install Zip & Unzip
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install zip unzip -y
#Install NodeJS
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y \
software-properties-common
EXPOSE 80
EXPOSE 443
CMD ["/usr/local/bin/run"]
Maybe you already loaded the helper either in autoload or a class that was initialized before you attempted to load it again. CI is able to prevent duplicates with classes but not pure php helper files. That is why they surround their functions with:
if (!function_exists('functionname')) { ... }
I would suggest you do the same.
So I solved the issue. Turns out PHP version didn't really make a difference, my docker file was changed to PHP 7.0 since it worked with that, I'll attach it below.
It turns out that CodeIgniter 2.x was using mysql instead of mysqli, so I changed all references in the code accordingly. Also I had to rename the file my_url_helper to just urlhelper_helper and then in the autoload file change it accordingly so it would load the correct file. For some reason even though it worked on the old server, I had to do this to get it to work with either version of PHP.
These fixes were all that were necessary to fix it.
Related
I am building an app (PHP/Laravel) that is supposed to be deployed on Google's App Engine. One of the components of the app is to be able to connect to an MSSQL server. Everything worked fine when I was debugging it, but as soon as I deployed it to the App Engine - guess what? It does not work (error: could not find driver).
I went through the Google documentation and I found out that the MSSQL drivers (pdo_sqlsrv, sqlsrv) are not enabled nor available in the standard environment. I checked the flexible environment, but that's the same. The difference is that I can use my own runtime using Dockerfile.
I changed two lines of my app.yaml in the root directory:
runtime: custom
env: flex
Then I created my Dockerfile also in the root directory that was supposed to install sqlsrv and pdo_sqlsrv using PECL and enable it:
FROM gcr.io/google-appengine/php72:latest
ARG COMPOSER_FLAGS='--prefer-dist --ignore-platform-reqs --optimize-autoloader'
ENV COMPOSER_FLAGS=${COMPOSER_FLAGS}
ENV SWOOLE_VERSION=4.3.4
ENV DOCUMENT_ROOT=/app/public
ENV ACCEPT_EULA=Y
COPY . $APP_DIR
RUN apt-get update -y \
&& curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
&& curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update -y \
&& apt-get install -y \
unzip \
autoconf \
build-essential \
libmcrypt-dev \
libmpdec-dev \
libpq-dev \
unixodbc-dev \
msodbcsql17 \
mssql-tools \
php-common \
&& apt-get update \
&& pecl install \
decimal \
sqlsrv \
pdo_sqlsrv \
xdebug \
&& apt-get update \
&& phpenmod sqlsrv pdo_sqlsrv \
&& curl -o /tmp/swoole.tar.gz https://github.com/swoole/swoole-src/archive/v$SWOOLE_VERSION.tar.gz -L \
&& tar zxvf /tmp/swoole.tar.gz \
&& cd swoole-src* \
&& phpize \
&& ./configure \
--enable-coroutine \
--enable-async-redis \
--enable-coroutine-postgresql \
--enable-sqlsrv=static --with-pdo_sqlsrv=static \
&& make \
&& make install \
&& chown -R www-data.www-data $APP_DIR \
&& /build-scripts/composer.sh;
ENTRYPOINT ["/build-scripts/entrypoint.sh"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
EXPOSE 8080
I also have my own php.ini with two lines in the root directory:
extension = pdo_sqlsrv.so
extension = sqlsrv.so
According to the Google documentation, having this file in the root of an app will extend/replace their default php.ini with my configuration. However, I only found this statement in the docs for non-custom runtimes. I tested it out by changing the value of display_errors and then phpinfo(). The display_errors was still set to the default value and get_loaded_extensions() didn't display sqlsrv nor pdo_sqlsrv.
I checked the build-log and it seems that the drivers were properly installed, because in the 3714 lines I found:
Installing '/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/sqlsrv.so'
install ok: channel://pecl.php.net/sqlsrv-5.8.1
.....
Installing '/opt/php72/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/pdo_sqlsrv.so'
install ok: channel://pecl.php.net/pdo_sqlsrv-5.8.1
.....
configuration option "php_ini" is not set to php.ini location
You should add "extension=sqlsrv.so" to php.ini
configuration option "php_ini" is not set to php.ini location
You should add "extension=pdo_sqlsrv.so" to php.ini
Does anybody have any experience with this, please? What do I need to change in the Dockerfile to make Google App Engine enable the PHP extensions?
TL;DR: Add COPY php.ini /opt/php/lib/conf.d/ to Dockerfile.
Google documentation for GAE Standard environment says that you can place php.ini into the root directory, but I didn't find anything like that about Flexible env. Indeed, if you check Configuration File in phpinfo, and related. fields, they show other paths they're looking for php.ini, so you need to place the file there.
When I try that, the custom php.ini is loaded and allows overwriting display_errors, which you mentioned didn't work for you.
Multi-stage build
To avoid shipping C compiler and other build tools to production, which is wasteful and may slow down deployment of your app, you should also use docker's multi-stage build. Basically, you'll build the extensions in one "builder" container and copy the compiled result to the production container.
You Dockerfile will look sth like this:
FROM gcr.io/google-appengine/php72:latest AS builder
RUN apt-get update -y \
&& apt-get install -y \
unzip \
autoconf \
build-essential \
libmcrypt-dev \
libmpdec-dev \
libpq-dev \
unixodbc-dev \
php-common \
&& pecl install \
sqlsrv \
pdo_sqlsrv
FROM gcr.io/google-appengine/php72:latest
# Copy extensions from builder above
ENV PHP_EXT_DIR=/opt/php/lib/x86_64-linux-gnu/extensions/no-debug-non-zts-20170718/
COPY --from=builder $PHP_EXT_DIR/sqlsrv.so $PHP_EXT_DIR/
COPY --from=builder $PHP_EXT_DIR/pdo_sqlsrv.so $PHP_EXT_DIR/
# Install runtime dependencies
ENV ACCEPT_EULA=Y
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -\
&& curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update -y \
&& apt-get install -y \
msodbcsql17 \
mssql-tools
...
I have set up a Symfony4 project with in a Docker container.
I followed the Jobeet-Tutorial where they use the phpdocker.io - generator.
All works perfect but very slow. So I want to speed up and enable the opcache and configure it.
I found helpful links in the net. So I added to my Dockerfile this:
RUN docker-php-ext-configure opcache --enable-opcache \
&& docker-php-ext-install opcache
# Copy configuration
COPY config/opcache.ini $PHP_INI_DIR/conf.d/
The problem is that I don't have this helperscripts:
docker-php-ext-configure
docker-php-ext-install
docker-php-ext-enable
So I decided to search it in the internet and copy it into my project.
Now I have it in the php-fpm folder of my docker directory.
My directory looks like this now - the scripts are in the beneath the Dockerfile:
Is there any other step I forgot to do, like registering these scripts somewhere?
The most immediate answer to your question is that you need to copy those scripts into the Docker image you are building. To do that, you should create a subdirectory within the php-fpm directory named bin and put all of those scripts in that directory. Then, in your Dockerfile:
COPY bin /usr/local/bin
Now when you try to use that image, the scripts will be within your executable PATH.
However
Those docker-php-ext-* scripts you found are from the PHP project's official Docker images and are intended to be used with those images.
You are using the phpdockerio/php73-fpm:latest image, which seems to use ubuntu:bionic as a base image. These scripts depend heavily on the PHP Dockerfiles, which do a bunch of preparatory steps, such as downloading the source code for the PHP interpreter itself to /usr/src. Making these scripts run directly in a phpdockerio container would be a very involved process.
That leaves you with 2 options:
Forgo the scripts and install Ubuntu's prebuilt packages. You seem to already have the apcu, apcu-bc, cli, curl, json, mbstring, opcache, readline, xml, and zip PHP extensions installed. You can see the full list of packages that are available from the default repos this way by running
docker run --rm -it phpdockerio/php73-fpm:latest bash -c 'apt-get update && apt search ^php7.3-';
When you know which packages you want, you can add them to your Dockerfile.
Switch to using an official PHP image instead so you can use the docker-php-ext-* scripts. The phpdocker-io image you are using is essentially PHP7.3-FPM on Ubuntu, and the closest official PHP image to that is php:7.3-fpm-stretch (Debian 9). You can build and install the extensions listed in Option 1 by changing your PHP-FPM Dockerfile to:
FROM php:7.3-fpm-stretch
# Run in Bash instead of Bourne shell to get lists
RUN ["bash", "-c", " \
#Exits on error or unbound variable. Now we can use semicolons instead of
#ampersands
set -eu; \
\
ext_build_dependencies=( \
#Needed to build php-curl
libcurl4-gnutls-dev \
\
#Needed to build php-mbstring
libedit-dev \
\
#Needed to build php-xml \
libxml2-dev \
\
#Needed to build php-zip
zlib1g-dev libzip-dev \
); \
\
apt-get update; \
apt-get install -y ${ext_build_dependencies[#]}; \
\
#Build the extensions
docker-php-ext-install curl json mbstring readline xml zip ; \
pecl install apcu apcu_bc; \
\
apt-get purge -y ${ext_build_dependencies[#]}; \
apt-get autoremove -y; \
apt-get clean -y; \
"]
If Ubuntu 18 and Debian were binary-compatible (they're not), you could try a third option, which would be building the extensions using a PHP image, then copying over the built extensions as the second stage of a multi-stage build. This would be possible if your image uses the same Linux flavor as as the PHP image does. For example, if your image were based on alpine:3.8, you could use php:7.3-fpm-alpine3.8 to build your extensions and copy them over.
I would appreciate any help I can get with following issue.
I've set up Symfony Messenger to use AMQP and RabbitMQ. I can dispatch message and make use of AMQPConnection within my project.
But when I try to consume the message I get following:
$ php bin/console messenger:consume-messages amqp
Attempted to load class "AMQPConnection" from the global namespace.
Did you forget a "use" statement for "PhpAmqpLib\Connection\AMQPConnection"?
The console command calls a method within AmqpFactory.php
public function createConnection(array $credentials): \AMQPConnection
{
return new \AMQPConnection($credentials);
}
So when I run the project from the browser, everything works fine. I can use AMQPConnection and all. But when running from terminal, it cannot find the AMQPConnection class.
From within my composer.json I also have the amqplib installed
"php-amqplib/php-amqplib": "^2.7",
I use Docker and the Dockerfile contains:
FROM php:7-apache
RUN usermod -u 1000 www-data &&\
a2dissite 000-default &&\
apt-get update &&\
apt-get install -y \
zlib1g-dev \
libicu-dev \
g++ \
libfreetype6-dev \
libssh-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
librabbitmq-dev \
libpng-dev &&\
docker-php-ext-configure intl &&\
docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ &&\
docker-php-ext-install -j$(nproc) gd pdo_mysql intl opcache zip pcntl exif bcmath sockets &&\
a2enmod rewrite
RUN pecl install amqp \
&& docker-php-ext-enable amqp
COPY docker/apache2.conf /etc/apache2/apache2.conf
WORKDIR /var/www/project
UPDATE!
I've printed the phpinfo() and when dispatching the message I have version 7.2.8 and when executing the terminal command I have 7.2.7. So terminal is not using the Docker instance of PHP when executing the command.
Solved this, finally. I had no idea I had to go via Docker to run this command. This worked for me:
docker exec -ti container_name sh -c "cd /var/www/project/ && php bin/console messenger:consume-messages amqp"
When using Docker, Symfony commands needs to be executed inside needed container.
The problem come from trying to execute php from the local host:
$ php bin/console messenger:consume-messages amqp
whereas the local host does not have the necessary dependencies, RabbitMQ in this case.
Instead the command should be run using the right container:
$ docker exec -ti container_name sh -c "cd /var/www/project/ && php bin/console messenger:consume-messages amqp"
container_name being the name of the container having the RabbitMQ dependencies.
You are missing package librabbitmq4 in your Docker container. Add RUN apt-get update --fix-missing && apt-get update && apt-get install php-amqp to your Dockerfile and rebuild the image.
I am working on a PHP API and I would like to disable unused php Modules inside my PHP-FPM image, such as "sqlite3, pdo ..".
I am a docker beginner and I would like to know if is there anything similar to docker-php-ext-enable if not what is the best practice for disabling unused php modules.
Finally I found the key point.
Inside docker php container, all the registered modules holds by a configuration file under the below path.
/usr/local/etc/php/conf.d/*.ini
bash into the container:
docker exec -it php_container_name bash
You can list all the enabled modules by php -m:
And cd into that folder, you can see the relating config files:
cd /usr/local/etc/php/conf.d/
ls
# output
docker-php-ext-mcrypt.ini docker-php-ext-mysqli.ini
docker-php-ext-opcache.ini opcache-recommended.ini
docker-php-ext-zip.ini
To disable some extension module, make a dir disabled, and move that .ini file inside it, for example:
mkdir disabled
mv docker-php-ext-opcache.ini disabled
mv opcache-recommended.ini
Finally, press Ctrl+D to exit the container, and then restart the container to make changes work.
docker restart php_container_name
You can get into the container and run php -m to see, the relating extension is gone.
Piggybacking off Alfred's answer but I made these today.
alias disDebugCust="docker exec -it xdebugContainer bash -c 'cd /usr/local/etc/php/conf.d/ && mkdir -p disabled && mv xdebug.ini disabled && /etc/init.d/apache2 reload'"
alias enDebugCust="docker exec -it xdebugContainer bash -c 'cd /usr/local/etc/php/conf.d/disabled && mv xdebug.ini /usr/local/etc/php/conf.d/ && /etc/init.d/apache2 reload'"
First we exec into the container.
Then we go to the config folder.
Then we make a new directory called disabled if one doesn't exist.
Then we move the ini file.
Finally we restart apache.
The second command just moves it back and restarts apache.
In my case i had to enable/disable xdebug extension. I appears that there's some 'magic' that works by (de-)suffixing extensions ini file with -disabled.
Once the suffix changes, php somehow magically loads/unloads module. You can check that by running php -m command. (maybe this behaviour is only alpine-linux related??)
I wrote additional docker-php-ext-disable-xdebug script by taking example from /usr/local/bin/docker-php-ext-enable-xdebug:
#!/bin/sh
if test -f '/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini'; then
echo 'Disabling extension xdebug'
mv '/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini' '/usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini-disabled'
else
echo 'The extension xdebug is not enabled'
fi
Yes that's possible.
Taken from https://hub.docker.com/_/php/
For example, if you want to have a PHP-FPM image with iconv, mcrypt and gd extensions, you can inherit the base image that you like, and write your own Dockerfile like this:
FROM php:7.0-fpm
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmcrypt-dev \
libpng12-dev \
&& docker-php-ext-install -j$(nproc) iconv mcrypt \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd
Remember, you must install dependencies for your extensions manually. If an extension needs custom configure arguments, you can use the docker-php-ext-configure script like this example.
I want to add Zend Guard Loader support on my php instance.
http://www.zend.com/en/products/loader/downloads#Linux
Normally, I will download the package, and then add the following settings into php.ini
[Zend Guard Loader]
zend_extension="/usr/local/webserver/php/ext/ZendGuardLoader.so"
zend_loader.enable=1
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
zend_loader.license_path="/var/developer.zl"
But, now I'm running the instance within docker.
docker run --name php_instance php:5-fpm
And I tried to get into the shell:
docker exec -it php_instance bash
But I cannot find the php.ini, how can I make it work?
Did you add a command in your Dockerfile to copy the php.ini file from local to docker container?
Similar to
FROM php:7.1-fpm
# Install system packages
RUN apt-get update && apt-get install -y \
openssl \
libssh2-1 \
libssh2-1-dev \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pecl install xdebug
# Enable php extensions
RUN docker-php-ext-install mysqli pdo_pgsql
RUN pecl install ssh2-1.1.2
# Copy custom php.ini file
ADD ./deployment/my.php.ini /usr/local/etc/php/