centos apache加载php模块,CentOS 7 源代码安装 Apache2.4 和 PHP7.3

本次安装过程需要联网,首先下载 Apache 和 PHP 。测试服务器IP192.168.126.131。本文编写于2019年4月17日。

PHP 和 Apache 官方网站下载地址如下:

首先安装编译依赖软件,再选择下载安装所需版本。

#直接在服务器安装依赖软件

[root@promote ~]# yum install epel-release gcc gcc-c++ make openssl-devel expat-devel apr apr-devel apr-util apr-util-devel pcre wget

#下载源代码

[root@promote ~]# wget https://www.php.net/distributions/php-7.3.4.tar.gz

[root@promote ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.39.tar.gz

也可以使用迅雷等下载软件下载后使用WinSCP或Xshell等工具上传到目标服务器。

解压 httpd(Apache)安装文件。

[root@promote ~]# tar -zxvf httpd-2.4.39.tar.gz

[root@promote ~]# tar -zxvf php-7.3.4.tar.gz

安装 httpd 。

#查看配置帮助信息

[root@promote httpd-2.4.39]# ./configure --help

#配置安装文件,生成makefile文件,启用ssl和动态模块加载

[root@promote httpd-2.4.39]# ./configure --prefix=/usr/local/apache2.4 --enable-ssl --enable-module=shared --enable-so

#安装软件,离开目录

[root@promote httpd-2.4.39]# make && make install && cd

添加httpd服务。

[root@promote ~]# ln -s /usr/local/apache2.4/bin/apachectl /etc/rc.d/init.d/httpd

修改配置文件。

#修改配置文件

[root@promote conf]# pwd

/usr/local/apache2.4/conf

#配置文件修改完成

# #添加php支持

# AddType application/x-httpd-php .php

# AddType application/x-httpd-php-source .phps

#

[root@promote conf]# vim httpd.conf

#

# TypesConfig points to the file containing the list of mappings from

# filename extension to MIME-type.

#

TypesConfig conf/mime.types

#

# AddType allows you to add to or override the MIME configuration

# file specified in TypesConfig for specific file types.

#

#AddType application/x-gzip .tgz

#

# AddEncoding allows you to have certain browsers uncompress

# information on the fly. Note: Not all browsers support this.

#

#AddEncoding x-compress .Z

#AddEncoding x-gzip .gz .tgz

#

# If the AddEncoding directives above are commented-out, then you

# probably should define those extensions to indicate media types:

#

AddType application/x-compress .Z

AddType application/x-gzip .gz .tgz

#

# AddHandler allows you to map certain file extensions to "handlers":

# actions unrelated to filetype. These can be either built into the server

# or added with the Action directive (see below)

#

# To use CGI scripts outside of ScriptAliased directories:

# (You will also need to add "ExecCGI" to the "Options" directive.)

#

#AddHandler cgi-script .cgi

# For type maps (negotiated resources):

#AddHandler type-map var

#

# Filters allow you to process content before it is sent to the client.

#

# To parse .shtml files for server-side includes (SSI):

# (You will also need to add "Includes" to the "Options" directive.)

#

#AddType text/html .shtml

#AddOutputFilter INCLUDES .shtml

AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

安装PHP所需依赖软件。

[root@promote ~]# yum -y install libxml2-devel openssl curl-devel libjpeg-devel libpng libpng-devel freetype-devel libmcrypt-devel libzip libzip-devel

[root@promote ~]# tar -xvf php-7.3.4.tar.gz

[root@promote ~]# cd php-7.3.4/

#部分系统提示libzip版本过低,可选yum或源码安装

[root@promote ~]# yum install http://rpmfind.net/linux/centos/7.6.1810/os/x86_64/Packages/libzip-0.10.1-8.el7.x86_64.rpm

[root@promote ~]# wget https://libzip.org/download/libzip-1.5.2.tar.gz

编译和安装。需要注意一下,Apache怎么和PHP互动?

[root@promote ~]# tar -xvf php-7.3.4.tar.gz

[root@promote ~]# cd php-7.3.4/

#开启php和apache关联

[root@promote php-7.3.4]# ./configure --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php/etc --enable-fpm --enable-sysvsem --enable-sockets --enable-pcntl --enable-mbstring --enable-mysqlnd --enable-opcache --enable-shmop --enable-ftp --enable-wddx --enable-soap --with-apxs2=/usr/local/apache2.4/bin/apxs

[root@promote php-7.3.4]# make && make install

#复制配置文件

[root@promote php-7.3.4]# cp php.ini-production /usr/local/php7.3/etc/php.ini

[root@promote php-7.3.4]# ls /usr/local/php7.3/etc/

pear.conf php-fpm.conf.default php-fpm.d php.ini

[root@promote php-7.3.4]# vim /usr/local/php7.3/etc/php.ini

[root@promote php-7.3.4]# /etc/init.d/httpd -k restart

[root@promote ~]# netstat -ntlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1/systemd

tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 7372/dnsmasq

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6979/sshd

tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 6981/cupsd

tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7307/master

tcp 0 0 127.0.0.1:6010 0.0.0.0:* LISTEN 8900/sshd: root@pts

tcp6 0 0 :::111 :::* LISTEN 1/systemd

tcp6 0 0 :::80 :::* LISTEN 24953/httpd

tcp6 0 0 :::22 :::* LISTEN 6979/sshd

tcp6 0 0 ::1:631 :::* LISTEN 6981/cupsd

tcp6 0 0 ::1:25 :::* LISTEN 7307/master

tcp6 0 0 ::1:6010 :::* LISTEN 8900/sshd: root@pts

[root@promote php-7.3.4]# cd

[root@promote ~]# cd /usr/local/apache2.4/htdocs/

[root@promote htdocs]# cd /usr/local/apache2.4/htdocs/

#查看phpinfo.php文件内容

[root@promote php-7.3.4]# vim /usr/local/apache2.4/htdocs/phpinfo.php

[root@promote php-7.3.4]# cat /usr/local/apache2.4/htdocs/phpinfo.php

phpinfo();

?>

[root@promote php-7.3.4]#

PHP安装完成,重启Apache服务。

[root@promote ~]# cd

[root@promote ~]# /usr/local/apache2.4/bin/apachectl restart

f9bc35a5bc54572ff2e565e809e894bb.png

查看配置 Apache 文件。以下是部分代码

[root@promote ~]# cat /usr/local/apache2.4/conf/httpd.conf

#已加载libphp7.so模块

LoadModule php7_module modules/libphp7.so

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值