Ubuntu 16.04 环境下编译安装 LAMP

Ubuntu 16.04 环境下编译安装 LAMP

编译安装 apache

编译安装依赖 apr

./configure --prefix=/usr/local/apr
make
make install

编译安装依赖 apr-util

./configure --prefix=/usr/local/apr-util 
            --with-apr=/usr/local/apr
make
make install

编译安装依赖 pcre

# pcre 在 apache 的 2.2 版本中包含在源码中,但是在 2.4 版本不再包含,但是却是必须的,所以需要单独编译。
./configure --prefix=/usr/local/pcre
make
make install

编译安装 httpd 2.4.23

./configure --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --prefix=/usr/local/apache
make
sudo make install
  • 如果使用远程连接编译,防止断网引起编译安装失败,可以使用 screen 命令。
  • 可能需要的依赖:sudo apt install gcc g++ cmake make
  • 用户的文件一般安装在 /opt//usr/local/ 目录下。
  • 在编译后,需要为 httpd.conf 添加 ServerName : sudo sed -i 's/#ServerName.*/ServerName localhost/ /usr/local/apache/conf/httpd.conf
  • 启动:sudo /usr/local/apache/bin/apachectl start
  • 测试:curl -I 127.0.0.1

编译安装 mysql 5.7

  • 依赖:sudo apt install cmake gcc make libcurses # 或者 libncurses
  • 还需要下载 boost:wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz && tar zxf boost_1_59_0.tar.gz
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DWITH_INNOBASE_STORAGE_ENGINE=1   -DENABLED_LOCAL_INFILE=1  -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 
make
make install

# 安装后的配置:
cd /usr/local/mysql
chown -R mysql.mysql .
bin/mysqld --initialize --user=mysql 
bin/mysql_ssl_rsa_setup
chown -R root .
chown -R /opt/data/mysql
bin/mysqld_safe --user=mysql &
cp support-files/mysql.server /etc/init.d/mysql.server

编译安装 PHP

# 安装依赖:
sudo apt-get install zlib1g-dev libbz2-dev libcurl4-gnutls-dev  libjpeg-dev libpng12-dev  libfreetype6-dev  libmcrypt-dev libxml2-dev
./configure --with-apxs2=/usr/local/apache/bin/apxs --with-mysqli --enable-mysqlnd --enable-mbstring --prefix=/usr/local/php --with-config-file-path=/etc/php/php.ini --with-config-file-scan-dir=/etc/php/conf.d
make
make test
sudo make install
  • 安装必需的模块即可,若需要某个模块,可以安装并动态加载模块:
# 需要安装依赖:
sudo apt install autoconf
cd ./php-x.z.y/ext/name
/usr/local/php/phpize # 可以看到目录下多出了 configure 文件
./configure --with-name=/p/a/t/h --with-php-config=/usr/local/php/php-config #--with-name=/p/a/t/h 并非必需
make 
make install

修改配置文件:
# 修改 extension_dir="/usr/local/php/php/lib/php/extensions/no-debug-zts-20131226"
添加 extension = name.so
  • 配置 http.conf 使 apache 可以解析 php 文件:
    1. 在 http.conf 中添加如下内容:Include conf/extra/httpd-php.conf;
    2. 在 conf/extra 中添加 httpd-php.conf 文件:touch httpd-php.conf;
    3. 在 httpd-php.conf 中添加如下内容:
<FilesMatch "\.ph(p[2-6]?|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>

<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

尽量不要编译,尽可能使用已经编译好的二进制发行包,因为编译浪费时间,而且因为系统的差异有诸多问题。
mysql 在编译时,一定确保有足够的内存。

编译安装 ext openssl

# 编译安装 openssl
./config --prefix=/usr/local/openssl shared
make
sudo make install

# 编译安装 php ext openssl
./configure --with-openssl=/usr/local/openssl --with-php-config=/usr/local/php/php5/bin/php-config
make 
sudo make install
bash -s 'echo "extension=openssl.so >> /usr/local/php/php5/etc/php.ini"

自动安装 lamp

#!/bin/bash
sudo apt install -y gcc g++ make cmake autoconf vim git zlib1g-dev libbz2-dev ibcurl4-gnutls-dev  libjpeg-dev libpng12-dev  libfreetype6-dev  libmcrypt-dev libxml2-dev
cd apt-1.5.2
./configure --prefix=/usr/local/apr
make
sudo make install

cd ../apr-util-*
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make 
sudo make install

cd ../pcre-*
./configure --prefix=/usr/local/pcre
make 
sudo make install 

cd ../httpd*
./configure --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --prefix=/usr/local/apache
make
sudo make install

cd ../openssl*
./config --prefix=/usr/local/openssl shared
make
sudo make install

cd ../php*
./configure -with-apxs2=/usr/local/apache/bin/apxs --with-mysqli --with-mysql --enable-mysqlnd --enable-mbstring --enable-bcmath --enable-sockets --enable-zip --with-bz2 --with-curl --with-gd --with-pdo-mysql --with-xmlrpc --with-zlib --prefix=/usr/local/php/php5 --with-config-file-path=/usr/local/php/php5/etc/php.ini --with-config-file-scan-dir=/usr/local/php/php5/etc/conf.d --with-openssl=/usr/local/openssl
make
sudo make install

sudo sed -i 's/#ServerName.*/ServerName localhost/ /usr/local/apache/conf/httpd.conf'
cd ../php*
sudo cp php.ini-deve* /usr/local/php/php5/etc/php.ini
sudo sh -c "echo Include conf/extra/httpd-php.conf >> /usr/local/apache/conf/httpd.conf"
sudo sh -c "cat >> /usr/local/apache/conf/extra/httpd-php.conf <<EOF<FilesMatch \"\\.ph(p[2-6]?|tml)$\">    SetHandler application/x-httpd-php</FilesMatch><FilesMatch \"\\.phps$\">    SetHandler application/x-httpd-php-source</FilesMatch>EOF"

下面关于LAMP相关的内容你可能也喜欢

相关推荐