Mac上重装PHP-7.3和apache-2.4.41

升级

请移驾最新,最省心的教程:

Mac上最简单的brew自主安装Apache+PHP教程 (A2.4.41 + P7.4.1)

https://blog.csdn.net/qq285744011/article/details/103729227

 

 


步骤

# 清理(1)brew安装的php:

brew unlink php
brew uninstall php

 

# 清理(2)Mac自带的php:

cd /etc/
sudo rm -rf php-fpm.conf.defaultphp.ini php.ini.default

cd /usr/bin/
sudo rm -rf php php-config phpdoc phpize

cd /usr/include
sudo rm -rf php

cd /usr/lib
sudo rm -rf php

cd /usr/sbin
sudo rm -rf php-fpm

cd /usr/share
sudo rm -rf php

cd /usr/share/man/man1
sudo rm -rf php-config.1 php.1 phpize.1

cd /usr/share/man/man8
sudo rm -rf php-fpm.8

 

# 为brew安装command-line工具

xcode-select --install
brew update

 

# Mac 重装Apache

sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew unlink apache2
brew uninstall apache2
brew unlink httpd
brew uninstall httpd

brew install apache2
sudo apachectl start

  1. /usr/local/etc/httpd/httpd.conf 这是brew安装的apache2的配置文件
  2. /usr/local/etc/httpd/extra/httpd-ssl.conf 这是阿帕奇的SSL配置文件
  3. /usr/local/etc/httpd/extra/httpd-vhosts.conf 这是阿帕奇的vhost配置文件
  4. /usr/local/Cellar/httpd/2.4.41_1/lib/httpd/modules/ 这是阿帕奇的模块文件夹,注意版本号
  5. /usr/local/Cellar/php/7.4.1/ 这是PHP最新版的安装路径,如果你用brew install php的话,但是不建议,因为它的扩展包安装很不容易,推荐下面的方法

 

# 开始一键安装PHP-7.3

# 请参考大神网站https://php-osx.liip.ch/进行版本选择

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3

  1. /usr/local/php5-7.3.8-20190811-205217/libphp7.so 这是当前PHP的阿帕奇包
  2. /usr/local/php5-7.3.8-20190811-205217/bin/pecl 这是当前PHP的pecl工具

  3. /usr/local/php5-7.3.8-20190811-205217/bin/php 这是当前php的运行文件

  4. /usr/local/php5-7.3.8-20190811-205217/lib/php.ini 这是当前PHP的配置文件

 

# 开始配置PHP+apache

ll  /usr/local/php5-7.3.8-20190811-205217/libphp7.so
ll /usr/local/php5-7.3.8-20190811-205217/bin/php
sudo rm /usr/libexec/apache2/libphp7.so
sudo nano /usr/local/etc/httpd/httpd.conf

# 添加以下内容
LoadModule php7_module /usr/local/php5-7.3.8-20190811-205217/libphp7.so

# 将DirectoryIndex index.html改为
DirectoryIndex index.php index.html

# 监听80端口,原来是Listen 8080,改为:
Listen 80

# 启用以下三行
LoadModule socache_shmcb_module lib/httpd/modules/mod_socache_shmcb.so
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf
Include /usr/local/etc/httpd/extra/httpd-mpm.conf

# 启用并修改“#ServerName www.example.com:8080”为:
ServerName www.example.com:80

# 找到标签,修改其内部的:“Require all denied”为:
Require all granted

# 找到标签,在内部添加下面的代码,使Apache能解析PHP文件,否则PHP文件只会显示源码而不解析:
AddType application/x-httpd-php .php

# 保存,重启apache
sudo apachectl restart
php -m
php -i

 

安装PHP的扩展

原创 Mac上通过pecl安装PHP扩展

https://blog.csdn.net/qq285744011/article/details/103719694

 

延伸

查看当前系统的$PATH:

echo $PATH

 


部分参考:

https://www.jianshu.com/p/4189c878da21
https://php-osx.liip.ch/
https://blog.csdn.net/gray___/article/details/91127369

 

代码

Last login: Wed Dec 25 00:44:20 on ttys001
You have new mail.
ME865:~ rudon$ brew unlink php
Unlinking /usr/local/Cellar/php/7.4.1... 24 symlinks removed
ME865:~ rudon$ brew uninstall php
Uninstalling /usr/local/Cellar/php/7.4.1... (517 files, 75.9MB)
ME865:~ rudon$ php -i
-bash: php: command not found
ME865:~ rudon$ curl -s https://php-osx.liip.ch/install.sh | bash -s 7.3
Detected macOS Mojave >= 10.14.4. All ok.
Get packager.tgz
Unpack packager.tgz
Please type in your password, as we want to install this into /usr/local
Password:
Start packager (may take some time) using /usr/bin/python2.7
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/install/7.3-10.10-frontenddev-latest.dat
downloading https://s3-eu-west-1.amazonaws.com/php-osx.liip.ch/install/7.3-10.10/frontenddev/7.3-10.10-frontenddev-7.3.8-20190811-205217.tar.bz2

Installing package 7.3-10.10-frontenddev into root /
./pkg/pre-install
pkg/pre-install
Skipping existing directory 
Skipping existing directory usr/
Skipping existing directory usr/local/
Extracting usr/local/php5-7.3.8-20190811-205217/
Extracting usr/local/php5-7.3.8-20190811-205217/bin/
Extracting usr/local/php5-7.3.8-20190811-205217/entropy-php.conf
Extracting usr/local/php5-7.3.8-20190811-205217/etc/
Extracting usr/local/php5-7.3.8-20190811-205217/include/
Extracting usr/local/php5-7.3.8-20190811-205217/info/
Extracting usr/local/php5-7.3.8-20190811-205217/lib/
Extracting usr/local/php5-7.3.8-20190811-205217/libphp7.so
Extracting usr/local/php5-7.3.8-20190811-205217/php.d/
Extracting usr/local/php5-7.3.8-20190811-205217/sbin/
Extracting usr/local/php5-7.3.8-20190811-205217/share/
Extracting usr/local/php5-7.3.8-20190811-205217/ssl/
Extracting usr/local/php5-7.3.8-20190811-205217/var/
Extracting usr/local/php5-7.3.8-20190811-205217/var/log/
Extracting usr/local/php5-7.3.8-20190811-205217/var/run/
Extracting usr/local/php5-7.3.8-20190811-205217/ssl/cert.pem
Extracting usr/local/php5-7.3.8-20190811-205217/ssl/certs/
Extracting usr/local/php5-7.3.8-20190811-205217/ssl/misc/
Extracting usr/local/php5-7.3.8-20190811-205217/ssl/openssl.cnf
Extracting usr/local/php5-7.3.8-20190811-205217/ssl/private/
...
...
...
Extracting usr/local/php5-7.3.8-20190811-205217/lib/php/
Extracting usr/local/php5-7.3.8-20190811-205217/lib/php.ini
Extracting usr/local/php5-7.3.8-20190811-205217/lib/php.ini-development
Extracting usr/local/php5-7.3.8-20190811-205217/lib/php.ini-recommended
Extracting usr/local/php5-7.3.8-20190811-205217/lib/pkgconfig/
Extracting usr/local/php5-7.3.8-20190811-205217/lib/postgresql/
Extracting usr/local/php5-7.3.8-20190811-205217/lib/xsltConf.sh
Extracting usr/local/php5-7.3.8-20190811-205217/lib/postgresql/ascii_and_mic.so
Extracting usr/local/php5-7.3.8-20190811-205217/lib/postgresql/cyrillic_and_mic.so
Extracting usr/local/php5-7.3.8-20190811-205217/lib/postgresql/dict_snowball.so
Extracting usr/local/php5-7.3.8-20190811-205217/lib/postgresql/euc2004_sjis2004.so
...
...
...
Extracting usr/local/php5-7.3.8-20190811-205217/bin/curl
Extracting usr/local/php5-7.3.8-20190811-205217/bin/curl-config
Extracting usr/local/php5-7.3.8-20190811-205217/bin/datacopy
Extracting usr/local/php5-7.3.8-20190811-205217/bin/xsltproc
Executing post-install script /tmp/7.3-10.10-frontenddev-post-install
Create symlink /usr/local/php5/entropy-php.conf /etc/apache2/other/+php-osx.conf
Finished.
ME865:~ rudon$ 
ME865:~ rudon$ ll  /usr/local/php5-7.3.8-20190811-205217/libphp7.so
-rwxr-xr-x  1 root  wheel  16802996  8 12 02:52 /usr/local/php5-7.3.8-20190811-205217/libphp7.so
ME865:~ rudon$ 
ME865:~ rudon$ sudo ln -s /usr/local/php5-7.3.8-20190811-205217/libphp7.so /usr/libexec/apache2/libphp7.so
Password:
ln: /usr/libexec/apache2/libphp7.so: File exists
ME865:~ rudon$ sudo rm /usr/libexec/apache2/libphp7.so
ME865:~ rudon$ 
ME865:~ rudon$ 
ME865:~ rudon$ sudo ln -s /usr/local/php5-7.3.8-20190811-205217/libphp7.so /usr/libexec/apache2/libphp7.so
ME865:~ rudon$ 
ME865:~ rudon$ sudo nano /etc/apache2/httpd.conf
ME865:~ rudon$ sudo nano /etc/apache2/httpd.conf
Password:
ME865:~ rudon$ php -m
-bash: php: command not found
ME865:~ rudon$ 
ME865:~ rudon$ ll /usr/local/php5-7.3.8-20190811-205217/bin/php
-rwxr-xr-x  1 root  wheel  16880188  8 12 02:52 /usr/local/php5-7.3.8-20190811-205217/bin/php
ME865:~ rudon$ 
ME865:~ rudon$ echo 'export PATH="/usr/local/php5-7.3.8-20190811-205217/bin:$PATH"' >> ~/.bash_profile
ME865:~ rudon$ 
ME865:~ rudon$ php -m
-bash: php: command not found
ME865:~ rudon$ source ~/.bash_profile
ME865:~ rudon$ 
ME865:~ rudon$ 
ME865:~ rudon$ php -m
[PHP Modules]
apcu
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
gmp
hash
iconv
igbinary
imap
intl
json
libxml
mbstring
mcrypt
mongodb
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
propro
raphf
readline
redis
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xdebug
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib

[Zend Modules]
Xdebug
Zend OPcache

ME865:~ rudon$ sudo apachectl restart
Password:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using ME865.local. Set the 'ServerName' directive globally to suppress this message
ME865:~ rudon$ 

 

 

你可能感兴趣的:(PHP,运维,Mac,OS,X,PHP,Mac,brew)