How to call this below script? - php

I have cloned a project from repo in projects directory, where I have got a few files as below. I am confused how it would be called or do i need to call it explicitly ? and this file is not containing any extension LIKE PHP OR SH, and project is in php using Vagrant AND VIRTUAL BOX, I am also not much familiar with VAGRANT.
#!/usr/bin/env bash
export DEBIAN_FRONTEND=noninteractive
installpkg(){
dpkg-query --status $1 >/dev/null || apt-get install -y $1
}
apt-get update
installpkg php5
installpkg php5-mysql
installpkg redis-server
installpkg mysql-server
installpkg apache2-utils
installpkg apache2-suexec-custom
Any help will be appreciated.

I believe this is a shell provisioning script that vagrant can execute when booting up the VM. you can add the following to your Vagrantfile so it is executed automatically
Vagrant.configure("2") do |config|
config.vm.provision "shell", path: "<path to your file>"
end

Related

Docker File Environment variable issue in PHP

I am using docker file for PHP Apache. I declare some environments variable in docker file but when I run the docker its only get Apache environment variable while my environment variable is not working.
here is my docker file.
# Install dependencies
From ubuntu:16.04
RUN apt-get update -y
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
vim apache2 php7.0 php7.0-mysql php7.0-gd php7.0-mbstring libapache2-mod-php7.0 curl lynx-cur
RUN service apache2 stop
# Install app
RUN rm -rf /var/www/html/*
ADD . /var/www/html
# Configure apache
RUN a2enmod php7.0
RUN a2enmod rewrite
RUN chown -R www-data:www-data /var/www/html/backend/runtime /var/www/html/backend/web/assets /var/www/html/uploads
RUN sed -i '/<Directory \/var\/www\/>/,/<\/Directory>/ s/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pidd
ENV test myenv_variable_value
EXPOSE 80
RUN service apache2 start
CMD ["apache2", "-D", "FOREGROUND"]
While I can easily print APACHE_PID_FILE but when I tried test its not working.
here is my PHP method
<?php
getenv('APACHE_PID_FILE');
$_ENV['test']
getenv('test');
?>
These both method are not working in case of test env.
Thanks
The problem is Apache doesn't expose environment variables which apache was launched with. You need to expose these environment variable using your config. Apache has a PassEnv directive that you need to use
https://httpd.apache.org/docs/current/mod/mod_env.html
PassEnv test
This will pass the environment test to your page. You need it for do it for every environment you want to expose.

/usr/bin/env: �php\r’: No such file or directory

I have a problem during Propel ORM configuration.
I prepared environment on my Vagrant with PHP 7.1 following this provision file:
# Install software
add-apt-repository ppa:ondrej/php
apt update
apt install python-software-properties
apt update
apt install -y apache2
apt install -y php
apt install -y php-mcrypt
apt install -y php-mysql
apt install -y php-curl
apt install -y php-cli
apt install -y php-xml
apt install -y libapache2-mod-php
apt install -y mc
# install composer, configure Apache and create database
service apache2 restart
/etc/init.d/mysql restart
Currently I want to install Propel ORM. I added Propel to composer, installed, and now I type (by SSH in Vagrant)
/var/www/application/Vendors/bin/propel init but unfortunately I get error:
/usr/bin/env: �php\r’: No such file or directory
What can I do to resolve it?
EDIT:
File that I run (not edited, installed via Composer):
#!/usr/bin/env sh
dir=$(d=${0%[/\\]*}; cd "$d"; cd "../propel/propel/bin" && pwd)
# See if we are running in Cygwin by checking for cygpath program
if command -v 'cygpath' >/dev/null 2>&1; then
# Cygwin paths start with /cygdrive/ which will break windows PHP,
# so we need to translate the dir path to windows format. However
# we could be using cygwin PHP which does not require this, so we
# test if the path to PHP starts with /cygdrive/ rather than /usr/bin
if [[ $(which php) == /cygdrive/* ]]; then
dir=$(cygpath -m "$dir");
fi
fi
dir=$(echo $dir | sed 's/ /\ /g')
"${dir}/propel" "$#"
I don't use propel but had the same problem with phpunit.
The problem is often that the vendor/propel/propel/bin/propel, or in my case the vendor/phpunit/phpunit/phpunit file you try to execute is Windows encoded and not Unix encoded. It happens when you do composer install/update on Windows but run your code in a vagrant box.
You have multiple ways of getting rid of the CRLF:
dos2unix command (sudo apt-get install dos2unix)
use your prefered text editor (Sublime, PHPStorm, they can both do that)
get rid of vendor and run composer install/update from your vagrant box
Remember that the problem is not the vendor/bin/propel file but the vendor/propel/propel/bin/propel file.
Hope this help!

Docker and symfony

I'm struggling with Docker.
I'm tring to create an image to work on symfony project and to learn Docker in the same time.
Here is my Dockerfile:
FROM php:7-apache
LABEL Description = "This image is used to start Symfony3 project"
ENV DIRPATH /var/www/html
# apt-get command
RUN apt-get update && apt-get install -y \
vim \
git \
&& apt-get clean
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Install the Symfony Installer
RUN curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
RUN chmod a+x /usr/local/bin/symfony
I build the image with the command:
docker build -t symfony .
Works well! Cool!
I'm create a container with:
docker run --name symfony -d -v "$PWD":/var/www/html -p 80:80 symfony
Works well also. The web server is running on the good port.
I can go in my container with:
docker exec -ti symfony bash
But when I'm trying to do a composer update, I have some errors:
Failed to download symfony/symfony from dist: Could not decompress the archive, enable the PHP zip extension.
A php.ini file does not exist. You will have to create one.
How can I create the php.ini in Dockerfile?
I also think that I have an issue with permission.
When I'm trying to the web/app_dev.php I have this message:
You are not allowed to access this file. Check app_dev.php for more information.
You can ADD a custom php.ini configuration specifing it in the dockerfile,
As Example, you can take a look at this repo for this example:
dokerfile
# install a few more PHP extensions
RUN apt-get update && apt-get install -y php5-imagick php5-gd php5-mongo php5-curl php5-mcrypt php5-intl
# copy a custom config file from the directory where this Dockerfile resides to the image
COPY php.ini /etc/php5/fpm/php.ini
You can find various approach and various sample on the net.
Hope this help
Next to the missing php.ini file you should also install zip so you can download from dist, i.e.
RUN docker-php-ext-install zip
Which will install and enable the PHP zip extension which is requested in your error message.

Travis CI with Apache & PHP

How to configure travis-ci to use phpenv's php version in Apache?
phpenv's README states that ~/.phpenv/lib/libphp5.so is set whenever "phpenv global" is called, however when I try to configure apache to use this as its apxs library I get this:
Travis outputs:
/home/travis/build/OpenBuildings/Clippings/.phpenv/lib/libphp5.so: cannot open shared object file: No such file or directory
I don't think using "apt-get install libapache2-mod-php5" is the right call as I would rather use the specifically set php version from travis' config.
My config so far is:
before_script:
- sudo apt-get update
- sudo apt-get install -y --force-yes apache2
- echo "extension=memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
- printf "\n" | pecl install imagick
- echo "LoadModule php5_module $(pwd)/.phpenv/lib/libphp5.so" | sudo tee /etc/apache2/mods-available/php5.load
- sudo cp build/travis/etc/apache2/clippings /etc/apache2/sites-available/clippings
- sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/clippings
- sudo a2ensite clippings
- sudo a2enmod rewrite
- sudo a2enmod php5
- sudo service apache2 restart
Apparently there are 2 "phpenv" libraries, and travis is using the other one.
So after a bit of digging I managed to configure appache successfully with php-fpm (which is supported by travis)
I've made a pull rquest for travis-ci docs to reflect my findings, and it's already merged to master: http://about.travis-ci.org/docs/user/languages/php/

Cannot install LAMP server in UBUNTU

I am new using Ubuntu. Basically I want to set the LAMP package in order to test PHP locally. So I installed tasksel then I executed in the terminal.
sudo tasksel
Which promps a list of servers I can install. I move the cursor to LAMP Server option, hits enter and returns to the command line. Like if I had pressed EXIT.
What am I missing? Can someone experienced help me install LAMP even if it is on another way? I have Ubuntu 13, by the way. I have been struggling with this for a while now.
You can try with.
sudo tasksel install lamp-server
https://help.ubuntu.com/community/ApacheMySQLPHP
To install apache, open terminal and type in these commands:
sudo apt-get update
sudo apt-get install apache2
to test if apache is working use this simple script:
ifconfig eth0 | grep inet | awk '{ print $2 }'
and browse to : http://<you'r ip address>
to install mysql open the terminal and write this:
sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
Once you have installed MySQL, we should activate it with this command:
sudo mysql_install_db
Finish up by running the MySQL set up script:
sudo /usr/bin/mysql_secure_installation
The prompt will ask you for your current root password.
Type it in.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Now, its time to install PHP:
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt
That's it! restart apache to apply the changes:
sudo service apache2 restart
Hope it helps.
Change user to root
sudo su root
update the repository
sudo apt-get update
install LAMP packages by,
apt-get install apache2 php5 libapache2-mod-php5 mysql-server mysql-client php5-mysql
This three simple step is enough to install LAMP.
Courtasy: iGyan: Install LAMP with PHPmyadmin in linux
You can easily install LAMP stack in Ubuntu with one command lines:
apache2 mysql-server mysql-client libapache2-mod-auth-mysql php5 php5-mysql libapache2-mod-php5 php5-mcrypt php5-curl php5-cli php5-gd phpmyadmin apache2-utils

Categories