首页 > 编程知识 正文

apache运行特定php函数(phpapache)

时间:2023-12-24 12:05:40 阅读:320750 作者:HQAT

本文目录一览:

怎么在apache中运行php文件

安装php,从php官网下载php安装包。配置好php环境。(或者使用ampz,phpstudy这些软件便捷安装php以及Apache服务器环境)

将php文件放在网站根目录下。

打开浏览器在地址栏中键入Localhost或者127.0.0.1,即可运行浏览你的php程序这样试试吧?你看过后很简单吧以后不会可以向我一样经常到后盾人平台找找相关教材看看就会了,希望能帮到你,给个采纳吧谢谢 ∧_∧

(・∀・)

( ∪ っ

 ) ) )

(_(_)

弱弱的问下,如何在apache下运行php程序

1、如果你只是测试用,apache/php/mysql都没必要自己装,直接下载一个apmserv这样的软件,绿色的,一键启动这些程序。

2、默认的网站根目录是在apache安装目录下的htdocs文件夹下,把你的网站放那去就行了,也可以确认一下,打开apache安装目录下的conf文件夹,用记事本之类打开httpd.conf,搜索一下DocumentRoot,看看它的值在哪,那个就是网站根目录。

mac apache环境 运行php

mac 自带环境 打开终端 输入 sudo apache -v 和php -v 即可查看版本

启动apache

sudo apachectl start  Mac自带的Apache启动了 在浏览器输入“”,会显示“It works!”,说明服务器已经启动成功了。Apache默认根目录在“/Library/WebServer/Documents/”下。

配置文件(httpd.config)保存在/etc/apache2

修改配置文件  sudo vi /etc/apache2/httpd.conf 

将默认目录/Library/WebServer/Documents 替换成自己需要的目录

LoadModule php7_module libexec/apache2/libphp7.so 将前面的# 去掉

运行localhost 会报错:You don't have permission to access / on this server.

这时修改下apache的配置文件httpd.conf:

AllowOverride None

Require all granted

Order deny,allow

Allow from all

然后 sudo apachectl configtest  查看是否修改成功

配置虚拟机 

在配置文件httpd.conf的最后一行  并cd 进去  再 vi 进vhosts.conf文件

接着来到下图 我们可以设置我们拉下来的项目的serverName

修改host文件  sudo vi /etc/hosts

接着在浏览器地址 输入我们项目的servername 即可访问

如果没有成功 一般是缓存原因 换个浏览器  或者清除缓存 关闭浏览器程序 并重启

(以后增加项目 改servername 谷歌有缓存 记得关闭再重启)

一般命令

sudo apachectl start #启动服务器

sudo apachectl restart 重启

sudo apachectl -v 查看服务器版本

sudo apachectl stop #关闭服务器

sudo vi /etc/apache2/httpd.conf  输入密码 进行配置文件修改

sudo apachectl configtest 查看更改是否成功

默认命令行 i 插入模式  esc退出模式

:wq! 保存和退出 (!表示强制修改) 要在英文模式下输入

:w 保存

:q退出 

:q! 强制退出 (误改了东西 强制退出 就不会保存)

命令模式下 /content    查找(n查找下一个)

第一步 配置虚拟机

cd /private/etc/apache2/other

vi vhosts.conf

第二步 更改指向

sudo vi /etc/hosts

报错:

E325: ATTENTION

Found a swap file by the name "/var/tmp/vhosts.conf.swp"

原因:

其一,是当前有其他的进程正在对相同的文档进行编辑;

其二,之前的编辑会话被销毁了(crashed)(也就是说,你上次编辑的时候,没有保存就强制离开了。)

原理:

我们在编辑文件的时候,并不是对原有文件进行修改和覆盖的,而是新建一个副本,名字叫xx.swp,我们对文件的编辑都放在了这个副本里面,这也是为什么我们能进行撤销的原因,我们并没有对原有的文件进行修改。当我们正常退出时,这个文件就正常消失,而当我们异常退出时,这个文件就会作为隐藏文件,当我们下次启动vim时,它就会提示我们上次编辑时,有一个文件异常退出了,是否要进行恢复。也就是弹出E325错误。当我们异常退出时,这个隐藏文件会帮助我们还原到上次编辑的状态。也就相当于是一个自动保存的功能。

解决办法:

进入/var/tmp/vhosts.conf.swp  并将这个文件删除

Apache需要将php文件交给PHP解释器处理后再 返回给浏览器,那PHP如何运行的呢?

1.我们从未手动开启过PHP的相关进程,它是随着Apache的启动而运行的;

2.PHP通过mod_php5.so模块和Apache相连(具体说来是SAPI,即服务器应用程序编程接口);

3.PHP总共有三个模块:内核、Zend引擎、以及扩展层;

4.PHP内核用来处理请求、文件流、错误处理等相关操作;

5.Zend引擎(ZE)用以将源文件转换成机器语言,然后在虚拟机上运行它;

6.扩展层是一组函数、类库和流,PHP使用它们来执行一些特定的操作。比如,我们需要mysql扩展来连接MySQL数据库;

7.当ZE执行程序时可能会需要连接若干扩展,这时ZE将控制权交给扩展,等处理完特定任务后再返还;

8.最后,ZE将程序运行结果返回给PHP内核,它再将结果传送给SAPI层,最终输出到浏览器上。

怎么配置apache 使定时触发指定php脚本程序? - 技术问答

使用linux下的crontab命令即可,他的格式是

* * * * * 命令 *分别对应着分 时 日 月 周 最后的是你要执行的命令 ,

这个命令只要写清要执行 的脚本在哪即可比如说 /usr/src/apache2/conf/apachectl 等等

希望对你有所帮助。

PHP运行于Apache 模块方式

当使用 PHP 作为 Apache 模块时,也可以用 Apache 的配置文件(例如 httpd.conf)和 .htaccess 文件中的指令来修改 PHP 的配置设定。需要有“AllowOverride Options”或“AllowOverride All”权限才可以。

有几个 Apache 指令可以使用户在 Apache 配置文件内部修改 PHP 的配置。哪些指令属于 PHP_INI_ALL,PHP_INI_PERDIR 或 PHP_INI_SYSTEM 中的哪一个,请参考附录中的 php.ini 配置选项列表。

php_value name value

设定指定的值。只能用于 PHP_INI_ALL 或 PHP_INI_PERDIR 类型的指令。要清除先前设定的值,把 value 设为 none。

Note: 不要用 php_value 设定布尔值。应该用 php_flag(见下面)。

php_flag name on|off

用来设定布尔值的配置指令。仅能用于 PHP_INI_ALL 和 PHP_INI_PERDIR 类型的指令。

php_admin_value name value

设定指定的指令的值。不能用于 .htaccess 文件。任何用 php_admin_value 设定的指令都不能被 .htaccess 或 virtualhost 中的指令覆盖。要清除先前设定的值,把 value 设为 none。

php_admin_flag name on|off

用来设定布尔值的配置指令。不能用于 .htaccess 文件。任何用 php_admin_flag 设定的指令都不能被 .htaccess 或 virtualhost 中的指令覆盖。

Example #1 Apache 配置例子

IfModule mod_php5.c

php_value include_path ".:/usr/local/lib/php"

php_admin_flag engine on

/IfModule

IfModule mod_php4.c

php_value include_path ".:/usr/local/lib/php"

php_admin_flag engine on

/IfModule

Caution

PHP 常量不存在于 PHP 之外。例如在 httpd.conf 中不能使用 PHP 常量如 E_ALL 或 E_NOTICE 来设定 error_reporting 指令,因为其无意义,实际等于 0。应该用相应的掩码值来替代。这些常量可以在 php.ini 中使用。

通过 Windows 注册表修改 PHP 配置

在 Windows 下运行 PHP 时,可以用 Windows 注册表以目录为单位来修改配置。配置值存放于注册表项 HKLMSOFTWAREPHPPer Directory Values 下面,子项对应于路径名。例如对于目录 c:inetpubwwwroot 的配置值会存放于 HKLMSOFTWAREPHPPer Directory Valuescinetpubwwwroot 项下面。其中的设定对于任何位于此目录及其任何子目录的脚本都有效。项中的值的'名称是 PHP 配置指令的名字,值的数据是字符串格式的指令值。值中的 PHP 常量不被解析。不过只有可修改范围是 PHP_INI_USER 的配置值可以用此方法设定,PHP_INI_PERDIR 的值就不行。

其它接口下的 PHP

无论怎样运行 PHP,都可以在脚本中通过 ini_set() 而在运行时修改某个值。更多信息见手册中 ini_set() 的页面。

如果对自己系统中的配置设定及其当前值的完整列表感兴趣,可以运行 phpinfo() 函数并查看其结果的页面。也可以在运行时用 ini_get() 或 get_cfg_var() 取得个别配置指令的值。

add a note add a note

User Contributed Notes 13 notes

up

down

3 Anteaus ?2 years ago

One of the most serious problems here is that it is hard to determine programmatically which of three or more possible configuration methods (php.ini, .user.ini, .htaccess) should be used on any given hosting company's server.

The worst outcome is if an install.php routine attempts to set .htaccess directives on a cgi-mode server, in which case the outcome is usually a '500' crash. Once in that situation the php installation routine cannot be rerun to correct the problem, so you effectively have a hosting lockout situation which can only be corrected by manual intervention.

up

down

-2 contrees.du.reve at gmail dot com ?9 years ago

Being able to put php directives in httpd.conf and have them work on a per-directory or per-vitual host basis is just great. Now there's another aspect which might be worth being aware of:

A php.ini directive put into your apache conf file applies to php when it runs as an apache module (i.e. in a web page), but NOT when it runs as CLI (command-line interface).

Such feature that might be unwanted by an unhappy few, but I guess most will find it useful. As far as I'm concerned, I'm really happy that I can use open_basedir in my httpd.conf file, and it restricts the access of web users and sub-admins of my domain, but it does NOT restrict my own command-line php scripts...

up

down

-3 nick at vistaworks dot net ?4 years ago

On Windows, as the documentation above states, you cannot set max_upload_filesize and post_max_size in the registry, because they are PHP_INI_PERDIR.

Confusingly, however, is the fact that phpinfo() will show your changes if you do add those to the regsitry, as if they were taking effect. However, the upload size is *not* changed, regardless of what phpinfo() reports.

I believe the reading of registry values and override happen 'too late' in the request processing, ie, after the file has already been uploaded and rejected.

In a perfect world, phpinfo() would recognize this and not report the overridden values, which is very confusing.

up

down

-4 Woody/mC ?9 years ago

@ pgl: As the documentation says:

"To clear a previously set value use none as the value."

Works fine for me.

up

down

-6 user at NOSPAM dot example dot com ?5 years ago

PHP Constants will work with php_value; for example:

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。