LAMP 手动安装小结

越来越多的开源工具选择同样开源 PHP 作为其运行环境,比如 nagios ,以及最近在研究的 owncloud 。要想使用这些个工具,安装 LAMP 必不可少,而使用 yum 或 apt 来安装又难管理,所以推荐手动安装 LAMP 。作为使用开源工具必装的工具,觉得拆分开来单独记录很有必要,后续分析其他工具时有需要可直接链接引用,不用再重新记录,遂记录步骤如下。

######## 下载 httpd ########

1
2
3
4
wget https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.25.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-1.5.2.tar.gz
wget http://mirrors.tuna.tsinghua.edu.cn/apache/apr/apr-util-1.5.4.tar.gz
wget --no-check-certificate https://ftp.pcre.org/pub/pcre/pcre-8.38.tar.gz

######## 下载 php ########

1
wget http://cn2.php.net/distributions/php-5.6.28.tar.gz

######## 下载 mysql(二进制包) ########

1
wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.13-linux-glibc2.5-x86_64.tar

######## 安装 mysql(二进制安装) ########

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 二进制安装和yum安装的会有冲突,必须先卸载yum安装的mysql
sudo yum install libaio
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
tar xf mysql-5.7.13-linux-glibc2.5-x86_64.tar
tar zxf mysql-5.7.13-linux-glibc2.5-x86_64.tar.gz
sudo mv mysql-5.7.13-linux-glibc2.5-x86_64 /usr/local/mysql-5.7.13
cd /usr/local
sudo ln -s mysql-5.7.13 mysql
cd mysql
mkdir mysql-files
sudo chown -R mysql:mysql .
sudo rm -rf /etc/my.cnf /etc/mysql
sudo bin/mysqld --initialize --user=mysql
sudo bin/mysql_ssl_rsa_setup
sudo chown -R root .
sudo chown -R mysql data mysql-files
sudo bin/mysqld_safe --user=mysql &
sudo cp support-files/mysql.server /etc/init.d/mysql.server
cd ~

######## 安装 httpd ######

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
sudo yum install gcc gcc-c++ perl
tar zxf httpd-2.4.25.tar.gz
tar zxf apr-1.5.2.tar.gz
tar zxf apr-util-1.5.4.tar.gz
tar zxf pcre-8.38.tar.gz
cd apr-1.5.2
sudo ./configure --prefix=/usr/local/apr-1.5.2
sudo make && sudo make install
cd -
cd apr-util-1.5.4
sudo ./configure --prefix=/usr/local/apr-util-1.5.4 --with-apr=/usr/local/apr-1.5.2/
sudo make && sudo make install
cd -
cd pcre-8.38
sudo ./configure --prefix=/usr/local/pcre-8.38
sudo make && sudo make install
cd -
cd httpd-2.4.25
sudo ./configure --prefix=/usr/local/httpd-2.4.25 --with-apr=/usr/local/apr-1.5.2/ --with-apr-util=/usr/local/apr-util-1.5.4/ --with-pcre=/usr/local/pcre-8.38/ --enable-so --enable-modules=all
sudo make && sudo make install
sudo mkdir -p /usr/local/httpd-2.4.25/conf.d
sudo touch /usr/local/httpd-2.4.25/conf.d/null.conf
sudo sh -c 'echo -e "\nInclude conf.d/*.conf\n" >> /usr/local/httpd-2.4.25/conf/httpd.conf'
sudo sed -i 's/#ServerName .*/ServerName 127.0.0.1/g' /usr/local/httpd-2.4.25/conf/httpd.conf
sudo sed -i "#/replace/with/path/to/perl/interpreter#/usr/bin/perl#g" /usr/local/httpd-2.4.25/bin/apxs
cd -

######## 安装 php ########

1
2
3
4
5
6
7
8
9
10
sudo yum install libxml2 libxml2-devel libpng-devel m4 autoconf
tar zxf php-5.6.28.tar.gz
cd php-5.6.28
sudo ./configure --prefix=/usr/local/php-5.6.28 --with-apxs2=/usr/local/httpd-2.4.25/bin/apxs --with-config-file-path=/usr/local/php-5.6.28/etc --with-zlib --with-gd --with-pear --with-mysql --with-gettext --enable-ftp --enable-mbstring --enable-fpm
sudo make && sudo make install
sudo cp php.ini-production /usr/local/php-5.6.28/etc/php.ini
sudo mv /usr/local/php-5.6.28/etc/php-fpm.conf.default /usr/local/php-5.6.28/etc/php-fpm.conf
sudo sh -c 'echo "<?php phpinfo(); ?>;" > /usr/local/httpd-2.4.25/htdocs/index.php'
sudo sh -c 'echo "AddType application/x-httpd-php .php" >> /usr/local/httpd-2.4.25/conf/httpd.conf'
cd -

######## 安装 php 常用模块 ########

######## 方法1 ########

1
2
3
4
5
6
7
8
9
10
11
# 到http://pecl.php.net/上搜索下载需要的模块
# 网站很慢,I don't know why yet……
# 以zip模块安装为例
wget http://pecl.php.net/get/zip-1.13.2.tgz
tar zxf zip-1.13.2.tgz
cd zip-1.13.2
sudo /usr/local/php-5.6.28/bin/phpize
sudo ./configure --with-php-config=/usr/local/php-5.6.28/bin/php-config
sudo make && sudo make install
sudo sh -c 'echo "extension=/usr/local/php-5.6.28/lib/php/extensions/no-debug-zts-20131226/zip.so" >> /usr/local/php-5.6.28/etc/php.ini'
cd -

######## 方法2 ########

以安装cURL模块安装为例
1
2
3
4
5
6
7
sudo yum install curl-devel
cd php-5.6.28/ext/curl
sudo /usr/local/php-5.6.28/bin/phpize
sudo ./configure --with-php-config=/usr/local/php-5.6.28/bin/php-config
sudo make && sudo make install
sudo sh -c 'echo "extension=/usr/local/php-5.6.28/lib/php/extensions/no-debug-zts-20131226/curl.so" >> /usr/local/php-5.6.28/etc/php.ini'
cd -

######## 启动httpd ########

/usr/local/httpd-2.4.25/bin/apachectl restart
1
curl 127.0.0.1:80/index.php