ubuntu 16.04 源码安装httpd和php

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhao__zhen/article/details/84672307

ubuntu 16.04 源码安装httpd和php

在对httpd和php进行编译时,需要提前安装一些依赖包,请先完整的阅读本篇文章,把本人遇到的一些问题依赖问题解决好再进行操作!

1. 源码安装httpd

  • 安装apr
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.5.tar.gz
tar -zvxf apr-1.6.5.tar.gz 
cd apr-1.6.5
./configure --prefix=/usr/local/apr/
make
make install
  • 安装apr-util
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make 
make install
  • 错误解决

解决方案
sudo apt-get install libpcre3-dev
  • 编译安装httpd
wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.37.tar.gz
tar -zxvf httpd-2.4.37.tar.gz
cd httpd-2.4.37

./configure --prefix=/usr/local/httpd/ \
--sysconfdir=/etc/httpd/ \
--with-include-apr \
--disable-userdir \
--enable-headers \
--with-mpm=worker \
--enable-modules=most \
--enable-so \
--enable-deflate \
--enable-defate=shared \
--enable-expires-shared \
--enable-rewrite=shared \
--enable-static-support \
--with-apr=/usr/local/apr/ \
--with-apr-util=/usr/local/apr-util/bin \
--with-ssl \
--with-z 

make
make install

2. 源码安装php

  • 编译php7
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/httpd/bin/apxs  --enable-fpm  --with-zlib --with-libxml-dir --enable-sockets --with-curl --with-jpeg-dir --with-png-dir --with-gd --with-iconv-dir --with-freetype-dir --enable-gd-native-ttf --with-xmlrpc --with-openssl --with-mhash --with-mcrypt --with-pear --enable-mbstring --enable-sysvshm --enable-zip --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock --with-pdo-mysql --disable-fileinfo  

make
make install

错误解决

解决方法
apt-get install libssl-dev libcurl4-openssl-dev pkg-config
  1. configure: error: jpeglib.h not found.

解决方法:

apt-get install libjpeg-dev

  1. configure: error: freetype-config not found.

apt-get -y install libfreetype6-dev

  1. configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决方法:

apt-get install libmcrypt-dev

4.configure: error: Please reinstall the mysql distribution

这个表示没有找到 mysql 安装的那个 config 文件.然后就是找到mysql_config的文件路径,进行编译时添加–with-mysqli=mysql_config文件的路径。

3. 配置httpd.conf

在httpd.conf中找到以下相关内容,根据自己的需要进行修改或者添加

Listen 9998
DocumentRoot "/home/ubuntu/php_project/"
<Directory "/home/ubuntu/php_project/">
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

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

cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

启动|停止|重启   /etc/init.d/httpd start|stop|restart

#扩展
启动          /usr/local/httpd/bin/apachectl -f /etc/httpd/httpd.conf
暴力停止      /usr/local/httpd/bin/apachectl -k stop
优雅停止      /usr/local/httpd/bin/apachectl -k graceful-stop
优雅的重启   /usr/local/httpd/bin/apachectl -k graceful
暴力重启     /usr/local/httpd/bin/apachectl -k restart

在php_project中新进文件index.php

<?php
phpinfo();
?>

在浏览器中打开页面可得到

参考链接:https://blog.csdn.net/m0_37886429/article/details/79643078

猜你喜欢

转载自blog.csdn.net/zhao__zhen/article/details/84672307