Trying to update phalcon to 3.0 on Debian 8 v-server - php

First of all: I only know some basics on linux, but I wanted to try out Phalcon. So I've rented a small v-server with Debian 8 and installed php7.
At the time phalcon was at version 2.1.0r and I followed the tutorials until it seemed to work. Then I've had no time to really start working on it anymore (just created the first to 2 controllers from the tutorial).
Now I do have an idea for a test project and a little time, but I've seen that Phalcon 3.0 is out.
So I went into my cphalcon folder and got the 3.0 branch via git.
With git status I get Your branch is up-to-date with 'origin/3.0.x'.
Then I switched to the "build" folder and ran sudo ./install.
The process ran through without any errors and both /usr/include/php/20151012/ext/phalcon/php_phalcon.h and /usr/lib/php/20151012/phalcon.so are shown as recently updated within their respective folders.
In /etc/php/7.0/fpm/conf.d I do have a link called 30-phalcon.ini that points to /etc/php/7.0/mods-available/phalcon.ini containing only the line extension=phalcon.so
Then I've restarted the server via /etc/init.d/nginx restart.
When I run phpinfo(), it does still show phalcon version 2.1.0r though.
I'll try to get a linux training, but I'd love to try starting on Phalcon until then
The solution:
First, I recompiled via zephir, then I restarted php.
$ cd cphalcon/
$ zephir fullclean
$ zephir compile
$ cd build/
$ sudo ./install
$ /etc/init.d/nginx restart
$ /etc/init.d/php7.0-fpm restart
I don't know if I needed to do all this, but it worked and I'm happy. Thank you all.

For dev branches, e.g 3.0.x always use Zephir:
# PHP 5
$ zephir fullclean
$ zephir build
# PHP 7
$ zephir fullclean
$ zephir build --backend=ZendEngine3

Service php7-fpm restart ? Nginx is not php handler, it's fpm which handles php.

Related

How to change PHP version used by composer

I want to use another php version on my machine than the one already installed using WAMP (2 PHP version installed).
The composer installed uses PHP 5.6
A new project requires PHP7.0.
Whenever I choose PHP 7 from the control panel of WAMP and then run php -v it still printing PHP5.6 (CLI)... instead of PHP7.
How can I use PHP7 without reinstalling the composer again?
You can change php version of composer without uninstalling it, follow these steps :
Search for system environment variables in cortana.
Click on the button "Environment variables".
Under "System variables" select path and click on edit, you will see one entry like this "C:\wamp\bin\php\php5.6.13".
Just change this to the folder name of the php located at your wamp/bin/php7.1.9, here php7.1.9 is folder name.
Replace php5.6.13 with bin7.1.9, it will look like these "C:\wamp\bin\php\php7.1.9", just click ok on all the boxes.
You are done.
To verify, first close all the cmd windows, than open cmd and type php -v, press enter and you should see php7.1.9.
If you don't see change in php version than just restart your pc and run php -v again in cmd , it will work.
I'm assuming Windows if you're using WAMP. Composer likely is just using the PHP set in your path: How to access PHP with the Command Line on Windows?
You should be able to change the path to PHP using the same instructions.
Otherwise, composer is just a PHAR file, you can download the PHAR and execute it using any PHP:
C:\full\path\to\php.exe C:\full\path\to\composer.phar install
If anyone is still having trouble, remember you can run composer with any php version that you have installed e.g. $ php7.3 -f /usr/local/bin/composer update
Use which composer command to help locate the composer executable.
I found a very easy way to switch php versions:
Search for system environment variable
Click on "Environment variables"
Under "System variables" select path and click on edit
Move the PHP version folder you want to use before the other one.
So for example: php 7.0 will now be used:
Close all windows by clicking "OK"
Close all the cmd windows, than open cmd and type php -v
You will see the correct php version loaded now:
Another possibility to make composer think you're using the correct version of PHP is to add to the config section of a composer.json file a platform option, like this:
"config": {
"platform": {
"php": "<ver>"
}
},
Where <ver> is the PHP version of your choice.
Snippet from the docs:
Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config. Example: {"php": "7.0.3", "ext-something": "4.0.3"}.
This is what happens in my case. I hope this may help to someone have same situation. I'm using macOS Monterey with MAMP.
I linked the php 7.4 using ~/.profile file. So the terminal it says I'm using php 7.4. However, still my composer giving an error saying i'm using php 7.3.
So I check the php path using
which php
This gives me the /usr/local/bin/php as my php cli location. So I remove the file and made a symlink to my php7.4 and now working perfectly.
sudo rm -rf /usr/local/bin/php
sudo ln -s /Applications/MAMP/bin/php/php7.4.21/bin/php /usr/local/bin/php
I found out that composer runs with the php-version /usr/bin/env finds first in $PATH, which is 7.1.33 in my case on MacOs.
So shifting mamp's php to the beginning helped me here.
PHPVER=$(/usr/libexec/PlistBuddy -c "print phpVersion" ~/Library/Preferences/de.appsolute.mamppro.plist)
export PATH=/Applications/MAMP/bin/php/php${PHPVER}/bin:$PATH
Old question I know, but just to add some additional information:
WAMP is used only on Microsoft Windows Operating Systems.
Changing the version of PHP used through the left-click -> PHP -> Version menu changes the version used by Apache to server your site.
Changing the version of PHP used through the right-click -> Tools -> Change PHP CLI Version menu changes the version used by WAMP's PHP CLI.
Note: It is important to understand that the "PHP CLI Version" is used by WAMP's own internal PHP scripts. This "PHP CLI Version" has nothing to do with the version you wish to use for your scripts, Composer or anything else.
For your scripts to work with the version you require, you need to add it's path to the Users Environmental Path. You could add it to the Systems environmental Path but the Users Path is the recommended option.
From WAMP v3.1.2, it would display an error when it detect reference to a PHP path in the System or User Environmental Path. This was to stop confusion such as you were experiencing. Since v3.1.7 the display of this error can now be optionally displayed through a selection in the WampSettings menu.
As indicated in previous answers, adding an installed PHP path (such as "C:\wamp64\bin\php\php7.2.30") to the Users Environmental Path is the correct approach. PS: As the value of the Users Environmental Path is a string, all paths added must be separated with a semi-colon (;)
After experiencing the exact same problem (IE: Choosing which version of PHP I wanted Composer to use), I created a script which could easily and rapidly switch between PHP CLI Versions depending on what project I was working on.
The Windows batch script "WampServer-PHP-CLI-Version-Changer" can be found at https://github.com/custom-dev-tools/WampServer-PHP-CLI-Version-Changer
I hope this helps others.
Good luck.
After a long search on the internet and finding many unrelated answers / ones that did not work for me, Here is what worked for me.
Those who are in shared hosting know that bin directory is write-protected and running sudo commands or any system-wide command is not allowed.
There's two ways of solving this:
Run the command directly on your project folder selecting the appropriate PHP version you need.
ea-php80 /opt/cpanel/composer/bin/composer update
To get available PHP on your server type ea-php and hit TAB to see a list.
make an alias to composer
Run this command to edit/make this file nano ~/.bashrc
Inside that file, put alias composer="ea-php80 /opt/cpanel/composer/bin/composer"
This gives you the flexibility to run composer commands as usual without those long trailing strings
If you are using Windows, all you have to do is change the path to php.exe in the composer.bat file located in: "C:\ProgramData\ComposerSetup\bin".
In my case I include paths to all php versions, whenever I need to run a project on a specific php version, I just move the required path to the top (using these buttons in the right) and then close all the terminals and restart my wampp server.
The path with listing in the will be selected as your php version by windows
This is the simplest solution I think.
If you still facing the problem after changing Environment variables in windows, try to delete directory or just rename directory of your old php.
I've done it and it's work.
I will assume that you need this because a requirement to have multiple php versions installed to handle multiple projects.
If this is the case a prefer to run directly the php desired bin pointing to the executable script of composer, for example, in my case I have php 8.1 and 7.4, my main php version configured for CLI is 8.1, but I want to run composer with 7.4 in some projects, so I run this command:
php7.4 -f /usr/local/bin/composer install
Where php7.4 is the bin installed and my global composer script is in /usr/local/bin/composer
From there, you can make an alias like this to facilitate things: alias composer7.4='php7.4 -f /usr/local/bin/composer ' so next time you need to run composer with php#7.4 you only need to run: composer7.4 install
Came here by the title, but the question specifies WAMP; which this may not easily apply to. So, in my case - using a Mac.. so more like a MAMP - if you have brew and the below versions installed, this could help - and composer picks it up.
brew link --overwrite --force php#8.1
php -v
#PHP 8.1...
brew link --overwrite --force php#7.4
php -v
#PHP 7.4...

How to run composer on MAMP 's php version?

I can't run composer install because my php's version on my OS is not enough updated (5.5.36). So i tried to install composer globally with my MAMP's php(5.6.10)
1) I create alias for my MAMP's php
nano ~/.bash_profile
alias phpmamp='/Applications/MAMP/bin/php/php5.6.10/bin/php'
2) Run this line to install composer
curl -sS https://getcomposer.org/installer | phpmamp
3) Run this line to move composer
sudo mv composer.phar /usr/local/bin/composer
Composer is installed (run composer on terminal works)
This is a the tutorial.
But when i want to run composer install, composer uses my OS php.
Any idea ?
Those lines worked for me. I override the OS PHP path to my MAMP PHP path.
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
$ export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
$ source ~/.bash_profile
You can check the version by running :
$ which php
The complete solution
Thanks to #Andrew Patton
This is an old question, but it came up in web search for a similar issue I was having, and the latest version of MAMP Pro (mine is 6.6.2) has a GUI solution:
In Languages > PHP, under 'Default version', you should see a checkbox for "Also activate shortcut for Composer".
What this did for me is add an alias of composer=/Applications/MAMP/bin/php/composer (in my zshell ~/.profile file on macOS Monterey). Maybe yours works similarly.
Of course, when switching PHP versions, it wouldn't also switch composer versions (which is necessary when switching between PHP 5 and 7.2.5+), so I have to use the OS install for one version and MAMP's for another. A little tricky, but if you don't have this problem, then the alias will be fine.

How to run bundle from PHP script

I'm writing a webhook to automatically publish a site when I push to GitHub. Part of the process requires that I build the site with
bundle exec middleman build --clean
I'm trying to invoke that with a PHP script, the script called by the GitHub webhook, so the user is www-data. No matter what I try, however, I'm getting an error that bundle cannot be found.
How can I run a bundle command from a PHP script?
I was able to figure this out. First, I installed rvm as a multi-user installation to ensure the www-data account can access it.
$ curl -sSL https://get.rvm.io | sudo bash -s stable
Install the desired ruby version, in my case 2.3.1, then set rvm to use it:
$ rvm install 2.3.1
$ rvm use 2.3.1
Run gem to install any gems that are needed. Because rvm is a multi-user installation, these gems are stored to the system and not your specific user.
$ gem install packagename
I don't know if this is necessary, but I would close the SSH session and reopen it. rvm messes with environment variables, so better safe than sorry.
Run env to print all environment variables. printenv also works if env doesn't for some reason. You'll get a big list of everything set, you only need the ruby-related ones. Do not copy/paste these values, they are examples I pulled from my system. Yours will be different!
PATH=/usr/local/rvm/gems/ruby-2.3.1/bin:/usr/local/rvm/gems/ruby-2.3.1#global/bin:/usr/local/rvm/rubies/ruby-2.3.1/bin:/usr/local/rvm/bin:/home/steven/bin:/home/steven/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
rvm_bin_path=/usr/local/rvm/bin
GEM_HOME=/usr/local/rvm/gems/ruby-2.3.1
IRBRC=/usr/local/rvm/rubies/ruby-2.3.1/.irbrc
MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-2.3.1
rvm_path=/usr/local/rvm
rvm_prefix=/usr/local
rvm_ruby_string=ruby-2.3.1
GEM_PATH=/usr/local/rvm/gems/ruby-2.3.1:/usr/local/rvm/gems/ruby-2.3.1#global
RUBY_VERSION=ruby-2.3.1
Now we need PHP to recognize these variables. You'll need to find the right file on your system, which can be tricky. I don't have a way of knowing which one is correct, I used trial and error.
The file on my system is /etc/php/5.6/fpm/pool.d/www.conf. Add all of the environment variables you previously grabbed into this file with the below format. Note that you DO need PATH in here as well!
env[rvm_path] = /usr/local/rvm
env[rvm_prefix] = /usr/local
Now restart php-fpm. Your service name may be different from mine; I'm using the 5.6 build from ondrej/php.
Ubuntu 15.04 and newer (systemd):
$ sudo systemctl restart php5.6-fpm
Ubuntu 14.10 and newer:
$ sudo service php5.6-fpm restart
Finally, in the script itself you'll need to cd to the directory you're running the bundle command from. My short script is this:
cd /opt/slate
/usr/bin/git reset --hard
/usr/bin/git pull
bundle exec middleman build --clean
cp -R /opt/slate/build/* /var/www/docs
Works for me!

Installing pecl,pear and xde on mamp

I am trying to install pecl,pearl and xdebug on mamp 2.1.2. I have tried almost everything but even when xdebug appear in phpinfo it doesn't seem to work. I tried it for netbeans too but nothing. I am a new to mac and really frustrated on how to run it and make a local project of mine debug using breakpoints. can someone help me figure it out on how to make pecl,pear and xdebug on my OSX so i can debug my project.
Check this link :
http://www.lullabot.com/articles/installing-php-pear-and-pecl-extensions-on-mamp-mac-os-x-107-lion
Edit
MAMP doesn’t ship with a bunch of the PHP sources
Download MAMP components and configure
URL: http://www.mamp.info/en/downloads/index.html (i.e. MAMP_components_2.0.2.zip)
Unpack your MAMP_components_2.0.2.zip
Identify your php-5.x.x.tar.gz file (where 5.x.x is your version of PHP)
Create directory for your PHP sources: "mkdir -vp /Applications/MAMP/bin/php5/include"
Untar php-5.x.x.tar.gz into /Applications/MAMP/bin/php/php5.*/include or /Applications/MAMP/bin/php5/ include e.g. tar zxvf php-5.x.x.tar.gz -C /Applications/MAMP/bin/php/php5.?.??/include
Rename your php-5.x.x directory to php (without the version numbering) e.g. mv /Applications/MAMP/bin/php/php5.2.17/include/php-5.?.?? /Applications/ MAMP/bin/php/php5.2.17/include/php
Configure PHP sources (it’ll create necessary files i.e. zend_config.h, tsrm_config.h, etc.)
cd /Applications/MAMP/bin/php/php5.?.??/include/php ./configure
The process was for another fix but this resolved the issues with php.h not being found

How do I install Pdftk on my server?

I am using a Linux Server and am trying to install Pdftk, but I am problems trying to figure out what exactly to do.
I found the following documentation on how to install it, but they refer mostly to installing it on the local Windows machine.
They are:
http://www.andrewheiss.com/blog/2009/07/29/installing-pdftk-php/
http://www.accesspdf.com/pdftk/#packages
Can someone help me unserstand exactly what files I need to place where on my server so I can refer to pdftk?
Pdftk is a version of iText which has been converted from Java to c++ and rebuilt with a command-line bridge for easy access from PHP applications.
To build pdftk on Redhat / CentOS please follow the below instructions.
ssh [server to install pdftk on]
Now that we are in the server we need to create the directories to store pdftk.
cd /
sudo mkdir extra
cd extra
sudo mkdir src
cd src
sudo wget http://www.pdfhacks.com/pdftk/pdftk-1.41.tar.gz
sudo tar zxvf pdftk-1.41.tar.gz
cd pdftk-1.41/pdftk
Now we need to install the gcj libraries.
sudo yum install java-1.4.2-gcj-compat-devel.i386
The gcc-c++ library doesn't get installed with the gcj package so we will install it now, so we don't get an error halfway through the compile process.
sudo yum install gcc-c++
If you compile the application right now you will receive a warning that tmpnam is dangerous to use and you should use mkstemp.
sudo vi report.cc
Run this from inside VI to do a search and replace for the tmpnam method.
:%s/tmpnam(/mkstemp(/g
Press escape and save the changes with
:wq!
Now that we have all the packages installed, we are going to start compiling pdftk-1.41
from /extra/src/pdftk-1.41/pdftk run the following command
sudo make -f Makefile.RedHat
This will kick off the build process for compiling and converting the java file to c++. This could take SEVERAL minutes to convert iText to c++. Go grab yourself a margarita from our new margarita machine in the break room :).
Now with the pdftk file created we will want to copy it to the /bin directory so that we can run it from anywhere.
sudo cp pdftk /usr/local/bin
Let's make sure the build was successful and run
pdftk --version
As of 2020, things are different now. CentOS 6 is stepping out and pdftk can only support CentOS 5/6. GCJ on CentOS 7 is removed, so installing from source is not easy too. But we have docker now:
FROM centos:centos6
RUN yum install -y https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/pdftk-2.02-1.el6.x86_64.rpm
Then build with docker build . -t pdftk and run as:
docker run -it --rm -v $PWD:/data --workdir /data pdftk pdftk ./input.pdf output ./output.pdf
The example above can repair a pdf file missing a dozen of KB of data if you are lucky.
As mentioned by #rsc, pdftk-java will be available for Rocky Linux, but currently (2021.10.28), still cannot install it via yum.
Fortunately, there is a built command for x86_64 GNU/Linux systems, which does not require any runtime dependencies. So we can use it as follows
# the version number might be updated, check https://gitlab.com/pdftk-java/pdftk
wget https://gitlab.com/pdftk-java/pdftk/-/jobs/1527259632/artifacts/raw/build/native-image/pdftk
chmod +x pdftk
./pdftk ...
It works well in the server with the following system info,
$ lsb_release -a
LSB Version: :core-4.1-amd64:core-4.1-noarch
Distributor ID: Rocky
Description: Rocky Linux release 8.4 (Green Obsidian)
Release: 8.4
Codename: GreenObsidian
As of 2021, there is pdftk-java: A port of the original GCJ-based PDFtk to Java, which is currently on the way to the repositories for Fedora 33+ and EPEL 7+ (latter for CentOS, RHEL or Rocky), allowing yum install pdftk-java to succeed (once the package reached the stable repositories).
Edit: The pdftk-java package is in the stable repositories since yesterday, 2021-10-29.

Categories