码迷,mamicode.com
首页 > 其他好文 > 详细

源码安装lamp

时间:2017-10-18 19:45:20      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:lamp 源码编译

在实际环境中我们经常根据自己所处的公司环境进行配置,适合自己公司的配置。下面我们来介绍如何进行编译安装

安装前提

在CentOS7 系统:

关闭iptables
将selinux设置为disabled
apr-1.6.2.tar.gz      
httpd-2.4.27.tar.bz2                
php-7.1.10.tar.xz
apr-util-1.6.0.tar.gz  
mariadb-10.2.8-linux-x86_64.tar.gz  wordpress-4.8.1-zh_CN.tar.gz
安装工具包development tools

注意:这里安装需要按顺序进行的mariadb-->httpd-->php,mariadb和httpd安装顺序没有关系

源码编译httpd服务

在之前的apache博客中讲过为什么要安装apr和apr-util包,如果不懂请查看apache博客。

(1)源码编译安装apr

[root@localhost/usr/local/src]#tar xvf apr-1.6.2.tar.gz[root@localhost/usr/local/src/apr-1.6.2]#./configure --prefix=/app/apr[root@localhost/usr/local/src/apr-1.6.2]#make && make install

(2)源码编译安装apr-util

[root@localhost/usr/local/src]#tar xf apr-util-1.6.0.tar.gz[root@localhost apr-util-1.6.0]# yum install -y expat-devel
[root@localhost/usr/local/src/apr-util-1.6.0]#./configure --prefix=/app/apr-util --with-apr=/app/apr[root@localhost/usr/local/src/apr-util-1.6.0]#make && make install

(3)源码安装httpd

首先确认系统上是否有apache用户,如果没有需要创建

[root@localhost/usr/local/src]#useradd -r -m -d /app/website -s /sbin/nologin apache[root@localhost/usr/local/src]#tar xf httpd-2.4.27.tar.bz2

在编译安装httpd之前需要安装几个依赖包

[root@localhost/usr/local/src/httpd-2.4.27]#yum install -y pcre-devel apr-devel apr-util-devel openssl-devel

[root@localhost/usr/local/src/httpd-2.4.27]#./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/app/apr/ --with-apr-util=/app/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

[root@localhost/usr/local/src/httpd-2.4.27]#make -j 4 && make install

(4)设置环境变量

[root@localhost/etc/profile.d]#vim httpd24.sh

export PATH=/app/httpd24/bin:$PATH

[root@localhost/etc/profile.d]#source httpd24.sh

(5)设置man手册位置

[root@localhost/etc]#vim /etc/man_db.conf

23 MANDATORY_MANPATH                       /app/httpd24/man

(6)配置启动脚本

[root@localhost/app/httpd24]#cp bin/apachectl /etc/init.d/httpd24

(7)测试服务是否正常启动

技术分享已经监听80端口说明可以启动

http://192.168.4.60/ 技术分享

二进制安装mariadb

(1)二进制安装mariadb

[root@localhost/usr/local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql[root@localhost/usr/local/src]#tar xf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/[root@localhost/usr/local]#ln -sv mariadb-10.2.8-linux-x86_64/ mysql

(2)添加环境变量

[root@localhost/etc/profile.d]#vim mysql.sh

    PATH=/usr/local/mysql/bin:$PATH

(3)配置man手册

[root@localhost/usr/local/mysql/bin]#vim /etc/man_db.conf

    24 MANDATORY_MANPATH /usr/local/mysql/man

(4)创建启动脚本

[root@localhost/usr/local/mysql]#cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost/usr/local/mysql]#chkconfig --add mysqld

(5)配置主配置文件

[root@localhost/usr/local/mysql]#mkdir /etc/mysql

[root@localhost/usr/local/mysql]#cp support-files/my-large.cnf /etc/mysql/my.cnf

[root@localhost/usr/local/mysql]#vim /etc/mysql/my.cnf 

    27 [mysqld] 

    28 datadir = /app/mysqldb

(6)创建日志目录

[root@localhost/usr/local/mysql]#mkdir /var/log/mariadb

[root@localhost/usr/local/mysql]#setfacl -Rm u:mysql:rwx /var/log/mariadb/

(7)安装数据库

[root@localhost/usr/local/mysql]#scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb

(8)初始化数据库

[root@localhost~]#mysql_secure_installation 

(9)测试数据库是否安装成功

[root@localhost~]#mysql -u root -p

MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘127.0.0.1‘ IDENTIFIED BY ‘123456‘;

源码安装php

(1)解压缩并编译安装

[root@localhost/usr/local/src/php-7.1.10]#yum install -y libxml2-devel bzip2-devel libmcrypt-devel

[root@localhost/usr/local/src/php-7.1.10]#./configure --prefix=/app/php --enable-mysqlnd -- with-mysqli=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --enable-mbstring --with freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets -- with-apxs2=/app/httpd24/bin/apxs --with-mcrypt -- with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo[root@localhost/usr/local/src/php-7.1.10]#make && make install(2)配置主配置文件

[root@localhost/usr/local/src/php-7.1.10]#cp php.ini-production /etc/php.ini

(3)修改/etc/httpd/conf/httpd.conf

259 <IfModule dir_module>
260     DirectoryIndex index.php index.html
261 </IfModule>

512 AddType Application/x-httpd-php .php
513 AddType Application/x-httpd-php-source .phps

(4)测试能否与httpd连接成功

[root@localhost/app/httpd24/htdocs]#vim index.php

  1 <?php
 2         phpinfo();
 3 ?>

(5)测试是否能否可以和mariadb连接成功

[root@localhost/app/httpd24/htdocs]#vim index.php

<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
       echo "连接数据库失败!";
       $mysqli=null;
       exit;
}
       echo "连接数据库成功!";
       $mysqli->close();
       phpinfo();
?>

安装wordpress

(1)解压缩

[root@localhost/usr/local/src]#tar xf wordpress-4.8.tar.gz -C /app/httpd24/htdocs

(2)配置主配置文件

[root@localhost/app/httpd24/htdocs/wordpress]#cp wp-config-sample.php wp-config.php[root@localhost/app/httpd24/htdocs/wordpress]#vim wp-config.php

 23 define(‘DB_NAME‘, ‘wpdb‘);
24
25 /** MySQL database username */
26 define(‘DB_USER‘, ‘joah‘);
27
28 /** MySQL database password */
29 define(‘DB_PASSWORD‘, ‘123456‘);
30
31 /** MySQL hostname */
32 define(‘DB_HOST‘, ‘localhost‘);

http://192.168.4.59/wordpress/wp-admin/setup-config.php

测试其性能如何

[root@localhost/app/httpd24/htdocs/wordpress]#ab -c 10 -n 100 http://192.168.4.60/wordpress/

HTML transferred:       5209700 bytes
Requests per second:    25.25 [#/sec] (mean)    #在没有加速器性能还不错
Time per request:       396.061 [ms] (mean)

CentOS 6 源码编译

安装前环境准备 apr-1.6.2.tar.gz 
httpd-2.4.27.tar.bz2 
php-5.6.31.tar.xz 
xcache-3.2.0.tar.bz2 apr-util-1.6.0.tar.gz
mariadb-5.5.57-linux-x86_64.tar.gz wordpress-4.8.1-zh_CN.tar.gz

二进制安装mariadb

(1)二进制安装mariadb

[root@localhost/usr/local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql

[root@localhost/usr/local/src]#tar xf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/

[root@localhost/usr/local]#ln -sv mariadb-10.2.8-linux-x86_64/ mysql

(2)添加环境变量

[root@localhost/etc/profile.d]#vim mysql.sh

    PATH=/usr/local/mysql/bin:$PATH

(3)配置man手册

[root@localhost/usr/local/mysql/bin]#vim /etc/man_db.conf

    24 MANDATORY_MANPATH /usr/local/mysql/man

(4)创建启动脚本

[root@localhost/usr/local/mysql]#cp support-files/mysql.server /etc/init.d/mysqld

[root@localhost/usr/local/mysql]#chkconfig --add mysqld

(5)配置主配置文件

[root@localhost/usr/local/mysql]#mkdir /etc/mysql

[root@localhost/usr/local/mysql]#cp support-files/my-large.cnf /etc/mysql/my.cnf

[root@localhost/usr/local/mysql]#vim /etc/mysql/my.cnf

    27 [mysqld] 

    28 datadir = /app/mysqldb

(6)创建日志目录

[root@localhost mysql]# touch /var/log/mysqld.log

(7)安装数据库

[root@localhost/usr/local/mysql]#scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb

(8)初始化数据库

[root@localhost~]#mysql_secure_installation

(9)测试数据库是否安装成功

[root@localhost~]#mysql -u root -p

MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘127.0.0.1‘ IDENTIFIED BY ‘123456‘;

编译安装httpd服务

(1)解压缩httpd源码包

[root@localhost httpd-2.4.27]# yum install -y apr-devel apr-util-devel openssl-devel pcre-devel

[root@localhost httpd-2.4.27]# tar xf apr-1.6.2.tar.gz

[root@localhost httpd-2.4.27]# tar xf apr-util-1.6.0.tar.gz

[root@localhost httpd-2.4.27]# mv apr-1.6.2 httpd-2.4.27/srclib/

[root@localhost httpd-2.4.27]# mv apr-util-1.6.0 httpd-2.4.27/srclib/apr-util

[root@localhost httpd-2.4.27]# ./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

[root@localhost httpd-2.4.27]# make && make install

(2)配置环境变量

[root@localhost httpd24]# vim /etc/profile.d/httpd24.sh

    PATH=/app/httpd24/bin:$PATH 

(3)配置启动脚本

[root@localhost httpd24]# cp /etc/init.d/httpd /etc/init.d/httpd24

[root@localhost httpd24]# vim /etc/init.d/httpd24

apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/apachectl}
prog=httpd
pidfile=${PIDFILE-/app/httd24/logshttpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

(4)测试是否配置成功

[root@localhost httpd24]# service httpd24 start

编译安装php

安装方式一:基于php模块安装

(1)解压缩并编译安装

[root@localhost php-5.6.4]#yum install libxml2-devel bzip2-devel libmcrypt-devel

[root@localhost php-5.6.31]# ./configure --prefix=/app/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

[root@localhost php-5.6.4]# make && make install

(2)配置主配置文件

[root@localhost php-5.6.31]# cp php.ini-production /etc/php.ini

(3)在httpd.conf中配置

259 <IfModule dir_module>
260     DirectoryIndex index.php index.html
261 </IfModule>

512 AddType Application/x-httpd-php .php
513 AddType Application/x-httpd-php-source .phps

接下的步骤和CentOS 7中的配置类似,请参考上述配置。

(4)配置环境变量

[root@localhost php]# vim /etc/profile.d/php.sh

PATH=/app/php/bin:$PATH

[root@localhost php]# source /etc/profile.d/php.sh

(5)测试是否可以与apache通信

[root@localhost htdocs]# vim index.php

?>

(6)测试是否可以与mysql通信

<?php
       $msyqli=new mysqli("192.168.4.132","root","123456");
       if(mysqli_connect_errno()){
               echo "failure";
               $mysqli=null;
               exit;
       }
               echo "ok";
               $mysqli->close;
               phpinfo();
?>

(7)安装wordpress

步骤和CentOS7安装一样可以参考

(8)源码编译安装加速器

[root@localhost xcache-3.2.0]# phpize #生成configure

[root@localhost xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/app/php/bin/php-config

[root@localhost xcache-3.2.0]# make && make install

安装方式二:基于php-fpm模块安装

[root@localhost php-5.6.31]# ./configure --prefix=/app/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc/php5 --with-config-file-scan-dir=/etc/php5.d --with-bz2[root@localhost php-5.6.31]# make && make install

(2)准备启动脚本文件

[root@localhost php-5.6.31]# cp sapi/fpm/init.d.php-fpm.in /etc/rc.d/init.d/php-fpm

[root@localhost php-5.6.31]# chmod +x /etc/rc.d/init.d/php-fpm

[root@localhost php-5.6.31]# chkconfig --add php-fpm

(3)配置环境变量

[root@localhost php-5.6.31]# vim /etc/profile.d/php-fpm.sh

[root@localhost php-5.6.31]# source /etc/profile.d/php-fpm.sh

(4)创建主配置文件

[root@localhost etc]# mkdir /etc/php5

[root@localhost etc]# cp /usr/local/src/php-5.6.31/php.ini-production /etc/php5/php.ini

(5)准备服务配置文件

[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf

(6)编辑/app/httpd24/conf/httpd.conf

取消注释,启用此模块

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so

在配置文件末尾追加如下

AddType Application/x-httpd-php .php
AddType Application/x-httpd-php-source .phps
ProxyRequests off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1

(7)启动php-fpm服务

[root@localhost etc]# service php-fpm start

(8)测试是否可以与mysql和httpd连接成功

http://192.168.4.132/

(9)安装wordpress

安装过程和CentOS 7中安装一样,可以参考上述过程

(10)测试性能如何

Requests per second:    579.84 [#/sec] (mean)
Time per request:       17.246 [ms] (mean)
Time per request:       1.725 [ms] (mean, across all concurrent requests)
Transfer rate:          37900.46 [Kbytes/sec] received



本文出自 “Joah” 博客,请务必保留此出处http://merit.blog.51cto.com/10757694/1973795

源码安装lamp

标签:lamp 源码编译

原文地址:http://merit.blog.51cto.com/10757694/1973795

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!