Centos 6.7 编译安装LAMP
一、环境和软件包准备
[[email protected] ~]# cat/etc/redhat-release CentOS release 6.7 (Final) [[email protected] ~]# 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= (\[email protected]\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
启动数据库
[[email protected] tools]#/etc/rc.d/init.d/mysqld start Starting MySQL.........SUCCESS!
把mysql命令加入环境变量
PATH=$PATH:/opt/mysql/bin/ chkconfig --add mysqld chkconfig mysqld on [[email protected] tools]# chkconfig --list mysqld mysqld 0:off1:off2:on3:on4:on5:on6:off
使用service命令管理mysql进程
[[email protected] 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安装成功。
(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
设置mysql密码
mysqladmin -u root password abc123 mysqladmin -u root -h 127.0.0.1 passwordabc123
登陆mysql
mysql -u root -pabc123 ([email protected])[(none)]>grant allprivileges on *.* to [email protected]'%' identified by 'root'; Query OK, 0 rows affected (0.00 sec)
用浏览器访问http://yourip/phpadmin
看到如下界面,使用你的mysql用户名和密码登陆。
(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/ [[email protected] 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 [[email protected] 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 [[email protected] 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
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
站点搭建完成。
九、设置防火墙
[[email protected] tools]# iptables -tfilter -I INPUT -p tcp --dport 80 -j ACCEPT [[email protected] tools]# iptables -tfilter -I INPUT -p tcp --dport 443 -j ACCEPT [[email protected] tools]# iptables -tfilter -I INPUT -p tcp --dport 22 -j ACCEPT [[email protected] tools]# iptables -tfilter -I INPUT -p tcp --dport 3306 -j ACCEPT [[email protected] tools]# iptables -tfilter -P INPUT DROP [[email protected] tools]# iptables -tfilter -I INPUT -m state --stateRELATED,ESTABLISHED
转载于:https://blog.51cto.com/yylinfan/1706473