lanmp表示的是Linux,apache,nginx,mysql,php的简称,目前支持三种环境安装,即是lamp,lnmp,lnamp,也是linux服务器WEB环境一键安装包,可去wdlinux官网下载。
MYSQL安装
软件包依赖yum install gcc gcc-c++ make cmake ncurses-developenssl-devel bison zlib-devel
1.get mysql-5.6.10.tar.gz
tar zxf mysql-5.6.10.tar.gz
cd mysql-5.6.10
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql \
-DMYSQL_DATADIR=/usr/local/lnmp/mysql/data \
-DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all
然后make && make install
重新编译时,需要清除旧的对象文件和缓存信息
make clean
rm -fr CmakeCache.
useradd -M -s /sbin/nologin mysql
cd /usr/local/lnmp/mysql
cp support-file/my-medium.cnf /etc/my.cnf
chown -R mysql.mysql .
cd scripts/
./mysql_install_db --user=mysql --basedir=/usr/local/lnmp/mysql/--datadir=/usr/local/lnmp/mysql/data/
cd mysql/
chown -R root .
chown -R mysql data
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
/etc/init.d/mysqld start
vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin
source ~/.bash_profile
/etc/init.d/mysqld restart
mysql_secure_installation #按提示完成 mysql 安全设置,生产环境推荐使用
Nginx安装
yum install pcre-devel -y
tar zxf nginx-1.2.7.tar.gz
vi auto/cc/gcc
注释CFLAGS="$CFLAGS -g"
vi src/core/nginx.h
#define NGINX_VER "nginx" 修改此行,去掉后面的NGINX_VERSION,这样编译后外界无法获取程序的版本号
cd nginx-1.2.7
./configure --help
./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module--with-http_stub_status_module
然后make && make install
ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/
vi /usr/local/lnmp/nginx/conf/nginx.conf
#user nginx nginx ; ##1行
location / { ##43行
root html;
index index.html index.htm;
}
location /status {
stub_status on;
access_log off;
}
nginx -t ##检测语法
nginx ##运行 nginx
nginx -s reload ##重载主配置文件
nginx -s stop ##关闭 nginx
浏览器输入ip/status
加密证书通过https访问
vi nginx.conf
打开 HTTPS server 下的所有注释
修改 server_name 主机名;
修改 ssl_certificate_key cert.pem;
cd /etc/pki/tls/certs
make cert.pem
cp cert.pem /usr/local/lnmp/nginx/conf/
nginx -t
nginx -s reload
netstat -antpl ##443端口就是https打开的
浏览器输入https://server1.example.com
两个虚拟主机(纯静态-html 支持
cd /
mkdir /www
cd /www
mkdir linux.org cd linux.org echo www.linux.org > index.html
mkdir westos.org cd westos.org echo www.westos.org > index.html\
vi nginx.conf
在最后添加:
server {
listen 80;
server_name www.westos.org;
access_log logs/westos.org.access.log main;
location / {
index index.html;
root /www/westos.org;
}
}
server {
listen 80;
server_name www.linux.org;
access_log logs/linux.org.access.log main;
location / {
index index.html;
root /www/linux.org;
}
}
}
并打开下列注释
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status$body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
在宿主机上vi /etc/hosts
192.168.0.1 www.westos.org www.linux.org
测试结果
在浏览器分别输入www.westos.org www.linux.org 得到相应主机名
一个简单的负载均衡的示例,把www.domain.com均衡到本机不同的端口,也可以改为均衡到不同的地址上
在server2,server3上安装启动httpd
cd /var/www/html
分别输入echo `hostname` > index.html ##便于以后测试分别
在server1上 vi nginxc.conf
在http { 里添加
upstream westos {
server 192.168.0.2:80;
server 192.168.0.3:80;
修改
server {
listen 80;
server_name www.westos.org;
access_log logs/westos.org.access.log main;
location / {
proxy_pass http://westos;
}
}
相关配置文档可以在wiki.nginx.org 里查看
Php 安装
tar zxf libiconv-1.13.1.tar.gz ##加强系统对支持字符编码转换的功能
cd libiconv-1.13.1/
./configure --libdir=/usr/local/lib64
make && make install
ldconfig /usr/local/lib64 ##加载上述安装
tar jxf libmcrypt-2.5.8.tar.bz2 ##mcrypt mhash 是 php 加密算法扩展库
cd libmcrypt-2.5.8
./configure –libdir=/usr/local/lib64
make && make install
ldconfig /usr/local/lib64
cd libltdl
./configure –libdir=/usr/local/lib64 –enable-ltdl-install
make && make install
ldconfig /usr/local/lib64
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure –libdir=/usr/local/lib64
make && make install
ldconfig /usr/local/lib64
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8/
./configure --libdir=/usr/local/lib64
make && make install
#./configure 时可能会报这个错:/bin/rm: cannot remove`libtoolT’: No such file or directory 直接忽略
cd /usr/local/lnmp/mysql
ln -s lib lib64
软件包依赖性:
yum install net-snmp-devel curl-devel libxml2-devel libpng-devel libjpeg-develfreetype-
devel gmp-devel openldap-devel -y
tar jxf php-5.3.6.tar.bz2
cd php-5.3.6
./configure --prefix=/usr/local/lnmp/php--with-config-file-path=/usr/local/lnmp/php/etc--with-mysql=/usr/local/lnmp/mysql/ --with-openssl --with-snmp --with-gd--with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir--with-freetype-dir --with-pear --with-gettext --with-gmp--enable-inline-optimization --enable-soap --enable-ftp --enable-sockets--enable-mbstring --with-mysqli=/usr/local/lnmp/mysql/bin/mysql_config--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-libdir=lib64--with-mcrypt --with-mhash
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/lnmp/php/etc/php.ini
cd sapi/fpm/
cp init.d.php-fpm /etc/ini.t/fpm
chmod +x /etc/init.d/fpm
cd /usr/local/lnmp/php/etc/
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
pid=run/php-fpm.pid ##去掉注释
vi /usr/local/lnmp/php/etc/php.ini
cgi.fix_pathinfo=0 ## 防止nginx文件类型错误解析漏洞
/etc/init.d/fpm start
cd /usr/local/lnmp/nginx/conf
vi nginx.conf
在server中的location 中修改
index index.php index.html index.htm;
并打开如下
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
nginx -t
nginx -s reload
cd html
vi index.php
phpinfo(();
?>
/etc/init.d/mysqld start
输入ip/index.php
发布论坛
get Discuz_X2.5_SC_UTF8.zip
unzip Discuz_X2.5_SC_UTF8.zip -C /usr/local/lnmp/nginx/html
mv upload/ bbs
cd bbs/
chown -R nginx.nginx bbs/
浏览器输入ip/bbs/install/
Memcache 是 danga.com 的一个开源项目,它是一个高性能的分布式的内存对象缓存系统,通过在
内存里维护一个统一的巨大的 Hash 表,能够用来存储各种格式的数据。可以类比于 MySQL 这样的服
务,而 PHP 扩展的 Memcache 实际上是连接 Memcache 的方式
yum install libevent libevent-devel -y
tar zxf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure
make && make install
memcached -u root -m 10 -d
vi ~/.bash_profile
PATH=$PATH:$HOME/bin:/usr/local/lnmp/mysql/bin:/local/lnmp/php/bin/
source ~/.bash_profile
yum install autoconf -y
tar zxf memcache-2.2.5.tar.gz
cd memcache-2.2.5
phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
cd /usr/local/lnmp/php/etc/
vi php.ini
修改
extension=memcache.so
/etc/init.d/fpm reload
cd memcache-2.2.5
cp memcache.php /usr/local/lnmp/nginx/html/
cd /usr/local/lnmp/nginx/html/
vi memcache.php
define('ADMIN_PASSWORD','westos');
输入 ip/memchace.php