LNMP是一个基于CentOS/Debian编写的Nginx、PHP、MySQL、phpMyAdmin、eAccelerator一键安装包。可以在VPS、独立主机上轻松的安装LNMP生产环境。
简介
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。
Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。
Mysql是一个小型关系型数据库管理系统。
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
环境:centos6.5 32位
版本:nginx-1.9.4.tar.gz
版本:mysql-5.5.15-linux2.6-i686.tar.gz
版本:php-5.5.8.tar.bz2
安装nginx
版本:nginx-1.9.4.tar.gz
[[email protected] ~]# yum --disablerepo=\* --enablerepo=c6-media groupinstall "Development tools" -y [[email protected] ~]# tar -zxvf nginx-1.9.4.tar.gz -C /usr/local/src/ [[email protected] ~]# cd /usr/local/src/nginx-1.9.4/ [[email protected] nginx-1.9.4]# yum --disablerepo=\* --enablerepo=c6-media install openssl-devel pcre-devel -y [[email protected] nginx-1.9.4]# ./configure > --prefix=/usr/local/nginx > --conf-path=/etc/nginx/nginx.conf > --error-log-path=/var/log/nginx/error.log > --http-log-path=/var/log/nginx/access.log > --pid-path=/var/run/nginx/nginx.pid > --lock-path=/var/lock/nginx.lock > --user=nginx > --group=nginx > --with-http_ssl_module > --with-http_flv_module > --with-http_stub_status_module > --with-http_gzip_static_module > --http-client-body-temp-path=/var/tmp/nginx/client/ > --http-proxy-temp-path=/var/tmp/nginx/proxy/ > --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ > --with-pcre [[email protected] nginx-1.9.4]# groupadd nginx [[email protected] nginx-1.9.4]# useradd -r -g nginx nginx [[email protected] nginx-1.9.4]# make && make install [[email protected] nginx]# vim /etc/profile
[[email protected] nginx]# . /etc/profile [[email protected] nginx]# mkdir -pv /var/tmp/nginx/client/ [[email protected] nginx]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is success [[email protected] nginx]# nginx
****控制脚本没有写,有时间再补充吧
安装MySQL
版本:mysql-5.5.15-linux2.6-i686.tar.gz
[[email protected] ~]# rpm -qa |grep mysql mysql-libs-5.1.71-1.el6.i686 [[email protected] ~]# rpm -e mysql-libs --nodeps [[email protected] ~]# groupadd mysql [[email protected] ~]# useradd -r -g mysql mysql [[email protected] ~]# tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/ [[email protected] local]# ln -s mysql-5.5.15-linux2.6-i686/ mysql [[email protected] mysql]# chown -R mysql:mysql . [[email protected] mysql]# yum --disablerepo=\* --enablerepo=c6-media install libaio -y [[email protected] mysql]# ./scripts/mysql_install_db --user=mysql ***初始化 [[email protected] mysql]# chown -R root . [[email protected] mysql]# chown -R mysql data/ [[email protected] mysql]# cp support-files/my-medium.cnf /etc/my.cnf [[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql]# service mysqld start [[email protected] mysql]# chkconfig --add mysqld [[email protected] mysql]# vim /etc/profile
[[email protected] mysql]# . /etc/profile ***重新读取一下 [[email protected] mysql]# mysqladmin -u root -p password ‘123‘ [[email protected] mysql]# vim /etc/ld.so.conf.d/mysql.conf ***扩展名.conf结尾,
***加入新的库的路径 [[email protected] mysql]# ldconfig ***刷新 [[email protected] mysql]# ldconfig -pv |grep mysql libtcmalloc_minimal.so.0 (libc6) => /usr/local/mysql/lib/libtcmalloc_minimal.so.0 libmysqlclient.so.18 (libc6) => /usr/local/mysql/lib/libmysqlclient.so.18 libmysqlclient.so (libc6) => /usr/local/mysql/lib/libmysqlclient. [[email protected] mysql]# echo "MANPATH /usr/local/mysql/man" >> /etc/man.config
安装PHP
版本:php-5.5.8.tar.bz2
[[email protected] ~]# tar -jxvf php-5.5.8.tar.bz2 -C /usr/local/src/ [[email protected] ~]# cd /usr/local/src/php-5.5.8/ [[email protected] php-5.5.8]# yum --disablerepo=\* --enablerepo=c6-media install libxml2-devel libjpeg-turbo-devel libpng-devel freetype-devel -y [[email protected] php-5.5.8]# ./configure > --prefix=/usr/local/php > --sysconfdir=/etc/fpm > --enable-fpm \ **形成独立的服务器 > --enable-sockets > --with-mysql=/usr/local/mysql > --with-pdo-mysql=/usr/local/mysql > --with-mysqli=/usr/local/mysql/bin/mysql_config > --enable-mbstring > --enable-xml > --with-png-dir > --with-gd > --with-jpeg-dir > --with-zlib > --with-freetype-dir > --with-config-file-path=/etc/php > --with-config-file-scan-dir=/etc/php5.d
由于编译时间过长,安装screen
[[email protected] php-5.5.8]# yum --disablerepo=\* --enablerepo=c6-media install screen -y [[email protected] php-5.5.8]# make && make install [[email protected] php]# cd /etc/fpm [[email protected] fpm]# cp php-fpm.conf.default php-fpm.conf **配置文件 [[email protected] mysql]# cd /usr/local/src/php-5.5.8/ [[email protected] php-5.5.8]# mkdir /etc/php /etc/php5.d [[email protected] php-5.5.8]# cp php.ini-production /etc/php/php.ini **初始化文件 [[email protected] fpm]# pwd /usr/local/src/php-5.5.8/sapi/fpm [[email protected] fpm]# cp init.d.php-fpm /etc/init.d/php-fpm **控制脚本 [[email protected] fpm]# chmod a+x /etc/init.d/php-fpm [[email protected] fpm]# service php-fpm start Starting php-fpm done [[email protected] fpm]# netstat -tupln |less
[[email protected] fpm]# chkconfig --add php-fpm [[email protected] fpm]# chkconfig --list |grep php-fpm php-fpm 0:off 1:off 2:on 3:on 4:on 5:on 6:off [[email protected] php]# vim /etc/profile
[[email protected] php]# . /etc/profile
nginx与PHP 的结合
[[email protected] php]# vim /etc/nginx/nginx.conf
[[email protected] php]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [[email protected] php]# nginx -s reload
测试PHP,nginx,MySQL的结合
[[email protected] php]# cd /usr/local/nginx/html/ [[email protected] html]# vim index.php
如果访问不到,可能是防火墙没有关闭
连接数据库测试
[[email protected] html]# vim index1.php
至此,LNMP环境已经搭建完成。
xcache的安装
[[email protected] ~]# tar -zxvf xcache-3.1.0.tar.gz -C /usr/local/src/ [[email protected] ~]# cd /usr/local/src/xcache-3.1.0/ [[email protected] xcache-3.1.0]# phpize **把xcache变成PHP的功能扩展 Configuring for: PHP Api Version: 20121113 Zend Module Api No: 20121212 Zend Extension Api No: 220121212 [[email protected] xcache-3.1.0]# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config **变成PHP模块,指明PHP-config位置 [[email protected] xcache-3.1.0]# make && make install
安装好之后,在下面的目录下,已经生成了动态库
[[email protected] xcache-3.1.0]# cd /usr/local/php/lib/php/extensions/no-debug-non-zts-20121212/ [[email protected] no-debug-non-zts-20121212]# cp xcache.so /etc/php5.d/ [[email protected] no-debug-non-zts-20121212]# cd /usr/local/src/xcache-3.1.0/ [[email protected] xcache-3.1.0]# cp xcache.ini /etc/php5.d/
测试,重启PHP
[[email protected] xcache-3.1.0]# service php-fpm restart
****如果配置时没有指明PHP5.d目录,追加到php.ini
cat xcache.ini >> /usr/local/php/lib/php.ini
客户访问的对象——nginx服务器实现缓存
[[email protected] xcache-3.1.0]# vim /etc/nginx/nginx.conf [[email protected] xcache-3.1.0]# mkdir -pv /data/nginx/cache
[[email protected] xcache-3.1.0]# nginx -s reload
重新访问一下,看到已经有收据被缓存。
[[email protected] nginx]# cd /data/nginx/cache/ [[email protected] cache]# ll total 4 drwx------. 3 nginx nginx 4096 Sep 5 18:04 3 [[email protected] cache]#