iphone系统安装php环境的办法详解
iphone系统安置php环境的办法:第一安置iTerm2乃至PhpStorm;然后安置Xcode;接着通过命令“brew install php”安置PHP7.4;最后安置mysql并启动效劳即可。
引荐:《PHP视频教程》
2019 年 10 月 8 日,iphone公司正式公布了新一代 macOS,版本为 Catalina (11.15)。
macOS Catalina 预装了 Ruby(2.6.3)、PHP(7.3.9)、Perl(5.18.4)、Python(2.7.16) 等常用的足本说话,乃至 Apache(2.4.41) Web 效劳器。
需要留意的是,在新版本中,zsh 已代替 bash 成为新版操纵系统中的默许 shell。
以下是我的 MNMP(macOS-nginx-MySQL-PHP)的安置历程。
本教程用使用了三处代替:
- 使用 iTerm2 代替了系统自带的命令行终端
- 使用 nginx 代替了系统自带的 Apache
- 使用 自行安置的 PHP7.4 代替了系统自带的 PHP7.3.9
安置 iTerm2
引荐 iTerm2,iTerm2 功效强大,可以替换系统默许的命令行终端。下载解压后,将 iTerm2 直接拖入"利用程序"名目。
安置 PhpStorm
引荐 JetBrains PhpStorm 作为集成开发工具。
安置 Xcode
Xcode 是iphone出品的包括一系列工具及库的开发套件。通过 AppStore 安置最新版本的 Xcode(9.0)。我们一样不会用 Xcode 来开发后端项目。但这一步也是必需的,由于 Xcode 会附带安置一些如 Git 等必要的软件。
安置 Command Line Tools for Xcode
这一步会帮你安置很多常见的基于 Unix 的工具。Xcode 命令行工具作为 Xcode 的一部分,包括了 GCC 编译器。在命令行中施行以下命令即可安置:
xcode-select --install # 安置 Xcode Command Line Tools
当 Xcode 和 Xcode Command Line Tools 安置完成后,你需要启动 Xcode,并点击赞成接受许可和谈,然后关闭 Xcode 就可以了。这一步骤也是必需的,不然 Xcode 包括的一系列开发工具都将不成用。
安置 Homebrew
Homebrew 作为 macOS 不成或缺的套件治理器,用来安置、升级乃至卸载常用的软件。在命令行中施行以下命令即可安置:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" # 使用系统自带的 ruby 安置 Homebrew
安置后可以修改 Homebrew 源,国外源不断不是很给力,这里我们将 Homebrew 的 git 长途仓库改为我国科学技术大学开源软件镜像:
cd "$(brew --repo)" git remote set-url origin https://mirrors.ustc.edu.cn/brew.git # 更换brew.git: cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core" git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git # 更换homebrew-core.git: echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc # 更换Homebrew Bottles源: source ~/.zshrc
安置 PHP 7.4
安置 PHP7.4.* 来代替系统自带的 PHP7.3:
brew install php
启动 php 效劳:
brew services start php
更换系统自带的 php-fpm:
echo 'export PATH="/usr/local/opt/php/sbin:$PATH"' >> ~/.zshrc source ~/.zshrc
查看版本信息:
php -v php-fpm -v
安置 MySQL
引荐 MySQL 8.0 作为数据库效劳器:
brew install mysql
当然,你也可以选中安置 PostgreSQL 或者 MariaDB。
安置完成后,启动 MySQL:
brew services start mysql
进入 MySQL 效劳器:
mysql -u root -p
设定 root 密码、平安等级等参数:
mysql_secure_installation
依照步骤提醒一步一步来即可。
安置 Redis
安置 redis 效劳器:
brew install redis
安置完成后,启动 Redis:
brew services start redis
使用 redis 客户端:
redis-cli
安置 nginx
这里我们选中 nginx 代替系统自带的 Apache,作为我们的 Web 效劳器:
brew install nginx
启动 nginx 效劳:
brew services start nginx
查看已安置的 brew services:
brew services list
配置 nginx.conf 文件
通过以下命令可以查看 nginx.conf 文件的位置:
nginx -h
输出:
nginx version: nginx/1.17.3 Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -T : test configuration, dump it and exit -q : suppress non-error messages during configuration testing -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/Cellar/nginx/1.17.3_1/) -c filename : set configuration file (default: /usr/local/etc/nginx/nginx.conf) -g directives : set global directives out of configuration file
翻开配置文件:
vi /usr/local/etc/nginx/nginx.conf
在文件末尾可以看到:
include servers/*;
它将同名目下的servers名目里的文件都包括了进来,由此,我们可以在servers文件里创立开发项目的配置信息:
cd /usr/local/etc/nginx/servers/ vi test.conf
将以下配置信息,写入 test.conf文件中:
server { listen 8099; server_name localhost; root /home/www/php-project; rewrite . /index.php; location / { index index.php index.html index.htm; autoindex on; } #proxy the php scripts to php-fpm location ~ \.php$ { include /usr/local/etc/nginx/fastcgi.conf; fastcgi_intercept_errors on; fastcgi_pass 127.0.0.1:9000; } }
在上述的/home/www/php-project
的名目下,我们创立一个 index.php 文件:
vim /home/www/php-project/index.php
写入内容:
<?php phpinfo();
重新启动 nginx:
brew services restart nginx
翻开阅读器,拜访http://localhost:8099
,即可拜访到关于 PHP 配置的信息。
安置 Composer
Composer 是 PHP 用来治理依靠(dependency)关系的工具。你可以在本人的项目中声明所依靠的外部工具库(libraries),Composer 会帮你安置这些依靠的库文件。
安置并更换镜像:
curl -sS https://getcomposer.org/installer | php mv composer.phar /usr/local/bin/composer composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ # 改为阿里云的国内源
安置 PHP 扩展
以 php-redis 扩展为例,有下载源码包来停止安置或者 pecl install 安置:
wget https://pecl.php.net/get/redis-5.1.0.tgz # 下载源码包 tar -zxvf redis-5.1.0.tgz # 解压 cd redis-5.1.0 # 进入名目 phpize # 生成编译配置 ./configure # 编译配置检测 make # 编译 make install # 安置
扩展安置完成后,我们还需最后一步,修改php.ini
文件,并重新启动 PHP 效劳:
vi /usr/local/etc/php/7.4/php.ini # 追加 extension=redis.so brew services restart php # 重新启动 php 效劳 php -m |grep redis # 查看可否安置成功
或者使用 pecl 安置:
pecl install redis
以上就是iphone系统安置php环境的办法详解的具体内容,更多请关注百分百源码网其它相关文章!