Can't restart PHP with homebrew on macOS - php

I successfully installed homebrew by following the instructions of the official website (https://brew.sh/).
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
It was installed under /opt/homebrew
I then did install php with brew install php#8.1
If I restart php with brew services restart php I get the following error message:
Permission denied # rb_sysopen - /Users/USER/Library/LaunchAgents/homebrew.mxcl.php.plist
I use macOS Monterey 12.4
Using sudo to restart php results in the warning:
Warning: php must be run as non-root to start at user login!
Does anybody have an idea on how to solve this issue?

Command to restart my php-fpm:
brew services restart php#8.1
If you don't have brew services, try installing it like this:
brew tap homebrew/services

Edit: Solved by using 'chown' on a sub directory that was still running under the wrong user.

Related

Update PHP to 7.4 macOS Catalina with brew

I try to update my PHP version to 7.4 on macOS Catalina with brew.
I did brew install php#7.4
If I check my version php -v, I still see the old version PHP 7.3.11?
What do I have to do?
Update:
After brew doctor I get:
Warning: Homebrew's sbin was not found in your PATH but you have
installed formulae that put executables in /usr/local/sbin. Consider
setting the PATH for example like so: echo 'export
PATH="/usr/local/sbin:$PATH"' >> ~/.profile
You can find my similar answer for php#7.2.
brew install php#7.4
brew link --force --overwrite php#7.4
brew services start php#7.4
export PATH="/usr/local/opt/php#7.4/bin:$PATH"
export PATH="/usr/local/opt/php#7.4/sbin:$PATH"
try:
brew update
brew upgrade php
php -v
brew services start php
or
brew services restart php
if you use apache server:
sudo apachectl restart
if you use ngnix
sudo nginx -s reload
Edit:
brew unlink php#7.3
brew link php#7.4
If anyone want to downgrade php from latest 8.1.2 to 7.4 on systems demand, try the below commands with homebrew:
Installing PHP 7.4 :
brew install php#7.4
brew services restart php
brew unlink php#8.1
brew link php#7.4
echo 'export PATH="/usr/local/opt/php#7.4/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php#7.4/sbin:$PATH"' >> ~/.zshrc
Or
export PATH="/usr/local/opt/php#7.4/bin:$PATH"
export PATH="/usr/local/opt/php#7.4/sbin:$PATH"
Using terminal of MacOS. Don't use terminal in vscode.
I recently faced this issue, all the suggestion here didn't work until I ran:
xcode-select --install
Then ran the command I was trying before and the error stopped, for my case it was php
dyld: Library not loaded: /usr/local/opt/openldap/lib/libldap-2.4.2.dylib
Referenced from: /usr/local/opt/php#7.4/bin/php
Reason: image not found
zsh: abort php -v
I move to directory by: cd /usr/local
Find the file location by: find /usr/local/ -name libphp7.so. (Then get the file location at: /usr/local//Cellar/php#7.4/7.4.23/lib/httpd/modules/libphp7.so. I copy this.)
I open the file by: sudo vim /etc/apache2/httpd.conf
Look for the line by: /libphp7.so
Uncomment the line and update the line by: LoadModule php7_module /usr/local//Cellar/php#7.4/7.4.23/lib/httpd/modules/libphp7.so
Restart apache by: sudo apachectl restart
Verify PHP by accessing http://localhost/phpinfo.php

class "DOMDocument" not found in a Drupal 8 site

I've found an error on a page in my Drupal 8 site; it always show this message error when I visit it:
Error: Class 'DOMDocument' not found in /var/www/vhosts/mysite/core/lib/Drupal/Component/Utility/Html.php on line 286
I'm using Centos 6 and I runned this commands:
yum install php71w-xml
sudo service httpd restart
I verified in php.ini: extensions php are enabled dom, xml, xmlreader, xmlwrite
But not worked for me.
Can you give me a solution? I'm Drupal 8, php 7.1, apache2.2
I had the same issue on Ubuntu with php 7.x and fixed it doing the following.
sudo apt-get install php-xml
Once done, restart your web server
Source: https://laracasts.com/discuss/channels/servers/how-do-i-install-the-dom-extension-for-php7
You Need to Install XML Extension
$ sudo apt-get update
$ sudo apt-get install php5.6-xml //for PHP 5.6
and then restart the apache
$ sudo service apache2 restart
in case using NGINX
nginx -s reload

Uninstall Laravel Valet

I installed Valet for the first time and I had some problems listed below:
It throws an error saying:
Unable to determine linked PHP.
Even though I have PHP 7.1 installed by php-osx.liip.ch so it just goes ahead and installs PHP 7.0 with homebrew anyway!
In the non-laravel projects my localhost does not work and it responds:
ERR_EMPTY_RESPONSE
and then Valet itself does not work either!
I'm getting an error on Valet domains with message:
This site can’t be reached laravel_from_scratch.dev’s server DNS
address could not be found.
So I decided to uninstall it by running $ valet uninstall, it returns the corresponding response but then when I'm running $ valet it is all there! How to uninstall it correctly?
BTW, I posted this issue also on the Valet GitHub page.
I guess I find the solution after a little bit playing around.
It seems Valet uninstall command does not work as expected. To uninstall it first run the composer command to uninstall the php dependencies:
$ composer global remove laravel/valet
then to uninstall the dependencies installed with the Homebrew, first run;
$ brew list
just so you know we are in the same page then if you see dnsmasq and php70 in case you do not want them or you have php7 installed in another approach (like me) run:
$ brew uninstall dnsmasq
and
$ brew uninstall php70
Then go to your user directory and delete the .valet hidden directory or run the terminal command like so:
$ sudo rm -r ~/.valet
An official response here:
https://github.com/laravel/valet/issues/341#issuecomment-287048987
valet uninstall --force
sudo brew services stop nginx
sudo brew services stop php70
sudo brew services stop dnsmasq
brew uninstall nginx
brew uninstall php70
brew uninstall dnsmasq
rm -rf ~/.valet
rm /usr/local/bin/valet

Unable to install PHP 7 with Homebrew on macOS Sierra

I'm trying to setup Laravel's Valet which, as a dependency, requires PHP 7. When I try to install PHP 7 with Homebrew I get the following error:
Configuring SAPI modules
checking for Apache 2.0 handler-module support via DSO through APXS...
Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
The output of /usr/sbin/apxs follows:
apxs:Error: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/apr-1-config not found!.
configure: error: Aborting
READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/brew):
https://github.com/Homebrew/homebrew-php/issues
These open issues may also help:
php70-dbase https://github.com/Homebrew/homebrew-php/issues/3508
php70-intl not found https://github.com/Homebrew/homebrew-php/issues/3591
php70-opcache install issue https://github.com/Homebrew/homebrew-php/issues/3586
Problem installing php70-mcrypt, php70-opcache, php70-xdebug on El Capitan https://github.com/Homebrew/homebrew-php/issues/3587
Add php70-zmq formula https://github.com/Homebrew/homebrew-php/pull/3474
Problem installing homebrew/php/php70-imagick https://github.com/Homebrew/homebrew-php/issues/3571
Install PHP70: Incompatible library version https://github.com/Homebrew/homebrew-php/issues/3444
brew install php70-redis https://github.com/Homebrew/homebrew-php/issues/2762
Allow --enable-redis-igbinary for php70-redis https://github.com/Homebrew/homebrew-php/pull/3473
Add head formula for php70-uploadprogress https://github.com/Homebrew/homebrew-php/pull/3178
This is on a fresh install of MacOS Sierra (actual release, not a beta) with a fresh install of Homebrew (updated). I have installed, ran and agreed to the Xcode licensing agreement.
I have no idea what these errors mean. How can I fix them?
Right I've figured it out. I'm posting the steps to successfully install the require components below in case anybody else stumbles upon this issue:
1). make sure Homebrew is up to date:
brew update
2). Fix the PHP 7 error by making sure Xcode is installed and then typing the following into the Terminal:
brew install apr apr-util
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/opt/apr/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/opt/apr-util/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
3). Run the following command (otherwise the PHP installation will complain about missing libz):
xcode-select --install
4). You can now install PHP 7 with Homebrew:
brew install homebrew/php/php70
It may also be important for those using the macOS-delivered installation of Apache with PHP via Homebrew that (quote from Homebrew php70 install):
With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-apache option. See brew options php70 for more details.
I used the following commands to make it work.
brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php
brew update && brew install apr apr-util
brew link apr-util --force
brew link apr --force
which apu-1-config
which apr-1-config
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
sudo ln -s /usr/local/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
brew install php70
Here is how I upgrade PHP 5.6 to 7.2 in my Macbook Pro (macOS Sierra)
a. Update the brew package first.
$ brew update && brew upgrade
b. Unlink the old version of PHP if it was installed with Homebrew.
$ brew unlink php56
c. Install the new version of PHP.
$ brew install php72
After installation, it shows:
To enable PHP in Apache add the following to httpd.conf (/etc/apache2) and restart Apache:
d. Using vim edit httpd.conf of apache2.
$ sudo vim /etc/apache2/httpd.conf
Search “php5_module” then commend out the statements as follows:
#Comment out the PHP5 module
#LoadModule php5_module libexec/apache2/libphp5.so
Add the commands as follows:
#Enable PHP 7 module
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
e. Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html
The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.2/
f. Restart Apache service
$ sudo apachectl restart
g. check the php version:
$ php -v
PHP 7.2.7 (cli) (built: Jun 22 2018 06:29:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
Done!
Please visit the article "Upgrade PHP version from 5.6 to 7.2 on macOS Sierra (10.12)"
of my blog for more information!
Cheer!

PHP7 on macOS Sierra Beta Fails to Install

I currently have PHP 5.6.23 installed on my system.. However, I am trying to install PHP7 on my system (macOS Sierra Beta), I'm trying to do this with brew install homebrew/php/php70.
However, I get the following error:
$ brew install php70
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
==> Installing php70 from homebrew/php
==> Downloading https://php.net/get/php-7.0.9.tar.bz2/from/this/mirror
Already downloaded: /Users/Removed/Library/Caches/Homebrew/php70-7.0.9
==> ./configure --prefix=/usr/local/Cellar/php70/7.0.9 --localstatedir=/usr/local/var --sy
Last 15 lines from /Users/Removed/Library/Logs/Homebrew/php70/01.configure:
checking for pthreads_lib...
Configuring SAPI modules
checking for Apache 2.0 handler-module support via DSO through APXS...
Sorry, I cannot run apxs. Possible reasons follow:
1. Perl is not installed
2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs
3. Apache was not built using --enable-so (the apxs usage page is displayed)
The output of /usr/sbin/apxs follows:
apxs:Error: /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/apr-1-config not found!.
configure: error: Aborting
READ THIS: https://git.io/brew-troubleshooting
If reporting this issue please do so at (not Homebrew/brew):
https://github.com/Homebrew/homebrew-php/issues
These open issues may also help:
php70-yaf https://github.com/Homebrew/homebrew-php/issues/3328
Install PHP70: Incompatible library version https://github.com/Homebrew/homebrew-php/issues/3444
No solr available for php70 yet https://github.com/Homebrew/homebrew-php/issues/3454
brew install php70-redis https://github.com/Homebrew/homebrew-php/issues/2762
php70-imagick has warnings https://github.com/Homebrew/homebrew-php/issues/2766
Add head formula for php70-uploadprogress https://github.com/Homebrew/homebrew-php/pull/3178
"brew upgrade" fails: php56 conflicting with php70 when upgrading phpmyadmin https://github.com/Homebrew/homebrew-php/issues/2945
10.6.8 "brew install php70" failed with Error 139 https://github.com/Homebrew/homebrew-php/issues/2708
Adds a new php70-gearman formula that updates php56-gearman https://github.com/Homebrew/homebrew-php/pull/3120
Why does wp-cli formula try to install php56 if php70 is already there? https://github.com/Homebrew/homebrew-php/issues/3179
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
The outcome of brew doctor is this:
$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!
Warning: You are using OS X 10.12.
We do not provide support for this pre-release version.
You may encounter build failures or other breakages.
Please create pull-requests instead of filing issues.
Any guidance/help would be much appreciated!
Try this:
$ brew link apr-util --force
$ brew link apr --force
$ which apu-1-config
/usr/local/bin/apu-1-config
$ which apr-1-config
/usr/local/bin/apr-1-config
$ sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
$ sudo ln -s /usr/local/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
$ sudo ln -s /usr/local/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php
$ brew update && brew install apr apr-util
$ brew link apr-util --force
$ brew link apr --force
$ which apu-1-config
$ which apr-1-config
$ sudo mkdir -p /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
$ sudo ln -s /usr/local/bin/apu-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
$ sudo ln -s /usr/local/bin/apr-1-config /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.12.xctoolchain/usr/local/bin/
$ brew install php70
In terminal,
curl -s http://php-osx.liip.ch/install.sh | bash -s 7.0
will install php7 on macOS Sierra, I just tested.
Edit httpd.conf (located in /etc/apache2/) file.
Comment below line.
#LoadModule php5_module libexec/apache2/libphp5.so

Categories