CentOS 7 源代碼安裝 Apache2.4 和 PHP7.3

本次安裝過程須要聯網,首先下載 Apache 和 PHP 。測試服務器IP192.168.126.131。本文編寫於2019年4月17日。php

PHP 和 Apache 官方網站下載地址以下:html

http://httpd.apache.org/download.cgimysql

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

首先安裝編譯依賴軟件,再選擇下載安裝所需版本。c++

#直接在服務器安裝依賴軟件
[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等工具上傳到目標服務器。sql

解壓 httpd(Apache)安裝文件。shell

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

安裝 httpd 。apache

#查看配置幫助信息
[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服務。vim

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

修改配置文件。centos

#修改配置文件
[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
<IfModule mime_module>
    #
    # 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
</IfModule>

安裝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 
<?php
phpinfo();
?>
[root@promote php-7.3.4]#

PHP安裝完成,重啓Apache服務。

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

瀏覽器地址欄輸入http://192.168.126.131/phpinfo.php

安裝完成

PHP官方網站教程https://www.php.net/manual/zh/install.unix.apache2.php

查看配置 Apache 文件。如下是部分代碼

[root@promote ~]# cat /usr/local/apache2.4/conf/httpd.conf
#已加載libphp7.so模塊
LoadModule php7_module        modules/libphp7.so
相關文章
相關標籤/搜索