Docker-compose : prevent PECL install from stopping the build process - php

So I have 2 Dockerfile to build my container. The first file is to build my "main" (production) container, the second extends the first (through From instruction) and adds some dev and testing dependencies.
Currently, my only testing dependency is Xdebug. I install it through PECL with : RUN pecl install xdebug && docker-php-ext-enable xdebug
When I rebuild my image, it seems that it doesn't rebuild everything from scratch so I get the error pecl/xdebug is already installed and is the same as the released version 2.9.8 install failed ERROR: Service 'webapi' failed to build : The command '/bin/sh -c pecl install xdebug && docker-php-ext-enable xdebug' returned a non-zero code: 1
So, ok, it fails, but I still end with Xdebug installed so my image will work just fine. But it stops the build. I don't want to.
I've seen the RUN command; exit 0 trick but, as mentionned by somebody, it will silence any real error (like "Sorry, server unreachable, can't download Xdebug") so to me it's not a viable option for production.
Also Xdebug isn't available on apt-get nor through docker-php-ext-install. I'm stuck with PECL.
Do you know any option (like some hidden param) to do something like "Install if you can, otherwise just like it roll" ?
Regards,

You can check if Xdebug is installed or not first:
bash -c '[[ -z "$(pecl list | grep xdebug)" ]] && (pecl install xdebug && docker-php-ext-enable xdebug)'
But honestly 'it doesn't rebuild everything from scratch' sounds quite weird in the first place and you probably should debug your Dockerfile.

Put this in your Dockerfile when you want to install XDebug:
RUN bash -c '[[ -n "$(pecl list | grep xdebug)" ]]\
|| (pecl install xdebug && docker-php-ext-enable xdebug)'
This will check the pecl installed packages list for 'xdebug' before attempting an install.
If grep returns anything for that, we know it's already installed and the statement evaluates to success.
If grep doesn't return anything, it'll go ahead and execute the commands to install xdebug, and fail if it's unable to install it.

Related

No output when trying to use nodejs

I installed node on my Ubuntu 14.04 machine with:
apt-get install node
However, when I run
node -v
there is no output.
I then tried apt-get install nodejs, and when I run nodejs -v I get v0.10.25.
I'm not really sure what I'm doing wrong to get node working.
My PHP script requires node.js and my check keeps failing:
if(preg_match("/^v\d+.\d+.\d+$/", `node -v`) === 0){
exit_json([
"error" => "Node isn't installed on this machine."
]);
}
How can I correctly install node.js on 14.04? I used digital ocean's tutorial.
If you are using Node.js as a developer in you developing machine I advise you to install it using NVM.
Follow the instructions than add the following to your ~/.bashrc file:
source ~/.nvm/nvm.sh
After type
$source ~/.bashrc
This will allow you to use NVM to install the versions you want:
$nvm install 10
You can install older versions and use whatever one you have installed by typing:
$nvm use 8.4.0
If you want to execute it, make sure you're specifying the full path (or make sure node is in the path.)
Also, that's a very, very old version of Node.js you've installed.
Try install like this :
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs

Laravel Dusk error: Failed to connect to localhost port 9515: Connection refused

As the title says, I've go a clean install of Laravel 5.4 and the latest Homestead (1.0.1). However, when I run a simple Dusk test case I get the following error:
Failed to connect to localhost port 9515: Connection refused
Anyone know how to deal with this? I tried changing the port to something else such as 8888 to no avail.
EDIT:
I've been able to dig a little deeper and found out that the chromedriver executable was not actually executable (chmod). Now that I've fixed that I get this error when I manually try to run it.
./chromedriver: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
For those looking for a solution on Mac, I've just had to restart Chrome. Yes, Chrome, the browser. It seems it'd a pending update (it said that in the upper right corner).
Restarting it, and later chromedriver, make everything went fine
I had this issue today and the solution is on Laracasts.
Here's a copy.
# makes sure all your repos are up to date
sudo apt-get update
# chrome dependencies I think
sudo apt-get -y install libxpm4 libxrender1 libgtk2.0-0 libnss3 libgconf-2-4
# chromium is what I had success with on Codeship, so seemed a good option
sudo apt-get install chromium-browser
# XVFB for headless applications
sudo apt-get -y install xvfb gtk2-engines-pixbuf
# fonts for the browser
sudo apt-get -y install xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable
# support for screenshot capturing
sudo apt-get -y install imagemagick x11-apps
# Once all this has run through, you need to fire up xvfb on your homestead box. If you’re planning to # do this on a regular basis, you’ll want to get this setup on boot, but for the sake of testing things out:
Xvfb -ac :0 -screen 0 1280x1024x16 &
On Ubuntu Linux 16.04, I got this to work:
Install Chromium & dependencies for headless testing
sudo apt-get -y install chromium-browser xvfb gtk2-engines-pixbuf xfonts-cyrillic xfonts-100dpi xfonts-75dpi xfonts-base xfonts-scalable imagemagick x11-apps
Create a customDuskCommand
Which extends the original, with this handle method:
public function handle()
{
$xvfb = (new ProcessBuilder())
->setTimeout(null)
->setPrefix('/usr/bin/Xvfb')
->setArguments(['-ac', ':0', '-screen', '0', '1280x1024x16'])
->getProcess();
$xvfb->start();
try {
parent::handle();
} finally {
$xvfb->stop();
}
return;
}
This will start Xvfb for headless testing before executing the tests and stop the process after testing completes.
Edit: And make sure vendor/laravel/dusk/bin/chromedriver-linux is executable.
Failed to connect to localhost port 9515 after 0 ms: Connection refused
Solution:
php artisan dusk:install
php artisan dusk:chrome-driver 65
It appears your chrome-driver installation is broken.
You can try to install it from scratch
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget -N http://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P ~/
unzip ~/chromedriver_linux64.zip -d ~/
rm ~/chromedriver_linux64.zip
sudo mv -f ~/chromedriver /usr/local/bin/chromedriver
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod 0755 /usr/local/bin/chromedriver
This should help you download the latest version of chrome driver and unpack it properly.
LATEST_VERSION=$(curl -s https://chromedriver.storage.googleapis.com/LATEST_RELEASE) && wget -O /tmp/chromedriver.zip https://chromedriver.storage.googleapis.co /$LATEST_VERSION/chromedriver_linux64.zip && sudo unzip /tmp/chromedriver.zip chromedriver -d /usr/local/bin/;
Create a customDuskCommand
namespace App\Console\Commands;
use Symfony\Component\Process\Process;
class DuskCommand extends \Laravel\Dusk\Console\DuskCommand {
public function handle() {
$xvfb = (new Process(['/usr/bin/Xvfb', '-ac', ':0', '-screen', '0', '1280x1024x16']))
->setTimeout(null);
$xvfb->start();
try {
parent::handle();
} finally {
$xvfb->stop();
}
return;
}
}
Thanks to https://stackoverflow.com/a/44322930/470749. It was outdated and didn't work, so I'm providing an updated answer that works.
UPDATE:
I personally don't follow this approach anymore. After I deployed to production, I got this error: E_ERROR: Class 'Laravel\Dusk\Console\DuskCommand' not found because I'd forgotten that my composer.json only installed Dusk in the dev environment rather than also in production. If you adhere to the principle that "test code" shouldn't be deployed to production, then this approach of writing a custom class that extends \Laravel\Dusk\Console\DuskCommand probably is not for you (since the DuskCommand dependency won't exist in production).
I will leave this answer here anyway since it's hopefully a valuable warning to people. Please comment if you think I should delete it instead. By the way, Jonas Staudenmeir tends to have great answers, so this looks interesting as an alternative.
With the latest laravel/homestead box v.6.0.0 it's working out of the box
https://app.vagrantup.com/laravel/boxes/homestead

Problems adding cURL to OAuth request engine support

I've recently been setting up a new environment for a web application I'm working on and I've run into this following issue that I cannot figure out.
Currently I have a docker-composer setup based off of https://hub.docker.com/r/ruslangetmansky/docker-apache-php/
Where I have my API, APP and DB running and need them to talk between each other.
During the initialisation of this, I'm currently doing the following command:
command: bash -c 'apt-get update && apt-get -y install curl libcurl3 libcurl3-dev php5-curl php5-oauth && rm -rf /var/lib/apt/lists/* && composer install && /sbin/entrypoint.sh'
I've even tried separating out the php5-oauth in-case we're running into a timing issue like so, but the same issue persists:
command: bash -c 'apt-get update && apt-get -y install curl libcurl3 libcurl3-dev php5-curl && apt-get -y install php5-oauth && rm -rf /var/lib/apt/lists/* && composer install && /sbin/entrypoint.sh'
As you can see, I've been trying everything to get php5-oauth built with cURL support, however at the moment the current build ends up with only php_streams request engine support:
However it looks like cURL support is also built in:
So currently when I boot my app+api, I can't talk between them due to no cURL support, as I've errors all over my application complaining of undefined constants such as the two following:
Message: Use of undefined constant OAUTH_REQENGINE_CURL - assumed 'OAUTH_REQENGINE_CURL'
and
Message: OAuth::setRequestEngine() expects parameter 1 to be long, string given
due to the lack of cURL support.
I also spotted similar questions around Stack Overflow, but nothing seems to mention what to do when these are installed and enabled but only 1 request engine is available.
Other research has led me to http://www.davidogilo.co.uk/technical/how-to-fix-oauth_reqengine_curl-is-undefined/ but my cURL default path has always been found succesfully.
Can anyone give me a hand here, or at least point out where i'm possibly going wrong? Cheers.
Reinstall oauth with sudo pecl install oauth to compile it with cURL support

Upgrading PHP in XAMPP for linux?

How can I upgrade my current php (only) in xampp?
I need to upgrade from 5.3.1 to 5.4.0
Download PHP's source code and extract it in /usr/src:
cd ~/downloads
wget http://snaps.php.net/php5.4-latest.tar.gz
tar -xzf php5.4-latest.tar.gz
sudo mv php5.4 /usr/src/php-5.4
You need to find the configuration of already installed version , so you can use it and install the new version with the exact same configuration
/opt/lampp/bin/php --info | grep "Configure Command"
You should see something like this as result :
./configure '--prefix=/opt/lampp' '--with-apxs2=/opt/lampp/bin/apxs' '--with-config-file-path=/opt/lampp/etc' '--with-mysql=mysqlnd' '--enable-inline-optimization' '--disable-debug'
Actually, list should probably be much more longer. Copy and store it as you will need to use it as a whole later.
Make a backup of the current installation, in case if anything goes wrong
sudo cp -r /opt/lampp /opt/lampp.bak
Now that you have configuration options, review it and then use it to compile the new version.
cd /usr/src/php-5.4/
./configure --prefix=/opt/lampp --with-apxs2=/opt/lampp/bin/apxs --with-config-file-path=/opt/lampp/etc --with-mysql=mysqlnd --enable-inline-optimization --disable-debug
make
make install
Run /opt/lampp/bin/php -v in order to make sure you have correct php version installed. It should be 5.4.0 Beta.
Just want to complement #altern answer....
When I tried all the indications exactly in line of
make install
I had an error in the output
Installing PHP SAPI module: apache2handler
/opt/lampp/build/instdso.sh SH_LIBTOOL='/opt/lampp/build/libtool' libphp7.la /opt/lampp/modules
/opt/lampp/build/libtool --mode=install install libphp7.la /opt/lampp/modules/
/opt/lampp/build/libtool: 3215: /opt/lampp/build/libtool: install_prog+=install: not found
/opt/lampp/build/libtool: 3235: /opt/lampp/build/libtool: files+= libphp5.la: not found
libtool: install: you must specify an install program
libtool: install: Try `libtool --help --mode=install' for more information.
apxs:Error: Command failed with rc=65536
After looking for information to solve, I found a japanese link:
http://d.hatena.ne.jp/Kenji_s/touch/searchdiary?word=*%5BUbuntu%5D
What I did to solve it after trying to understand this japanese solution was simply:
sudo nano /opt/lampp/build/libtool
And when the editor was opened I changed the first line, instead of:
#! /bin/sh
I wrote:
#! /bin/bash
After that I tried again
make install
And voila it compiled!
Hope It helps someone
Now XAMPP is supporting PHP 5.4 and PHP 5.5. You can now download installer of your required version of PHP from http://www.apachefriends.org/en/xampp-linux.html
Thanks.

Any docs about V8JS in PHP?

Is there any documentation about V8JS?
Do I need only standard PHP or some extensions to use V8JS?
I'll be very thankful for any information about V8JS in PHP.
Requirements
PHP 5.3.3+ and V8 library and headers installed in proper paths.
Install
I've found this docs on the v8js class.
The docs out there aren't complete or are not updated. I'm actually currently in the process of doing v8JS myself and it took me a few days to get the back end libs sorted out. First off, you must know that you can't do this is you have python < 2.7
Here is my install notes that I'm putting together for our dev vagrant boxes running centos 7.
cd /tmp
# Install depot_tools first (needed for source checkout)
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH=`pwd`/depot_tools:"$PATH"
# Download v8
fetch v8
cd v8
# Build (disable snapshots for V8 > 4.4.9.1)
make native library=shared snapshot=off -j8
# Install to /usr
sudo mkdir -p /usr/lib /usr/include
sudo cp out/native/lib.target/lib*.so /usr/lib64/
sudo cp -R include/* /usr/include
echo -e "create /usr/lib64/libv8_libplatform.a\naddlib out/native/obj.target/tools/gyp/libv8_libplatform.a\nsave\nend" | sudo ar -M
cd /usr/lib64
sudo chrpath -r '$ORIGIN' libv8.so
========================
Compile php-v8js itself
========================
cd /tmp
git clone -b master https://github.com/phpv8/v8js.git
cd v8js
phpize
./configure
make
make test
sudo make install
sudo service httpd restart
A note on the line make native library=shared snapshot=off -j8. I had the compile stop on me a couple times, I just restarted it. I'm not sure why it stopped, but it restarted just fine and completed just fine.
After that is done, you need to create the php extension file /etc/php.d/v8js.ini with the following content
; Enable v8js extension module
extension=v8js.so
Run the following to make sure it is installed correctly
php -r "phpinfo();" | grep v8js
If you get output back and no errors you're good to go.

Categories