How to upgrade to PHP 7.0 on macOS Sierra? - php

I tried to update my PHP version on my mac but I am facing some issues
When i use cURL it freezes and it will never complete the download on the terminal:
This is the cURL command that I am running is: curl -s https://php-osx.liip.ch/install.sh | bash -s 7.2
I tried to download a package manually but I can't extract it or even know how to install it.

You can use home-brew for installation / https://medium.com/#romaninsh/install-php-7-2-on-macos-high-sierra-with-homebrew-bdc4d1b04ea6 , I find it quite better then managing with Mac OS build in PHP

I don't have enough details so I will go in blind guess here.
First judging by screenshot it is stuck on downloading. For how long it was frozen? Maybe you didn't wait enough.
When you downloading the source what you need to do is:
Assuming you downloaded package with name php-7.2.6.tar.gz from PHP Official website.
Execute command tar xzf php-7.2.6.tar.gz from command line. (assuming you are in the same directory as file). It will unpack it in directory called php-7.2.6.
Enter the directory with command cd php-7.2.6.
Enter in terminal ./configure. It will take a while, so make sure to get some coffee.
After ./configure finished, execute command make. This will take a while as well, so you might get a sandwich.
Once command finished executing the last step will be executing command make install. It will be quicker than others, don't worry. After that you will be able to execute php command.
Optional Run make test to make sure everything is fine.
PHP has been installed, HOORAY!
Hope that helped, have a nice day. And if I answered your question, please mark it 'Answered`.

Related

Setting up PHPunit - PHP CLI is not executing the shell script

I'm in a multi developer program. The other developer installed PHPUnit via composer and successfully is running tests. I took the composer files, ran composer update, but when I try to run the tests, I am receiving this error:
C:\Repos\Project\TDD>php vendor/bin/phpunit
Output:
dir=$(cd "${0%[/\\]*}" > /dev/null; cd "../phpunit/phpunit" && pwd)
if [ -d /proc/cygdrive ]; then
case $(which php) in
$(readlink -n /proc/cygdrive)/*)
# We are in Cygwin using Windows php, so the path must be translated
dir=$(cygpath -m "$dir");
;;
esac
fi
"${dir}/phpunit" "$#"
This is the content of the phpunit shell script. The shebang first line #!/usr/bin/env sh is not being output, but this is the rest of the file. The problem appears to be that the PHP CLI is not executing the script, just reading it. I can't figure out how to fix that.
I am on a windows environment, and I am not running apache locally.
Things I have tried:
I have tried using full paths (eg, C:/php/php.exe) for both the php and the shell script, and that didn't matter.
I have tried reversing the slashes vendor\bin\phpunit
I can run php -v successfully, but php -f vendor/bin/phpunit still just outputs the file contents.
I have confirmed the PATH for php is accurate and restarted.
All expected vendor files do appear to be present.
Composer update is not throwing errors of any kind.
I've changed my terminal / CLI processor to use powershell instead of the default cmd.exe (same result as above)
I've confirmed encoding of the phpunit file is UTF-8 without BOM
I've tried making the php command execute the phpunit script in powershell and git bash directly with no luck --- it outputs the shell file. It seems to be that php is just not executing it, which makes me think there is a problem with my php.ini or something.
I CAN run the phpunit shell directly, such as phpunit --version, but I can't get it to run my tests.
I set the composer platform to match my cli php -v
"config": {
"platform": {
"php": "7.4.20"
}
}
Edit: Interestingly, I uploaded it all to my LAMP webserver and ran the same script there, and it is not executing there either. It's outputting the files...
There is a lot of stuff you're fiddling with while trouble-shooting your issue, so there can be only giving extended comments on it. Take it with a grain of salt and pick the pieces that make sense to you, it looks to me you're clever and should be close to the point where you connect the dots more soon than later (don't give up):
C:\Repos\Project\TDD>php vendor/bin/phpunit
This on your windows shell prompt command the php binary to execute the (php) script vendor/bin/phpunit.
And PHP does exactly this (everything else would be a surprise, right?), it executes that script.
The output you see confirms it. As php is the PHP CLI SAPI (PHP Command Line Binary), the first line starting with # is not output (you can find this behaviour described in the PHP documentation as well: https://www.php.net/manual/en/features.commandline.usage.php and on antoher place that I can't find right now that exactly describes this difference to the common mode https://www.php.net/manual/en/language.basic-syntax.phpmode.php).
You then correctly analyze:
This is the content of the phpunit shell script.
and make the note on the shebang line:
#!/usr/bin/env sh
So this looks to me that this shell script vendor/bin/phpunit is not to be executed with the given commandline:
php vendor/bin/phpunit
but instead just by:
C:\Repos\Project\TDD>vendor/bin/phpunit
Which won't (or might not) work on your windows system.
Some more background information (this applies to phpunit bin-stubs as well as other when installed as composer(1) dependencies):
composer manages these scripts (for you)
composer handles them for POSIX compatible systems as well as for others (compare the /usr/bin/env sh which is stupid, it's /bin/sh, always, may need a report on the composer project) incl. windows or windows with cygwin or WSL running on Windows, Vagrant box setups etc. pp. (yes they really care since years).
composer handles this at the time of install/update.
for windows (which I can't compare are not using it but from what I remember) composer is adding .bat or .cmd files next to the commands (as that is how Windows handles executables).
So mabye using:
C:\Repos\Project\TDD>composer exec phpunit
already solves your invocation problem.
Or
C:\Repos\Project\TDD>vendor\bin\phpunit.bat
Or
C:\Repos\Project\TDD>vendor\bin\phpunit.cmd
Or
C:\Repos\Project\TDD>vendor\bin\phpunit
does. Point in case is this: https://getcomposer.org/doc/articles/vendor-binaries.md
All in all this looks to me you got instructions from one developer working on a unixoide sytem (Mac, Linux) and you're running on Windows. This should not pose a problem on that level, however the onboarding in your team might be low or it's just the knowledge management (unfortunately after a decade or more of Stackoverflow this got worse) and you've been left alone with the trouble shooting.
It's not a programming problem, but merely getting the tooling to run.
Perhaps there is some regime about composer and running it which prevents you from looking there first. But this is hard to say on Stackoverflow.
I'd start fresh with the project, remove it from disk and install it anew. This must work, always. To not sink the current project you can do this a-new in a second directory (the project might support composer create-project to give it a quick start - that is cloning new and doing the composer install).
Similar it is that you could do a composer update in the existing project (which is intended to modify it and depending on how well the project you work with is integrated with composer and your development platform will enable or break things).
At the end of the day the common workflow is:
> rmdir vendor
(remove the vendor directory, that is the blank slate)
> composer install
(install the vendor directory, that is all PHP dependencies of the project)
> composer exec phpunit
(execute the phpunit test-runner)
Edit: Interestingly, I uploaded it all to my LAMP webserver and ran the same script there, and it is not executing there either. It's outputting the files...
Never install phpunit on a webserver system. Run it in development or CI, but not on the webserver. Period. (this has security implications, and it won't help you to execute it there, you need to run it where you develop when you're doing TDD - keep this focus for troubleshooting)
The true path to the PHP script that is represented by vendor/bin/phpunit is:
vendor/sebastianbergmann/phpunit/phpunit
(you can find it in the composer.json of phpunit https://github.com/sebastianbergmann/phpunit/blob/master/composer.json#L66)
Given your original command-line and from the various other information you give, this should work:
php vendor/sebastianbergmann/phpunit/phpunit

Install Composer without curl (local)

I have to run a Laravel Project on a customers Server, Mcrypt is already installed but I can't run "composer install" because composer is missing. Problem here is, that I can't run
curl -sS https://getcomposer.org/installer | php
because I don't get a connection to other server "outside".
So does anybody know, if I can save the file local and upload it with FTP and run it?
Already tried to save the /installer as a file and run it with "asdf | php" but it didn't work. I also downloaded the composer.phar file but how do I run the .phar file?
Thanks!!
Downloading the composer phar file as you have done is a sufficient alternative.
Usage:
php composer.phar command
Docs: https://getcomposer.org/doc/01-basic-usage.md
However, I am fairly sure composer depends on curl, at least as far as updating/installing packages goes. So if you're intending to use those features you'll need curl anyway.*
*citation needed.
edit:
I am currently looking through the composer source and I can't yet find a reference to curl. It appears to use stream_context_create, and the manual page for that method doesn't mention curl either. So maybe it'll work without curl...

Php update (Package 5.5-frontenddev is already installed)?

I am trying to update my Php to 5.5 on a mac (by pasting "curl -s http://php-osx.liip.ch/install.sh | bash -s 5.5" into terminal). The download starts but gives the following message before the downloads stops:
Package 5.5-frontenddev is already installed at version 5.5.5-20131020-233829. You wanted to install version 5.5.5-20131020-233829.
Is there anyway around this as I really need 5.5 in order to continue with my course!
Thank you in advance for any help.
Margate
You should be able to delete the packager registry log and just try the command again, making sure you have removed the relevant folders from /usr/local/php5-*.
The file is located at:
/usr/local/packager/registry.log

How to install PHPUnit with WAMP?

I'm a newbie programmer and I have tried for an embarrassingly long time to get PHPUnit set up and working with WAMP. I have read the documentation and went through various sites to see what I'm doing wrong, but I give up! I need someone to explain this to me in simple terms.
I've probably seen all the guides on how to set it up, but feel free to link me to something you believe is foolproof!
Try this blog : http://nishutayaltech.blogspot.com/2011/04/installing-phpunit-on-windows.html
This setup is for Windows. Hope this will help you.
Also check this out, may be useful http://www.mark-leong.com/installing-php-and-phpunit-on-windows-7/
// adding required pear channels
pear channel-update pear.php.net
pear upgrade-all
pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear update-channels
// performing install
pear install --alldeps --force phpunit/PHPUnit
If everything ok, check whether phpunit have been installed by putting in command line
phpunit -v
If you encountered any errors or interrupted installing
pear clear-cache
may be usefull in that case.
1) download https://phar.phpunit.de/phpunit.phar
2) run it via php phpunit.phar
Btw if that file ever goes away you can look at the original directions here: https://github.com/sebastianbergmann/phpunit
I recommend using composer. It can be used per project, but also 'globally'.
Make a folder on your C drive called 'globalpackages', then cd into it from the command line.
run 'composer require phpunit/phpunit'
once that finishes run 'composer install'
once that finishes you can check the contents of C:\globalpackages\vendor\phpunit' and should see two phpunit files, one of them a bat.
Add C:\globalpackages\vendor\phpunit to your system path and then you will be able to run phpuni from anywhere on your system.
For me this is the fastests and easiest way.
Make sure you have wamp with WAMP with PHP 7 installed as phpunit requires PHP7 to work! or at least 6.2
Go to folder
wamp64\bin\php\php7.0.10
(wherever you installed your wamp - BEWARE last folder is name of PHP version you have so it might be different then above )
We will be working in this folder during entire installation. So if I say edit file etc it means in this folder.
Download newest version of phpunit from https://phpunit.de/
At the time of writing this I get version phpunit 6.2 and php7.0.10
4. Copy downloaded file to wamp64\bin\php\php7.0.10 folder
For me it's: phpunit-6.2.2.phar
for you it might be different version.
Now change name of the phpunit-6.2.2.phar to phpunit.phar
Now make sure you have added your php to PATH in Environment Variables
To do this on Windows 10 and Windows 8
6a. In Search, search for and then select: System (Control Panel)
6b. Click the Advanced system settings link.
6c. Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
6d. In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Paste location of your PHP. For me it would be: D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10
(if in PATH there was other command or path just add ";" at the end. For exmaple:
%someOtherCommand%; D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10)
6e. Click OK. Close all remaining windows by clicking OK.
In cmd (to run cmd go to search in Windows and type cmd.exe and click Enter)
go to folder wamp64\bin\php\php7.0.10
(to go to folder type for example cd D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10)
now once you are in this folder run this command in cmd:
echo #php "%~dp0phpunit.phar" %* > phpunit.cmd
now run this command:
phpunit
you should get list of all commands available in phpunit
now run this:
phpunit --check-version
you will get info what phpunit version you have and if you are using the newest version.
if this doesn't work go to wamp64\bin\php\php7.0.10
Edit file phpunit.bat
Add this line:
""%PHPBIN%" "D:\AnyFolderYouInsalledWampTo\wamp64\bin\php\php7.0.10\phpunit.phar" %*
Repeat point 9.
if it still doesn't work let me know.
Very well done, Emil! You're a star! Perfect answer to install PHPUnit with WAMP on Windows. Look no further than Emil.
https://stackoverflow.com/users/5753967/emil

Running shell commands from PHP - With root permissions or sudo

I'll explain what I'm trying to do, because someone might have a much better and completely different approach to this.
I'm trying to install FFMPEG, but not just install it, I'm making an automated installer that installs some PHP scripts and also FFMPEG if it's not already installed.
I can't find any automated PHP scripts that can install FFMPEG, so I'm guessing this is more difficuilt than I thought.
I had 3 options to do this:
Build from source on the server using the exec function, this
requires root permissions.
Find a pre-compiled binary of FFMPEG, easily done, and I did it, but
then I realised it didn't have the correct codecs so wasn't working.
Use YUM or APT-GET to install FFMPEG, this would be great but it
requires root permissions.
So, how can I either:
Use YUM/APT-GET from PHP and set sudo
OR
Install codecs for FFMPEG after it has been compiled. Using the pre-compiled binaries that I found, if it were possible then I could just install the missing codecs (lame mp3 I think. Maybe others too). Or do the codecs need to be built into the binary.
I think the prefered option is to use YUM/APT-GET as my targets are mostly Centos 5 and maybe Ubuntu aswell.
sudo in php is a lot easier if you use SSH. Among other things you can make use of "expect" to wait for the appropriate prompts. If there's a way to do that with the built in exec() or system() I'm not aware of it.
If you end up compiling from source or installing from a repo you can handle the install processs through this project that allows PHP to obtain and interact with a real Bash shell. Get it here: https://github.com/merlinthemagic/MTS
After downloading you would simply use the following code:
$shell = \MTS\Factories::getDevices()->getLocalHost()->getShell('bash', true);
$return1 = $shell->exeCmd('yum -y install FFMPEG');
//the return will be a string containing the return of the command
echo $return1;
You will need to deal with the edge cases when i.e. there is a GPG key that need to be accepted or dependencies are conflicting. But the project lets you script all Bash interaction.

Categories