PHP 8 setup on Ubuntu 22.04.1 - php

I'm new to Ubuntu, having used Windows for many years, but switched to Ubuntu permanently, and while I have experience with the terminal, I'm not entirely familiar with commands in Linux. I don't have enough experience to solve the problems that eventually come my way and I don't want to install or modify something the wrong way.
Based on several "Dockerfile" files I have managed to find everything necessary to install the most used dependencies in PHP. However, some commands don't work correctly, and in some cases I get some permission errors that I can't understand.
sudo apt update \
&& sudo apt install -y gnupg gosu curl ca-certificates zip unzip git sqlite3 libcap2-bin libpng-dev \
&& sudo mkdir -p ~/.gnupg \
&& sudo chmod 600 ~/.gnupg \
&& sudo echo "disable-ipv6" >> ~/.gnupg/dirmngr.conf \
&& sudo echo "keyserver hkp://keyserver.ubuntu.com:80" >> ~/.gnupg/dirmngr.conf \
&& sudo gpg --recv-key 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c \
&& sudo gpg --export 0x14aa40ec0831756756d7f66c4f4ea0aae5267a6c > /usr/share/keyrings/ppa_ondrej_php.gpg \
&& sudo echo "deb [signed-by=/usr/share/keyrings/ppa_ondrej_php.gpg] https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy main" > /etc/apt/sources.list.d/ppa_ondrej_php.list \
&& sudo apt update \
&& sudo apt install -y php8.2-cli php8.2-dev \
php8.2-pgsql php8.2-sqlite3 php8.2-gd \
php8.2-curl \
php8.2-imap php8.2-mysql php8.2-mbstring \
php8.2-xml php8.2-zip php8.2-bcmath php8.2-soap \
php8.2-intl php8.2-readline \
php8.2-ldap \
php8.2-msgpack php8.2-igbinary php8.2-redis php8.2-swoole \
php8.2-memcached php8.2-pcov php8.2-xdebug \
&& php -r "readfile('https://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& curl -sLS https://deb.nodesource.com/setup_18.x | bash - \
&& sudo apt install -y nodejs \
&& npm install -g npm \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarn.gpg >/dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/yarn.gpg] https://dl.yarnpkg.com/debian/ stable main" > /etc/apt/sources.list.d/yarn.list \
&& curl -sS https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/pgdg.gpg >/dev/null \
&& echo "deb [signed-by=/usr/share/keyrings/pgdg.gpg] http://apt.postgresql.org/pub/repos/apt jammy-pgdg main" > /etc/apt/sources.list.d/pgdg.list \
&& sudo apt update \
&& sudo apt install -y yarn \
&& sudo apt install -y mysql-client \
&& sudo apt install -y postgresql-client-14 \
&& sudo apt -y autoremove \
&& sudo apt clean \
&& sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*;
These are the commands I'm using, but I'd like to simplify them so I can create a bash file that allows me to install everything I need at any time, on any machine.
I know it doesn't seem practical with so many tools and ways to achieve it, but my intention is to experiment and see what solution you can suggest to enrich my knowledge. I believe that with practice it is the most efficient way to learn.
Permissions errors occur when running the command sudo echo "keyserver hkp://keyserver.ubuntu.com:80" >> ~/.gnupg/dirmngr.conf, I couldn't figure this out because it is running with "sudo" and it shouldn't give me a permissions error.
I would really appreciate if the community could help me.
Thank you very much!

Try to run the sudo echo "something" >> test.txt and then you can check the owner and permissions with ls -al. Then you can see the test.txt created with your own user and don't with root.
I found this site with tips:
https://www.cyberciti.biz/faq/sudo-append-data-text-to-file-on-linux-unix-macos/
I suggest checking the second method with shell tips instead of the tee. But if you has tee in your environment, sure you can use it.
I hope it helps.

Related

oci8-2.2.0 does not connect to the database but doesn't return an error either

I'm trying to install oci8-2.2.0 on an ubuntu 18 docker with php 7.2
I'm using the following commands (php-pear and libc6 installed before those):
RUN apt-get update && \
apt-get install -y unzip libaio1 libsnl-dev && \
cd /tmp && \
wget https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-sdk-linux.x64-21.4.0.0.0dbru.zip && \
wget https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-sqlplus-linux.x64-21.4.0.0.0dbru.zip && \
wget https://download.oracle.com/otn_software/linux/instantclient/214000/instantclient-basic-linux.x64-21.4.0.0.0dbru.zip && \
mkdir -p /opt/oracle && \
cp instantclient-* /opt/oracle/ && \
cd /opt/oracle/ && \
unzip instantclient-basic-linux.x64-21.4.0.0.0dbru.zip && \
unzip instantclient-sdk-linux.x64-21.4.0.0.0dbru.zip && \
unzip instantclient-sqlplus-linux.x64-21.4.0.0.0dbru.zip && \
rm -rf /var/lib/apt/lists/* instantclient-basic-linux.x64-21.4.0.0.0dbru.zip instantclient-sdk-linux.x64-21.4.0.0.0dbru.zip instantclient-sqlplus-linux.x64-21.4.0.0.0dbru.zip && \
ln -s /opt/oracle/instantclient_21_4/libclntsh.so.21.1 /usr/lib/libclntsh.so && \
ln -s /lib64/ld-linux-x86-64.so.2 /usr/lib/ld-linux-x86-64.so.2 && \
ln -s /opt/oracle/instantclient_21_4/libnnz21.so /usr/lib/libnnz21.so && \
ln -s /opt/oracle/instantclient_21_4/libclntshcore.so /usr/lib/libclntshcore.so.21.1 && \
echo /opt/oracle/instantclient_21_4 > /etc/ld.so.conf.d/oracle-instantclient.conf
RUN echo "instantclient,/opt/oracle/instantclient_21_4" | pecl install oci8-2.2.0 && \
echo "extension=oci8.so" >> /etc/php/7.2/cli/php.ini && \
echo "extension=oci8.so" >> /etc/php/7.2/apache2/php.ini
PHP Seems to recognize the module and load it, but when I call #oci_new_connect I don't get a connection, but I don't get an error either.
Using sqlplus from the same server connects just fine, so its not that. Another installation with the adminer 4.8.1 docker (alpine & php 7.4) works fine.
I'm completely stumped. Does anyone have an idea where to look next?
Found the issue, needed to add
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/oracle/instantclient_21_4

Error reporting for php docker in browser

I am facing an issue where I am trying to run a docker container to practice php on local. When I hit the index php page in the browser after spinning up the container, it does not report error for me when there is an error. It just shows a white screen.
My docker file
FROM ubuntu:18.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
&& apt-get install -y tcl locales \
&& locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
RUN apt-get update \
&& apt-get install -y nginx curl zip unzip git software-properties-common supervisor \
&& add-apt-repository -y ppa:ondrej/php \
&& apt-get update \
&& apt-get install -y php7.4-fpm php7.4-cli php7.4-gd php7.4-mysql \
php7.4-imap php7.4-imagick php7.4-opcache php7.4-mbstring php7.4-xml php7.4-zip php7.4-intl php7.4-xmlrpc php7.4-curl \
&& php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer \
&& mkdir /run/php \
&& apt-get remove -y --purge software-properties-common \
&& apt-get -y autoremove \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& echo "daemon off;" >> /etc/nginx/nginx.conf
RUN ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
COPY default /etc/nginx/sites-available/default
COPY php-fpm.conf /etc/php/7.4/fpm/php-fpm.conf
EXPOSE 88
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
CMD ["/usr/bin/supervisord"]
Now to report the error please assist in what could be done to fix it?

build docker image with circleci/php:7.3-cli-node-browsers

I am trying to build an image in docker but after it compiles, I execute docker-compose up and it exits.
The docker file that I am using contains the next instructions:
FROM circleci/php:7.3-cli-node-browsers
USER root
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y \
libpng-dev \
zlib1g-dev \
zip \
curl \
&& docker-php-ext-install gd \
&& apt-get install -y zip \
&& apt-get install -y unzip \
&& apt-get install -y git \
&& apt install -y libsqlite3-dev zlib1g-dev \
&& docker-php-ext-install bcmath && docker-php-ext-enable bcmath \
&& docker-php-ext-install pcntl \
&& apt-get install -y --no-install-recommends libmagickwand-dev \
&& docker-php-ext-install exif \
&& pecl install imagick \
&& docker-php-ext-enable imagick
RUN pecl install redis && docker-php-ext-enable redis
COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www/html
COPY / /var/www/html
RUN composer self-update
RUN composer install -n --prefer-dist
RUN npm install
RUN npm run test
RUN chmod -R 777 /var/www/html
RUN chmod -R o+w /var/www/html/storage
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
RUN ln -s /usr/local/bin/docker-entrypoint.sh / # backwards compat
ENTRYPOINT ["docker-entrypoint.sh"]
This a laravel project, with node and Redis. Any ideas why it is not working?
Thank in advance for your help.
Your entrypoint finally call apache, but you even did not install apache in your docker image.
So, you need do next:
Install apache2 in Dockerfile:
RUN apt-get install -y apache2
Correctly launch apache2 in docker-entrypoint.sh:
echo "--> Starting app"
. /etc/apache2/envvars
mkdir -p /var/run/apache2
exec apache2 -D FOREGROUND

Docker with wkhtmltopdf is not work correctly

I am trying to use wkhtmltopdf in a container with Docker and Symfony.
The installation is done well, but the result is very different from the reality, so I think some libraries must be missing in the system, but I don't know which one.
I've been checking other questions here and in google, but they don't help.
FROM phpdockerio/php71-fpm:latest
# Fix debconf warnings upon build
ARG DEBIAN_FRONTEND=noninteractive
# Install selected extensions and other stuff
RUN apt-get update \
&& apt-get -y --no-install-recommends install cron \
php7.1-mysql \
php-redis \
php7.1-bcmath \
php7.1-gd \
php-imagick \
php7.1-intl \
cron \
python \
xz-utils \
libxrender1 \
libfontconfig1 \
zlib1g \
fontconfig \
libfreetype6 \
libx11-6 \
libxext6 \
wkhtmltopdf
RUN curl --insecure https://getcomposer.org/composer.phar -o /usr/bin/composer && chmod +x /usr/bin/composer
RUN cd /tmp \
&& curl "https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz" -L -o "wkhtmltopdf.tar.xz" \
&& tar Jxvf wkhtmltopdf.tar.xz \
&& rm wkhtmltopdf.tar.xz \
&& mv wkhtmltox/include/* /usr/local/include/ \
&& mv wkhtmltox/lib/* /usr/local/lib/ \
&& mv wkhtmltox/bin/* /usr/local/bin/ \
&& mv wkhtmltox/share/* /usr/local/share/
RUN apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
CMD php-fpm -F
This is the result in the container(docker)
And this is the result on my machine (without docker), as it should be.
Any idea what might be happening?

Building a Docker image with deprecated dependencies

I am struggling to build a Docker image with Debian Wheezy, Apache 2.2, PHP 5 with mcrypt enabled. I want to use it to do some maintenance on a quirky, legacy prestashop application.
Most semi-automatic procedures include Apache 2.4 and that will not work. I would have thought that by now there would be an online tool to auto-generate Docker images to specifications.
How should I do it? Should I use Docker compose?
This is what I have so far. I am only missing how to start mysql and apache on image run.
FROM debian:wheezy
RUN apt-get update && \
apt-get install -y libmcrypt-dev \
subversion ssl-cert nano wget unzip && \
echo "deb http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list.d/dotdeb.list && \
echo "deb-src http://packages.dotdeb.org wheezy-php56 all" >> /etc/apt/sources.list.d/dotdeb.list && \
wget http://www.dotdeb.org/dotdeb.gpg -O- | apt-key add - && \
echo mysql-server-5.5 mysql-server/root_password password yourpass | debconf-set-selections && \
echo mysql-server-5.5 mysql-server/root_password_again password yourpass | debconf-set-selections && \
apt-get update && \
apt-get install -y \
apache2 apache2-doc apache2-mpm-prefork apache2-utils apache2.2-bin apache2.2-common libapache2-mod-php5 \
openssl php-pear php5 php5-cli php5-common php5-curl php5-gd php5-mcrypt php5-mysql php5-memcache php5-readline \
subversion ssl-cert nano wget unzip \
mysql-server-5.5 mysql-client mysql-client-5.5 mysql-common && \
/etc/init.d/mysql start && \
mysql -u root -pyourpass -e "create database mydb;" && \
rm -rf /var/lib/apt/lists/* && \
rm /etc/apache2/sites-enabled/000-default && \
mkdir -p /var/www/html && \
chown www-data:www-data -R /var/www/html/
COPY conf/etc/ /etc/
COPY mydump.sql /var/www/html/mydump.sql
RUN /etc/init.d/mysql start && \
mysql -u root -pyourpass -h localhost mydb < /var/www/html/mydump.sql && \
rm /var/www/html/mydump.sql
VOLUME ["/var/www", "/var/log/apache2", "/etc/apache2", "/var/lib/mysql"]
EXPOSE 80 443 3306

Categories