PHP基础环境搭建

摘要:在最近工作开展中,发现常用操作记录在网页,便于查看和维护更新。这里记录一下PHP的环境搭建,用于展示一些静态网页

相关文章

  1. mysql 8.0.21在windows10上安装

一、PHP环境部署

PHP环境主要需要Apache服务器、PHP、MySQL数据库、phpMyAdmin,其中我自己初始只是需要搭建一个服务器环境,使得一个单机的Axure文件可以访问。此情景下,部署配置好 ``Apache服务器、PHP`` 两项即可。

1.1 下载地址:


Apache服务器
https://www.apachelounge.com/download/

PHP
https://www.php.net/downloads.php

MySQL数据库
https://dev.mysql.com/downloads/mysql/

phpMyAdmin
https://www.phpmyadmin.net/

除了以上文件外,在安装的过程中,还需要我们自行准备好VC++运行库,对于VC++运行库,可以通过以下方式获得


方式一:

在下载Apache页面有一个下载VC++库的链接,点击可直接下载,如图所示


方式二:


在微软中国支持界面进行搜索https://support.microsoft.com/

如图所示,直接搜索即可。链接:最新支持的 Visual C++ 下载,难的搜索可以直接点击此处直接对VC++最新运行库下载。


接下来就逐步进行环境配置,建议创建一个父目录便于将文件集中管理

1.2 环境配置


01、配置Apache服务器中httpd.conf
Define SRVROOT "D:\wamp\Apache24"
#加载php7模块
PHPIniDir "D:\wamp\php-7.3.28-Win32-VC15-x64"
LoadModule php7_module "D:\wamp\php-7.3.28-Win32-VC15-x64\php7apache2_4.dll"
#
AddType application/x-httpd-php .html .php

打开~/WAMP/Apache/conf/httpd.conf,找到路径定义Define SRVROOT(大约在37行),修改为你解压目录的地址同时加入php模块地址,注意Windows不区分大小写,正斜杠也可以在路径中使用。

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
#
ServerName www.example.com:80

取消掉ServerName(229行左右)前面的注释符

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

修改DirectoryIndex(288行左右),将index.php加入默认主页


02、配置php环境
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
;extension_dir = "./"
; On windows:
;extension_dir = "ext"
extension_dir = "D:\wamp\php-7.3.28-Win32-VC15-x64\ext"

复制php文件夹下的php.ini-development更名为php.ini,修改extension_dir为ext文件夹解压的目录,我这里是解压在D盘。


extension=mbstring
;extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=odbc
;extension=openssl
;extension=pdo_firebird
extension=pdo_mysql

启用mbstring、mysqli、pdo_mysql扩展,mbstring确保phpMyAdmin的部分高级功能可以正常使用,mysqli和pdo_mysql都是数据库扩展。

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Shanghai

建议修改一下时区(也可以在程序里改)


03、启动Apache服务器

方式一:直接跨盘进入指定目录

C:\Users\82221>cd /d D:\wamp\Apache24\bin

D:\wamp\Apache24\bin>

方式二:

C:\WINDOWS\system32> d:

D:\>cd D:\wamp\Apache24\bin

D:\wamp\Apache24\bin>

以管理员身份打开cmd进入到~/wamp/apache/bin目录,在Windows下要进入其他分区输入盘符加冒号即可,例如“d:”,在该目录下执行。


D:\wamp\Apache24\bin>httpd -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.

D:\wamp\Apache24\bin>httpd -k start

D:\wamp\Apache24\bin>

可能会有防火墙提示,允许即可。


打开浏览器,输入localhost或127.0.0.1,看到如下画面即安装成功:


04、MySQL数据库配置

参见链接:mysql 8.0.21在windows10上安装


05、配置phpMyAdmin
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

进入到phpMyAdmin的解压路径找到config.sample.inc.php,将它改名为config.inc.php,同时修改 c f g [ ′ S e r v e r s ′ ] [ cfg['Servers'][ cfg[Servers][i][‘AllowNoPassword’]为true,即允许空密码登录。

/**
 * This is needed for cookie based authentication to encrypt password in
 * cookie. Needs to be 32 chars long.
 */
$cfg['blowfish_secret'] = '0466fc45f0f49c877074933049967991'; /*  YOU MUST FILL IN THIS FOR COOKIE AUTH! */

往上在大约17行的位置找到$cfg['blowfish_secret'],这里需要设置一个长度为32位的字符串用来加密cookie,虽然现在是建议使用HTML5的Web存储。最后重启一下服务器使phpMyAdmin的配置生效:$ httpd -k restart

打开浏览器输入localhost/phpmyadmin打开并登录phpMyAdmin,密码为数据库密码。


二、遇到的问题

2.1 Apache配置时缺少php7apache2_4.dll

Define SRVROOT "D:\wamp\Apache24"
#加载php7模块
PHPIniDir "D:\wamp\php-7.3.28-Win32-VC15-x64"
LoadModule php7_module "D:\wamp\php-7.3.28-Win32-VC15-x64\php7apache2_4.dll"
#
AddType application/x-httpd-php .html .php
在配置Apache的时候,里面有一个 ``php7apache2_4.dll`` 文件,但是在自己里面有没有看见。PHP分为现场安全和线程非安全两种,一般

Windows下:Apache + PHP 选TS ,IIS(fast-cgi) + PHP 选TNS。
Linux 下:Apache + PHP 选TS,Nginx + PHP 选TNS。

在不同的PHP版本中,其 php7apache2_4.dll 数字不一样。

2.2 Composer detected issues in your platform: Your Composer dependencies require the following PHP extensions to be installed: openssl


01、什么是openssl?
关于openssl,我说的不如百度百科齐全,还是看看百度百科的解释吧! http://baike.baidu.com/view/300712.htm
php开启openssl的方法,大多数情况下openssl是没有开启的,要想启用需要进行下简单的设置:


02、windows下开启方法:

;by add hyl 2021-6-28
extension=php_openssl.dll
  1. 首先检查php.ini中;extension=php_openssl.dll是否存在, 如果存在的话去掉前面的注释符‘;’, 如果不存在这行,那么添加extension=php_openssl.dll
  2. 将php文件夹下的: php_openssl.dll, ssleay32.dll, libeay32.dll 3个文件拷贝到 WINDOWS\system32\ 文件夹下。
  3. 如果没有 php_openssl.dll ,点击下载php_openssl.dll
    下载下来有很多个php_openssl,找到你相应php版本下面的php_openssl。
    查看php版本可以用如下代码:
<?php
phpinfo();
?>

找到相应版本之后,按照上面讲的第二步来就可以了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值