您当前的位置: 首页 >  apache

自在的旅者

暂无认证

  • 1浏览

    0关注

    695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

环境搭建 - Apache、PHP

自在的旅者 发布时间:2021-09-03 14:27:44 ,浏览量:1

环境搭建-Apache、PHP

目录
  • 1、安装Apache
    • 1.1、下载
    • 1.2、解压
    • 1.3、安装
    • 1.4、启动、停止、重启
    • 1.5、浏览器访问站点
    • 1.6、添加到系统服务
    • 1.7、路径信息
  • 2、安装PHP
    • 2.1、下载
    • 2.2、解压
    • 2.4、配置文件php.ini
    • 2.5、配置Apache服务解析PHP文件
  • 精彩推荐
本篇主要讲解在CentOS环境下进行搭建部署

1、安装Apache 1.1、下载

下载地址:

http://archive.apache.org/dist/httpd/

例如下载httpd-2.4.48.tar.gz

并将已下载的文件上传到服务器上 或者直接输入命令,在服务器上进行下载

wget http://archive.apache.org/dist/httpd/httpd-2.4.48.tar.gz
1.2、解压
tar -xvf httpd-2.4.48.tar.gz

解压后生成httpd-2.4.48目录,并进入此目录 在这里插入图片描述 目录文件

1.3、安装

1、配置安装选项

./configure --prefix=/usr/local/httpd --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre

2、编译

make

3、编译安装

make install
1.4、启动、停止、重启

1、启动服务

/usr/local/httpd/bin/apachectl start

如果提示:AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using xxx.xxx.xxx.xxx. Set the ‘ServerName’ directive globally to suppress this message 解决方法:修改配置文件(httpd.conf)

vi /usr/local/httpd/conf/httpd.conf

将 ServerName www.example.com:80

修改为 ServerName localhost:80 即可 2、停止服务

/usr/local/httpd/bin/apachectl stop

3、重启服务

/usr/local/httpd/bin/apachectl restart
1.5、浏览器访问站点

查看服务器主机ip地址

ip addr

浏览器访问 http://服务器ip地址(端口默认80),页面出现It works!,则表示Apache运行成功。

在这里插入图片描述 注:如果无法访问站点服务,可查看是否因防火墙开启所阻碍,或者添加防火墙开放端口。

防火墙相关命令:

1、开启防火墙

systemctl start firewalld.service

2、关闭防火墙

systemctl stop firewalld.service

3、禁止firewall开机启动

systemctl disable firewalld.service

4、查看防火墙状态

systemctl status firewalld.service

5、防火墙已开启,添加防火墙开放端口(例如80)

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload

在这里插入图片描述 6、查看防火墙所有放行的端口

firewall-cmd --list-ports

1.6、添加到系统服务
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vim /etc/init.d/httpd

在文件开头加入下面几行:

# chkconfig: 35 85 15
# description: Apache server.

保存退出,之后输入如下命令

chmod +x /etc/init.d/httpd
chkconfig --add httpd
chkconfig httpd on

在这里插入图片描述 之后就可以使用服务命令了

1、启动服务

service httpd start

2、停止服务

service httpd stop

3、重启服务

service httpd restart
1.7、路径信息

安装路径:

/usr/local/httpd

配置文件路径:

/usr/local/httpd/conf/httpd.conf

网站文件默认访问路径:

/usr/local/httpd/htdocs
2、安装PHP 2.1、下载

官网地址:

https://www.php.net/

下载地址:

https://www.php.net/downloads

将已下载的文件上传到服务器上

或者直接输入命令,在服务器上进行下载(例如版本7.4.22)

wget https://www.php.net/distributions/php-7.4.22.tar.gz
2.2、解压
tar -zxvf php-7.4.22.tar.gz

解压后,生成php-7.4.22目录,并进入此目录

在这里插入图片描述 2.3、安装 1、配置安装选项

./configure --with-iconv-dir=/usr/local --with-apxs2=/usr/local/httpd/bin/apxs --with-freetype --with-jpeg

配置安装完成后

2、编译

make

编译完成后 在这里插入图片描述

3、编译安装

make install

编译安装完成后 在这里插入图片描述 如果在安装后想改变配置选项,添加功能模块,只需重新 ./configure 加上需要的功能模块,之后 make,之后 make install 就可以了,最后重新启动 Apache 服务,新模块就生效了。

2.4、配置文件php.ini

跳转到生成的php-7.4.22安装目录 在这里插入图片描述 若/usr/local/lib路径下没有php.ini文件,进行复制操作,有此文件则忽略该操作

cp php.ini-development /usr/local/lib/php.ini

配置文件路径:

/usr/local/lib/php.ini

如何查找配置文件php.ini的位置

方式一:

sudo find / -name php.ini

在这里插入图片描述 方式二:

php --ini

2.5、配置Apache服务解析PHP文件

1、检查Apache的配置文件httpd.conf里已调用PHP模块 2、httpd.conf添加如下内容


    SetHandler application/x-httpd-php

在这里插入图片描述 3、Apache默认文件路径下创建PHP文件(用于测试)

echo '' > /usr/local/httpd/htdocs/index.php

4、重启Apache服务,浏览器访问

http://服务器ip/index.php,页面展示如下, 则Apache解析PHP成功。 在这里插入图片描述 如果您觉得文章还不错,请 点赞、分享、在看、收藏 一下,因为这将是我持续输出更多优质文章的最强动力!

如有任何问题或想技术探讨等:

  • 软件测试学习交流群:785128166
  • 软件测试学习路线+配套资源,可关注公众号:程序员二黑,免费获取
  • 以后的路我们一起加油!
精彩推荐

在职阿里6年,一个29岁女软件测试工程师的心声

拒绝B站邀约,从月薪3k到年薪47W,我的经验值得每一个测试人借鉴

公司新来的阿里p8,看了我做的APP和接口测试,甩给了我这份文档

关注
打赏
1665557745
查看更多评论
立即登录/注册

微信扫码登录

0.0925s