阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 6.7 编译安装LAMP

201次阅读
没有评论

共计 9183 个字符,预计需要花费 23 分钟才能阅读完成。

CentOS 6.7 编译安装 LAMP

一、环境和软件包准备

[root@linuxidc ~]# cat/etc/RedHat-release
CentOS release 6.7 (Final)
[root@linuxidc ~]# uname -rm
2.6.32-573.el6.x86_64 x86_64

使用 163 的 yum 源

cd /etc/yum.repos.d/
wget http://mirrors.163.com/.help/CentOS6-Base-163.repo

关闭防火墙和 selinux

setenforce 0
service iptables stop

需要准备的软件包

    mkdir  /tools; cd /tools

        apr-1.5.2.tar.gz

        apr-util-1.5.4.tar.gz

        httpd-2.4.16.tar.gz

        curl-7.45.0.tar.gz   

        gettext-0.19.5.tar

        libmcrypt-2.5.7.tar.gz

        mcrypt-2.6.8.tar.gz

        lpng1618.zip

        mod_fastcgi-2.4.6.tar.gz

        MySQL-5.6.26.tar.gz

        php-5.5.30.tar.gz

        phpMyAdmin-4.5.0.2-all-languages.zip

        libpng-1.2.53.tar

        freetype-2.4.0.tar

        jpegsrc.v9.tar

        opencart-2.1.0.1.zip

        zlib-1.2.3.tar

        ……………….

        注. 版本不一定要一样。

二、安装依赖环境

yum -y groupinstall”Development Libraries”
yum -y groupinstall”Desktop Platform Development”
yum -y groupinstall “X Software Development”
yum -y install wget gcc gcc-c++ ncurses ncurses-devel cmakemake perl bison openssl openssl-devel gcc* libxml2 libxml2-devel curl-devellibjpeg* libpng* freetype* pcre-devel bzip2-devel libmcrypt-devel

三、编译安装 apr
1、编译安装 apr

cd /tools
tar xjvfapr-1.5.2.tar.bz2 -C /usr/src/;cd /usr/src/apr-1.5.2/
./configure–prefix=/usr/local/apr
make && makeinstall

2、编译安装 apr-util

cd /tools/
tar xjvfapr-util-1.5.4.tar.bz2 -C /usr/src/;cd /usr/src/apr-util-1.5.4
./configure–prefix=/usr/local/apr-util –with-apr=/usr/local/apr/
make  && make install
 

四、编译安装 apache

cd  /tools
tar xjvf httpd-2.4.17.tar.bz2  -C /usr/src/;cd /usr/src/httpd-2.4.17
 
./configure–prefix=/usr/local/apache2 –with-apr=/usr/local/apr–with-apr-util=/usr/local/apr-util/ –with-mpm=event –enable-so–enable-mods-shared=all –enable-proxy=shared –enable-proxy-balancer=shared–enable-prosy-http=shared –enable-proxy-ajp –enable-deflate –enable-cache–enable-disk-cache –enable-mem-cachemake &&  make  install

五、编译安装 mysql
1、安装 mysql

cd  /tools
tar xzvfmysql-5.6.26.tar.gz -C /usr/src/;cd /usr/src/mysql-5.6.26
cmake-DENABLE_DOWNLOADS=1 -DCMAKE_INSTALL_PREFIX=/opt/mysql –with-mysql=mysqlnd –with-pdo-mysql=mysqlnd –with-mysqli=mysqlnd
make&& make install
 
2、创建相关设置
mkdir/data/mysql/{mysql-data,mysql-logs} –pv
groupadd -r -g 306 mysql
useradd -r -g 306 -u 306mysql
chown -R mysql.mysql/data/mysql/

编辑配置文件

vim  /etc/my.cnf

添加如下内容

[mysql]
prompt= (\u@\h)[\d]>
 
[client]
port            = 3306
socket          = /tmp/mysql3306.sock
default_character_set = utf8 
 
[mysqld]
user= mysql
port            = 3306
socket          = /tmp/mysql3306.sock 
datadir              =/data/mysql/mysql-data
pid_file        = /data/mysql/mysql-data/mysql.pid                       
log-bin        = /data/mysql/mysql-logs/mysql-bin
log-error  = /data/mysql/mysql-logs/mysql.err

 

详细内容参考附件 my.cnf

编辑启动脚本

vim/etc/rc.d/init.d/mysqld

添加和修改如下三行

basedir=/opt/mysql
datadir=/data/mysql/mysql-data
defaultconf=/etc/my.cnf

详细内容参考附件 mysqld 文件

设置启动脚本权限

chmod +x/etc/rc.d/init.d/mysqld

3、初始化数据库并启动
初始化数据库,执行完成后如果看到有两个 OK,说明初始化成功了。

/opt/mysql/scripts/mysql_install_db–user=mysql –datadir=/data/mysql/mysql-data/ –basedir=/opt/mysql/  –defaults-file=/etc/my.cnf

启动数据库

[root@linuxidc tools]#/etc/rc.d/init.d/mysqld start
Starting MySQL………SUCCESS!

 

把 mysql 命令加入环境变量

PATH=$PATH:/opt/mysql/bin/
 
chkconfig –add mysqld
chkconfig mysqld on
[root@linuxidc tools]# chkconfig –list mysqld
mysqld            0:off1:off2:on3:on4:on5:on6:off

 

使用 service 命令管理 mysql 进程

[root@linuxidc tools]# service mysqld stop
Shutting down MySQL.SUCCESS!

 

六、编译安装 php
        1、安装 curl
cd  /tools
tar xzvf curl-7.45.0.tar.gz-C /usr/src/;cd /usr/src/curl-7.45.0
./configure–prefix=/usr/local/curl && make && make install

        2、安装 libmcrypt
cd  /tools
tar xzvflibmcrypt-2.5.8.tar.gz -C /usr/src/;cd /usr/src/libmcrypt-2.5.8/
./configure  –prefix=/usr/local/libmcrypt && make&& make install

        3、安装 mhash

cd  /tools
tar xzvfmhash-0.9.9.9.tar.gz -C /usr/src/;cd /usr/src/mhash-0.9.9.9
./configure–prefix=/usr/local/mhash && make && make install
    ln -s /usr/local/lib/libmhash.a/usr/lib/libmhash.a
    ln -s /usr/local/lib/libmhash.la/usr/lib/libmhash.la
    ln -s /usr/local/lib/libmhash.so/usr/lib/libmhash.so
    ln -s /usr/local/lib/libmhash.so.2/usr/lib/libmhash.so.2
    ln -s/usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
 
echo“/usr/local/lib”>>/etc/ld.so.conf
ldconfig

        4、安装 mcrypt

cd  /tools
tar xzvf mcrypt-2.6.8.tar.gz -C /usr/src/;cd/usr/src/mcrypt-2.6.8
./configure –prefix=/usr/local/mcrypt  –with-libmcrypt=/usr/local/libmcrypt/&& make && make install

        5、安装 gettext

cd  /tools
tar xvf gettext-0.19.5.tar-C /usr/src/;cd /usr/src/gettext-0.19.5
./configure–prefix=/usr/local/gettext && make && make install

        6、安装 libxml2
cd  /tools
tar xzvflibxml2-2.6.30.tar.gz -C /usr/src/;cd /usr/src/libxml2-2.6.30/
./configure–prefix=/usr/local/libxml2  &&make && make install

 
7、安装 php
cd  /tools
tarxzvf php-5.5.30.tar.gz -C /usr/src/;cd /usr/src/php-5.5.30
./configure–prefix=/opt/php –with-apxs2=/usr/local/apache2/bin/apxs–with-curl=/usr/local/curl/ –with-mcrypt=/usr/local/mcrypt/–with-mysql=/opt/mysql/ –with-gettext=/usr/local/gettext/    –with-mysqli –with-bz2 –with-mhash–enable-sockets –enable-mbstring –enable-zip –enable-bcmath–enable-calendar –enable-exif –enable-ftp –enable-fpm  –with-openssl–with-libxml-dir=/usr/local/libxml2/
make&& make install

      8、设置 phpinfo 和 phpadmin
        (1)、设置 phpinfo 页面

cd/usr/local/apache2/htdocs/
 
cat > index.php <<EOF
<?php
phpinfo();
?>
EOF

修改 apache 配置文件

vim  /usr/local/apache2/conf/httpd.conf

在 DirectoryIndex 后加上 index.php, 如下

DirectoryIndexindex.php  index.html

在末尾加上

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

访问 http://yourip

看到如下界面,说明 lamp 安装成功。

CentOS 6.7 编译安装 LAMP

        (2)、设置 phpadmin

        cd  /tools
        unzipphpMyAdmin-4.5.0.2-all-languages.zip
        mvphpMyAdmin-4.5.0.2-all-languages /usr/local/apache2/htdocs/phpadmin
        cd/usr/local/apache2/htdocs/phpadmin
        cpconfig.sample.inc.php config.inc.php
        vim  config.inc.php

        修改如下内容,在 $cfg[‘blowfish_secret’] 后面加上任意字符,给密码加密

        把 $cfg[‘Servers’][$i][‘host’]的 localhost 改成 127.0.0.1

CentOS 6.7 编译安装 LAMP

设置 mysql 密码

mysqladmin -u root password abc123
mysqladmin -u root -h 127.0.0.1 passwordabc123

登陆 mysql

mysql -u root -pabc123
(root@127.0.0.1)[(none)]>grant allprivileges on *.* to root@’%’ identified by ‘root’;
Query OK, 0 rows affected (0.00 sec)

用浏览器访问 http://yourip/phpadmin

看到如下界面,使用你的 mysql 用户名和密码登陆。

CentOS 6.7 编译安装 LAMPCentOS 6.7 编译安装 LAMP

            (3)、修改 php.in
到此 LAMP 基本安装完成,可通过调整 php.ini 实现一些自定义的功能。

cd /usr/src/php-5.5.30/
cp php.ini-production /opt/php/lib/php.ini

七、扩展 PHP 模块
有时候我们安装完成 php 后,发现有有需要的模块没有安装,但我们又不希望重新编译安装 php, 这时就可以使用动态扩展的方法安装 php 的扩展模块。

以下以 GD 模块和 zlib 模块为例子:

1、安装 freetype

cd  /tools
tar xjvffreetype-2.4.0.tar.bz2 -C /usr/src/;cd /usr/src/freetype-2.4.0/
./configure–prefix=/usr/local/freetype && make && make install

2、安装 jpeg

cd  /tools
tar xzvf jpegsrc.v9.tar.gz-C /usr/src/;cd /usr/src/jpeg-9
CFLAGS=”-O3-fPIC” ./configure –prefix=/usr/local/jpeg && make &&make install
 
        mkdir -p /usr/local/jpeg/include
        mkdir -p /usr/local/jpeg/lib
        mkdir -p /usr/local/jpeg/bin
        mkdir -p /usr/local/jpeg/man/man1

3、安装 libpng

cd /tools
tar xzvflibpng-1.2.53.tar.gz -C /usr/src/;cd /usr/src/libpng-1.2.53
CFLAGS=”-O3-fPIC” ./configure –prefix=/usr/local/libpng && make &&make install

4、安装 gd

cd/usr/src/php-5.5.30/ext/gd/
   
[root@linuxidc gd]#/opt/php/bin/phpize
Configuring for:
PHP Api Version:        20121113
Zend Module Api No:      20121212
Zend Extension Api No:  220121212

 
./configure–with-php-config=/opt/php/bin/php-config –with-jpeg-dir=/usr/local/jpeg –with-png-dir=/usr/local/libpng  –with-freetype-dir=/usr/local/freetype && make && makeinstall

5、安装 zlib

cd  /tools
tar xzvf zlib-1.2.3.tar.gz -C/usr/src/;cd /usr/src/zlib-1.2.3
./configure–prefix=/usr/local/zlib && make && make install
cd /usr/src/php-5.5.30/ext/zlib/
mv config0.m4 config.m4
 
[root@linuxidc zlib]#/opt/php/bin/phpize
Configuring for:
PHP Api Version:        20121113
Zend Module Api No:      20121212
Zend Extension Api No:  220121212

./configure–with-php-config=/opt/php/bin/php-config && make && makeinstall
 
[root@linuxidc zlib]# ls/opt/php/lib/php/extensions/no-debug-zts-20121212/
gd.so  opcache.so zlib.so

6、编辑 php.ini 文件
vim /opt/php/lib/php.ini

在末尾添加如下几行内容

extension_dir =/opt/php/lib/php/extensions/no-debug-zts-20121212/
extension=gd.so
extension=zlib.so

 
/opt/php/bin/php –m

重启 httpd 服务

/usr/local/apache2/bin/apachectlrestart

7、验证是否安装成功
用浏览器访问 phpinfo 查看是否有了 GD 模块和 zlib 模块

http://youip

CentOS 6.7 编译安装 LAMPCentOS 6.7 编译安装 LAMP

Php GD 模块和 zlib 模块安装完成。

八、搭建网站服务
我们使用 opencart 这个开源项目作为 WEB 站点实验

cd /tools
unzip opencart-2.1.0.1.zip;cd opencart-2.1.0.1
mv upload/ /usr/local/apache2/htdocs/opencart

浏览器访问 http://youip/opencart

CentOS 6.7 编译安装 LAMP

站点搭建完成。

九、设置防火墙

[root@linuxidc tools]# iptables -tfilter -I INPUT -p tcp –dport 80 -j ACCEPT
[root@linuxidc tools]# iptables -tfilter -I INPUT -p tcp –dport 443 -j ACCEPT
[root@linuxidc tools]# iptables -tfilter -I INPUT -p tcp –dport 22 -j ACCEPT
[root@linuxidc tools]# iptables -tfilter -I INPUT -p tcp –dport 3306 -j ACCEPT
[root@linuxidc tools]# iptables -tfilter -P INPUT DROP
[root@linuxidc tools]# iptables -tfilter -I INPUT  -m state –stateRELATED,ESTABLISHED

本文相关附件下载

—————————————— 分割线 ——————————————

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2015 年资料 /10 月 /27 日 /CentOS 6.7 编译安装 LAMP/

下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm

—————————————— 分割线 ——————————————

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

LAMP 平台安装 Xcache 和 Memcached 加速网站运行  http://www.linuxidc.com/Linux/2015-06/118835.htm 

CentOS 7 下搭建 LAMP 平台环境  http://www.linuxidc.com/Linux/2015-06/118818.htm

CentOS 6.5 系统安装配置 LAMP(Apache+PHP5+MySQL)服务器环境 http://www.linuxidc.com/Linux/2014-12/111030.htm

Ubuntu 14.04 配置 LAMP+phpMyAdmin PHP(5.5.9)开发环境  http://www.linuxidc.com/Linux/2014-10/107924.htm

Ubuntu 14.10 下安装 LAMP 服务图文详解  http://www.linuxidc.com/Linux/2014-12/110082.htm

LAMP 结合 NFS 构建小型博客站点  http://www.linuxidc.com/Linux/2015-08/121029.htm 

本文永久更新链接地址:http://www.linuxidc.com/Linux/2015-10/124582.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计9183字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中