1. 程式人生 > >ubuntu 16.04 原始碼安裝httpd和php

ubuntu 16.04 原始碼安裝httpd和php

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