Home > Backend Development > PHP Problem > How does apache parse php pages?

How does apache parse php pages?

(*-*)浩
Release: 2023-02-26 16:54:02
Original
4692 people have browsed it

How does apache parse php pages?

By default, there is no way to directly parse the PHP page after apache is installed. We need to modify the configuration file

1. Start httpd service (recommended learning: PHP video tutorial)

/usr/local/apache2.4/bin/apachectl start
Copy after login

2. When the configuration file is not modified by default, when httpd is first started, a prompt that ServerName is not defined will be reported, but there is no Does not affect the normal startup of httpd

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
Copy after login

3. Modify the configuration file

cp /usr/local/apache2.4/conf/httpd.conf /usr/local/apache2.4/conf/httpd.conf.bak  //修改任何配置文件,先拷贝一份副本
 
vim /usr/local/apache2.4/conf/httpd.conf +195
   ServerName www.example.com:80	//在任意处新增一段ServerName
Copy after login

By default, httpd only allows users to access files in the welcome page directory. Access to other httpd directories will result in 403 , this is because the default rule of httpd is denied, we need to change it to granted

vim /usr/local/apache2.4/conf/httpd.conf
 
把 <Directory />
    AllowOverride none
    Require all deined
    </Directory>
 
改成:
    <Directory />
  AllowOverride none
    Require all granted
   </Directory>
 
  
默认情况下httpd不支持解析php页面,为了能让httpd与php结合,需要新增一些配置内容
 AddType application/x-httpd-php .php
 
 
还需要增加一个目录索引
 
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
 
以上修改完成之后保存退出
Copy after login

4. After we modify the configuration file, we need to check whether there are any syntax errors before restarting and other operations

/usr/local/apache2.4/bin/apachectl -t//使用-t检查语法,出现Syntax OK 说明配置文件没有错误
Copy after login

5. There are two ways to make the httpd configuration file effective

1)/usr/local/apache2.4/bin/apachectl restart//重启启动httpd服务
2)/usr/local/apache2.4/bin/apachectl graceful    //只重新加载配置文件,不重启httpd服务
Copy after login

6. Write a php test script to detect whether httpd can parse php pages (the default page storage path is /usr/local/ apache2.4/htdocs directory)

vim /usr/local/apache2.4/htdocs/test.php
   <?php
   phpinfo();
   ?>
Copy after login

7. Enter the IP address of your own server in the browser and the name of the php page. If the following page appears, it means that httpd parses the php page normally

How does apache parse php pages?

The above is the detailed content of How does apache parse php pages?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template