一、环境和软件包准备1
2
3
4
| [iyunv@yy ~]# cat/etc/redhat-release
CentOS release 6.7 (Final)
[iyunv@yy ~]# uname -rm
2.6.32-573.el6.x86_64 x86_64
|
使用163的yum源
关闭防火墙和selinux
1
2
| 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
……………….
注.版本不一定要一样。
二、安装依赖环境1
2
3
4
| 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
|
三、编译安装apr1、编译安装apr1
2
3
4
| 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-util1
2
3
4
| 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
|
四、编译安装apache1
2
3
4
| 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
|
五、编译安装mysql1、安装mysql1
2
3
4
| 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、创建相关设置1
2
3
4
| 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 添加如下内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| [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 添加和修改如下三行
1
2
3
| basedir=/opt/mysql
datadir=/data/mysql/mysql-data
defaultconf=/etc/my.cnf
|
详细内容参考附件mysqld文件
设置启动脚本权限 1
| chmod +x/etc/rc.d/init.d/mysqld
|
3、初始化数据库并启动初始化数据库,执行完成后如果看到有两个OK,说明初始化成功了。 1
| /opt/mysql/scripts/mysql_install_db--user=mysql --datadir=/data/mysql/mysql-data/ --basedir=/opt/mysql/ --defaults-file=/etc/my.cnf
|
启动数据库
1
2
| [iyunv@yuanyang tools]#/etc/rc.d/init.d/mysqld start
Starting MySQL.........SUCCESS!
|
把mysql命令加入环境变量 1
2
3
4
5
6
| PATH=$PATH:/opt/mysql/bin/
chkconfig --add mysqld
chkconfig mysqld on
[iyunv@yy tools]# chkconfig --list mysqld
mysqld 0:off1:off2:on3:on4:on5:on6:off
|
使用service命令管理mysql进程 1
2
| [iyunv@yy tools]# service mysqld stop
Shutting down MySQL.SUCCESS!
|
六、编译安装php 1、安装curl1
2
3
| 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、安装libmcrypt1
2
3
| 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、安装mhash1
2
3
4
5
6
7
8
9
10
11
| 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、安装mcrypt1
2
3
| 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、安装gettext1
2
3
| 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、安装libxml21
2
3
| 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、安装php1
2
3
4
| 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页面1
2
3
4
5
6
7
| cd/usr/local/apache2/htdocs/
cat > index.php <<EOF
<?php
phpinfo();
?>
EOF
|
修改apache配置文件 vim /usr/local/apache2/conf/httpd.conf 在DirectoryIndex 后加上index.php,如下 1
| DirectoryIndexindex.php index.html
|
在末尾加上 1
2
| AddTypeapplication/x-httpd-php .php .phtml
AddType application/x-httpd-php-source.phps
|
访问http://yourip 看到如下界面,说明lamp安装成功。 (2)、设置phpadmin1
2
3
4
5
6
| 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密码 1
2
| mysqladmin -u root password abc123
mysqladmin -u root -h 127.0.0.1 passwordabc123
|
登陆mysql 1
2
3
| 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用户名和密码登陆。 (3)、修改php.in到此LAMP基本安装完成,可通过调整php.ini实现一些自定义的功能。 1
2
| cd /usr/src/php-5.5.30/
cp php.ini-production /opt/php/lib/php.ini
|
七、扩展PHP模块有时候我们安装完成php后,发现有有需要的模块没有安装,但我们又不希望重新编译安装php,这时就可以使用动态扩展的方法安装php的扩展模块。 以下以GD模块和zlib模块为例子: 1、安装freetype1
2
3
| 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、安装jpeg1
2
3
4
5
6
7
8
| 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、安装libpng1
2
3
| 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、安装gd1
2
3
4
5
6
7
| cd/usr/src/php-5.5.30/ext/gd/
[iyunv@yuanyang gd]#/opt/php/bin/phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
|
1
| ./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、安装zlib1
2
3
4
5
6
7
8
9
10
11
| 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
[iyunv@yuanyang zlib]#/opt/php/bin/phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
|
1
2
3
4
| ./configure--with-php-config=/opt/php/bin/php-config && make && makeinstall
[iyunv@yuanyang 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 在末尾添加如下几行内容 1
2
3
| extension_dir =/opt/php/lib/php/extensions/no-debug-zts-20121212/
extension=gd.so
extension=zlib.so
|
重启httpd服务 1
| /usr/local/apache2/bin/apachectlrestart
|
7、验证是否安装成功用浏览器访问phpinfo查看是否有了GD模块和zlib模块 http://youip Php GD模块和zlib模块安装完成。 八、搭建网站服务 我们使用opencart这个开源项目作为WEB站点实验
1
2
3
| 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
站点搭建完成。 九、设置防火墙1
2
3
4
5
6
| [iyunv@yuanyang tools]# iptables -tfilter -I INPUT -p tcp --dport 80 -j ACCEPT
[iyunv@yuanyang tools]# iptables -tfilter -I INPUT -p tcp --dport 443 -j ACCEPT
[iyunv@yuanyang tools]# iptables -tfilter -I INPUT -p tcp --dport 22 -j ACCEPT
[iyunv@yuanyang tools]# iptables -tfilter -I INPUT -p tcp --dport 3306 -j ACCEPT
[iyunv@yuanyang tools]# iptables -tfilter -P INPUT DROP
[iyunv@yuanyang tools]# iptables -tfilter -I INPUT -m state --stateRELATED,ESTABLISHED
|
[url=]mysql主配置文件[/url] [url=][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
binlog_format = mixed
sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION"
character_set_server = utf8
collation_server = utf8_bin
max_connections = 3000
max_connect_errors = 50
skip-external-locking
skip_name_resolve
lower_case_table_names=0
back_log = 128
table_open_cache = 512
open-files-limit = 65535
max_allowed_packet = 16M
thread_cache_size = 64
thread_concurrency = 8
binlog_cache_size = 1M
max_heap_table_size =1G
tmp_table_size = 500M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
sort_buffer_size = 8M
join_buffer_size = 8M
query_cache_size = 128M
query_cache_limit = 4M
event_scheduler = ON
#skip-innodb
default-storage-engine = innodb
innodb_buffer_pool_size = 1G
innodb_additional_mem_pool_size = 16M
innodb_flush_log_at_trx_commit = 2
innodb_open_files=65535
innodb_data_home_dir = /data/mysql/mysql-data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir= /data/mysql/mysql-data
innodb_log_files_in_group = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_flush_method=O_DIRECT
innodb_lock_wait_timeout = 120
innodb_max_dirty_pages_pct = 90
innodb_thread_concurrency = 8
key_buffer_size = 64M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 2G
myisam_repair_threads = 1
myisam_recover
wait_timeout = 864000
interactive_timeout = 864000
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
#safe-updates
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout[/url]
|