本篇内容介绍了“Windows和Linux环境下如何安装配置PHP”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

PHP简介

PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。 原始为Personal Home Page的缩写,已经正式更名为 “PHP: Hypertext Preprocessor”

Windows下安装配置PHP

1、下载

官网下载地址https://windows.php.net/download

选择最新版下载

更多版本如不同VC和Thread Safe左侧导航有介绍。

2、解压缩

文件名可以改简洁点

3、配置

#加载PHPLoadModulephp7_module'D:/tools/php7/php7apache2_4.dll'#将PHP配置文件加载到Apache配置文件中,共同生效PHPIniDir'D:/tools/php7'#配置Apache分配工作给PHP模块,把PHP代码交给PHP处理#即.php后缀名的文件AddTypeapplication/x-httpd-php.php

4、php.ini文件

上述配置的php.ini文件默认是不存在的,是以development和production格式存在,需要格式化处理。

5、测试配置(此步可跳过)

重启Apache服务,打开cmd,切到 Apache解压目录/bin,输入指令

httpd-M

6、测试PHP代码

<?php//测试echo'helloworld';?>

至此就全部好了(~ ̄▽ ̄)~

Linux下安装配置PHP

1、下载和解压

cd/usr/local/src/#切换目录wgethttp://cn2.php.net/distributions/php-7.4.10.tar.bz2#下载wgethttp://xmlsoft.org/downloads.html/tarjxvfphp-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

yuminstall-ylibxml2-devel

Package ‘openssl’, required by ‘virtual:world’, not found

yuminstall-yopensslopenssl-devel

Package ‘sqlite3’, required by ‘virtual:world’, not found

yuminstallsqlite-devel

configure: error: Please reinstall the BZip2 distribution

yuminstall-ybzip2bzip2-devel

Package ‘krb5’, required by ‘virtual:world’, not found

yuminstallkrb5-devel

Package ‘libcurl’, required by ‘virtual:world’, not found

yuminstalllibcurl-devel

Package ‘libjpeg’, required by ‘virtual:world’, not found

yuminstalllibjpeg-devel

Package ‘libzip’, required by ‘virtual:world’, not found

yuminstalllibzip-devel

Package ‘libxslt’, required by ‘virtual:world’, not found

yuminstalllibxslt-devel

Package ‘freetype2’, required by ‘virtual:world’, not found

yuminstallfreetype-devel

Package ‘libpng’, required by ‘virtual:world’, not found

yuminstalllibpng-devel

Package ‘oniguruma’, required by ‘virtual:world’, not found(这个有点麻烦 )

cd/usr/local/src/wgethttps://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz-Ooniguruma-6.9.4.tar.gztar-zxvfoniguruma-6.9.4.tar.gzyuminstallautoconfautomakelibtool#有询问输入ycdoniguruma-6.9.4/./autogen.sh&&./configure--prefix=/usrmake&&makeinstall

3、php.ini

拷贝格式化php.ini,同Windows

cpphp.ini-developmentphp.ini/usr/local/php7/#拷贝cpphp.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.ServerName195行ServerNamewww.example.com:80#2.Directory204行<Directory/>AllowOverridenoneRequireallgranted</Directory>#3.DirectoryIndex253行<IfModuledir_module>DirectoryIndexindex.htmlindex.php</IfModule>#4.AddType391行AddTypeapplication/x-httpd-php.php:wq#保存退出(先按ESC)/usr/local/apache2.4/bin/apachectl-t#测试配置语法/usr/local/apache2.4/bin/apachectlgraceful#重新加载配置文件

5、启动服务

/usr/local/apache2.4/bin/apachectlstartps-ef|grephttpd#查看httpd进程netstat-lntp|grep80#查看80端口curllocalhost#测试

6、测试

iptables-IINPUT-ptcp--dport80-jACCEPT#开放80端口或配置服务器安全组vim/usr/local/apache2.4/htdocs/test.php#编辑测试文件<?phpphpinfo();?>:wq#保存退出(先按ESC)

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

“Windows和Linux环境下如何安装配置PHP”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!