首頁  >  文章  >  後端開發  >  一文詳解Windows與Linux環境下怎麼安裝設定PHP

一文詳解Windows與Linux環境下怎麼安裝設定PHP

青灯夜游
青灯夜游轉載
2022-02-16 11:53:465722瀏覽

怎麼安裝設定PHP?以下這篇文章就來跟大家介紹一下Windows和Linux環境下安裝設定PHP的方法,希望對大家有幫助!

PHP簡介

PHP即“超文本預處理器”,是一種通用開源腳本語言。 PHP是在伺服器端執行的腳本語言,與C語言類似,是常用的網站程式語言。 PHP獨特的語法混合了C、Java、Perl以及 PHP 自創的語法。利於學習,使用廣泛,主要適用於Web開發領域。 原始為Personal Home Page的縮寫,已經正式更名為「PHP: Hypertext Preprocessor」

#Windows下安裝配置PHP

##1、下載

一文詳解Windows與Linux環境下怎麼安裝設定PHP

一文詳解Windows與Linux環境下怎麼安裝設定PHP

一文詳解Windows與Linux環境下怎麼安裝設定PHP##官網下載網址https://windows.php.net/download

選擇最新版下載3-一文詳解Windows與Linux環境下怎麼安裝設定PHP

更多版本如不同VC和Thread Safe左側導覽有介紹。

2、解壓縮

4-一文詳解Windows與Linux環境下怎麼安裝設定PHP

檔案名稱可以改變簡潔點

4-一文詳解Windows與Linux環境下怎麼安裝設定PHP

3、設定

Apache安裝設定可參考這裡一文詳解Windows與Linux環境下怎麼安裝設定PHP

https://blog.csdn.net/qq_45034708/article/details/108565486

#加载PHP
LoadModule php7_module 'D:/tools/php7/php7apache2_4.dll'

#将PHP配置文件加载到Apache配置文件中,共同生效
PHPIniDir 'D:/tools/php7'

#配置Apache分配工作给PHP模块,把PHP代码交给PHP处理
#即.php后缀名的文件
AddType application/x-httpd-php .php
6-一文詳解Windows與Linux環境下怎麼安裝設定PHP

6-一文詳解Windows與Linux環境下怎麼安裝設定PHP

#4、php.ini檔案

6-一文詳解Windows與Linux環境下怎麼安裝設定PHP

上述設定的php. ini檔案預設是不存在的,是以development和production格式存在,需要格式化處理。

5、測試設定(此步驟可跳過)

一文詳解Windows與Linux環境下怎麼安裝設定PHP重啟Apache服務,開啟cmd,切到Apache解壓縮目錄/bin,輸入指令

httpd -M

#6、測試PHP程式碼

  • <?php
    	//测试
    	echo &#39;hello world&#39;;
    ?>

至此就全部好了(~ ̄▽ ̄)~
  • Linux下安裝配置PHP

    1、下載和解壓縮
  • cd /usr/local/src/ #切换目录
    wget http://cn2.php.net/distributions/php-7.4.10.tar.bz2 #下载
    wget http://xmlsoft.org/downloads.html/
    tar jxvf php-7.4.10.tar.bz2 #解压

  • #2、安裝

    cd /usr/local/src/php-7.4.10
    ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=mysqlnd --with-mysqli --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif --enable-fpm
  • 執行configure時會報Error,說XXX not found等,對應安裝即可,直到沒錯
  • Package 'libxml-2.0', required by 'virtual:world' , not found

 yum install -y libxml2-devel
  • Package 'openssl', required by 'virtual:world', not found

#
 yum install -y openssl openssl-devel

一文詳解Windows與Linux環境下怎麼安裝設定PHP

Package 'sqlite3', required by 'virtual:world', not found

 yum install sqlite-devel

configure: error: Please reinstall the BZip2 distribution

一文詳解Windows與Linux環境下怎麼安裝設定PHP

 yum install -y bzip2 bzip2-devel

Package 'krb5', required 由 'virtual:world', not found

######
 yum install krb5-devel
####### ##Package 'libcurl', required by 'virtual:world', not found#########
 yum install libcurl-devel
#########Package 'libjpeg', required by 'virtual:world', not found#########
 yum install libjpeg-devel
#########Package 'libzip', required by 'virtual:world', not found##########
 yum install libzip-devel
###### ####Package 'libxslt', required by 'virtual:world', not found########
 yum install libxslt-devel
#########Package 'freetype2', required by 'virtual:world' , not found#########
 yum install freetype-devel
#########Package 'libpng', required by 'virtual:world', not found##########
 yum install libpng-devel
### ######Package 'oniguruma', required by 'virtual:world', not found(這個有點麻煩)#########
cd /usr/local/src/
wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz
tar -zxvf oniguruma-6.9.4.tar.gz
yum install autoconf automake libtool #有询问输入y
cd oniguruma-6.9.4/
./autogen.sh && ./configure --prefix=/usr
make && make install
############### #3、php.ini#########拷貝格式化php.ini,同Windows###
cp php.ini-development php.ini /usr/local/php7/ #拷贝
cp php.ini /usr/local/php7/
/usr/local/php7/bin/php -m #查看PHP加载模块
/usr/local/apache2.4/bin/apachectl -M #查看httpd加载模块
###############4、設定Apache### ###
vim /usr/local/apache2.4/conf/httpd.conf #编辑配置文件
#修改以下四点
#1.ServerName 195行
ServerName www.example.com:80
#2.Directory 204行
<Directory />
    AllowOverride none
    Require all granted
</Directory>
#3.DirectoryIndex 253行
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
#4.AddType 391行
AddType application/x-httpd-php .php

:wq #保存退出(先按ESC)
/usr/local/apache2.4/bin/apachectl -t #测试配置语法
/usr/local/apache2.4/bin/apachectl graceful #重新加载配置文件

4-一文詳解Windows與Linux環境下怎麼安裝設定PHP

4-一文詳解Windows與Linux環境下怎麼安裝設定PHP

4-一文詳解Windows與Linux環境下怎麼安裝設定PHP

一文詳解Windows與Linux環境下怎麼安裝設定PHP

5、启动服务

/usr/local/apache2.4/bin/apachectl start
ps -ef|grep httpd #查看httpd进程
netstat -lntp|grep 80 #查看80端口
curl localhost #测试

一文詳解Windows與Linux環境下怎麼安裝設定PHP

6、测试

iptables -I INPUT -p tcp --dport 80 -j ACCEPT #开放80端口或配置服务器安全组
vim /usr/local/apache2.4/htdocs/test.php #编辑测试文件
<?php
	phpinfo();
?>
:wq #保存退出(先按ESC)

一文詳解Windows與Linux環境下怎麼安裝設定PHP

 按此步骤下来就能成功了。

推荐学习:《PHP视频教程

以上是一文詳解Windows與Linux環境下怎麼安裝設定PHP的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:cloud.tencent.com。如有侵權,請聯絡admin@php.cn刪除