LNMP是一个基于CentOs编写的企业网站平台之一,基于Linux系统、Nginx服务、MySQL数据库和网站开发语言(PHP、perl、Python),Nginx是一个高性能Http和反向代理服务器,也是一个也是一个IMAP/POP3/SMTP代理服务器,MySQL是数据管理系统,PHP是一种在服务器端执行脚本语言,以上均为免费开源软件组合在一起称为一个免费、高效和扩展性能强的网站服务系统。
以下是yum源安装LNMP
/etc/init.d/NetworkManager stop
chkconfig NetworkManager off
iptables -F
/etc/init.d/iptables save
/etc/init.d/iptables stop
chkconfig iptables off
setenforce 0
vim /etc/selinux/config
SELINUX=permissive
/etc/init.d/httpd stop
配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有nginx软件包)
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof 安装开发包、语言和相应的依赖包
yum removn nginx mysql php 卸载已安装的包
yum install nginx 安装nginx
/etc/init.d/nginx
netstat -anptu | grep :80
yum install mysql mysql-server mysql-devel 安装MySQL
service mysqld start
netstat -anptu | grep :3306
mysqladmin -u root password "123456"
/etc/init.d/mysql restart
yum install php lighttpd-fastcgi php-cli php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy php-common php-devel php-fpm 安装php和需要组件使PHP支持MySQL、fastcgi模式
/etc/init.d/php-fpm restart
netstat -anptu | grep php-fpm(:9000)
vim /etc/nginx/conf.d/default.conf 配置nginx支持PHP
location / {
root /usr/share/nginx/html; 对应的路径
index index.html index.htm index.html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_n
ame; include fastcgi_params;
} 以上代码注释去掉即可,并修改nginx默认路径
vim /etc/php.ini
cgi.fix_pathinfo = 1 配置PHP,解决nginx文件类型解析时漏洞
/etc/init.d/php-fpm restart
/etc/init.d/nginx restart
vim /usr/share/nginx/html/info.php
<?php
phpinfo();
?> 验证LNMP配置
vim /usr/share/nginx/html/info2.php
<?php
echo "hello world";
?> 验证LNPM配置
elinks --dump http://192.168.8.8/info2.php
elinks --dump http://192.168.8.8/info2.php
vim /usr/share/nginx/html/data.php 验证PHP连接mysql服务
<?php
$linkdb=mysql_connect("localhost","root","123456");
if ($linkdb){
echo "link db ok"; #访问成功提示符
}else{
echo "link db err "; #访问不成功提示符
}
?> 生成PHP web页面
/etc/init.d/mysql restart 重启MySQL
elinks --dump http://192.168.8.8/data.php
/etc/init.d/mysql stop 停止MySQL服务在测试
elinks --dump http://192.168.8.8/data.php
以下是编译安装部署LNMP:
/etc/init.d/NetworkManager stop
chkconfig NetworkManager off
iptables -F
/etc/init.d/iptables save
/etc/init.d/iptables stop
chkconfig iptables off
setenforce 0
vim /etc/selinux/config
SELINUX=permissive
/etc/init.d/httpd stop 检查以上环境
yum -y groupinstall "Development tools" "Additional Development"
yum -y install gcc openssl-devel pcre-devel zlib-devel yum安装基础依赖包
date -s "2016-04-19 17:30:00" 修改当前年月日
安装Nginx
tar -zxvf nginx-1.8.0.tar.gz 解压tar包
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --pid-path=/usr/local/nginx/nginx.pid --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/usr/local/nginx/client --http-proxy-temp-path=/usr/local/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/fcgi --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-pcre
make && make install 编译安装
useradd -s /sbin/nologin www 添加用户组
/usr/local/nginx/sbin/nginx 启用Nginx服务
netstat -anptu | grep :80 查看Nginx默认监听端口
echo "测试Nginx" > /usr/local/nginx/html/data.html 生成web测试页面
yum -y install elinks
elinks --dump http://localhost/data.html 测试
elinks --dump http://192.168.8.8/data.html 客户机测试
安装MySQL 首先安装cmake,新版本需要cmake编译安装。
tar -zxvf cmake-2.8.10.2.tar.gz 解压cmake
cd cmake-2.8.10.2
./bootstrap --prefix=/usr/local/cmake
make && make install 编译安装
ls /usr/local/cmake/ 查看
/usr/local/cmake/bin/cmake --version cmake版本号
useradd -s /sbin/nologin mysql 添加用户组
grep mysql /etc/passwd或grep mysql /etc/group
tar -zxvf mysql-5.6.25.tar.gz 解压MySQL
./usr/local/cmake/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DSYSC
ONFDIR=/etc -DMYSQL_DATADIR=/usr/local/mysql/data -DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock -DMYSQL_USER=mysql -DEXTRA_CHARSETS=all -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1
make && make install 编译安装
chown -R mysql:mysql /usr/local/mysql/ 更改所有者与所有组
cd /usr/local/mysql/
./scripts/mysqld_install_db --user=mysql --datadir=/usr/local/mysql/data 初始化授权库
rm -rf /etc/my.cnf
cp /usr/local/mysql/my.cnf /etc/my.cnf
/usr/local/mysql/bin/mysqld_safe --user=mysql & 启用mysql后台运行
netstat -anptu | grep :3306 监听默认端口
/usr/local/mysql/bin/mysql -hlocalhost -uroot -p 直接回车、回车无密码
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysqldd mysql添加为系统命令(名称任意即可)
chmod +x /etc/init.d/mysqldd 权限
/etc/init.d/mysqldd stop 测试关闭mysql
/etc/init.d/mysqldd start 测试开启mysql
/usr/local/mysql/bin/mysqladmin -hlocalhost -uroot password "123" 设置mysql登录密码
/usr/local/mysql/bin/mysqladmin -hlocalhost -uroot -p password "321" 123 修改登录密码
PATH=/usr/local/mysql/bin:$PATH 变量在命令行输入临时有效
mysql -hlocalhost -uroot -p 测试登录
vim /etc/bashrc
export PATH=/usr/local/mysql/bin:$PATH 写入系统全局环境变量
vim /etc/ld.so.conf 此文件记录了编译时使用的动态库的路径,也就是加载so库的路径
/usr/local/mysql/lib
ldconfig -v | grep -i mysql 更新并输出详细信息
安装mhash、libiconv、libmcrypt、PHP
mhash-0.9.9.9.tar.gz (hash函数库)
libiconv-1.13.tar.gz (字符编码转换)
libmcrypt-2.5.8.tar.gz (提供加密功能库文件) 解压安装以上三个tar包
cd libmcrypt-2.5.8
./configure --with-gmetad --enable-gexec --enable-ltdl-install
make && make install
ls /usr/local/lib | grep --color mhash
ls /usr/local/lib | grep --color libiconv
ls /usr/local/lib | grep --color libmcrypt 查询后做软连接
ln -sv /usr/local/lib/mhash.* /usr/lib
ln -sv /usr/local/lib/libiconv.* /usr/lib
ln -sv /usr/local/lib/libmcrypt.* /usr/lib 将以上三个tar包软连接到指定目录下
tar -zxvf php-5.4.24.tar.gz
cd php-5.4.24
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-m
ysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap 以下运行中报错信息以及解决方法
1)configure: error: jpeglib.h not found.
yum -y install libjpeg-turbo-devel openjpeg-libs libpng-deve
2)configure: error: Cannot find ldap.h
yum -y install openldap.i686 openldap-devel.i686
3)configure: error: LDAP SASL check failed. Please check config.log for more inf
ormation.
yum -y install openldap-devel
4)configure: error: mcrypt.h not found. Please reinstall libmcrypt.
tar -zxvf libmcrypt-2.5.8.tar.gz
./configure
make && make install
5)configure: error: xml2-config not found. Please check your libxml2 installation.
yum -y install libxml2-devel
6)configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
yum -y install libcurl-devel
7)configure: error: freetype.h not found.
yum -y install freetype-devel
以上报错仅供参考
make ZEND_EXTRA_LIBS=‘-liconv‘
make install 编译安装
/usr/local/php/bin/php -m 查看php支持的软件包
cd php-5.4.9
cp php.ini-development /usr/local/php/etc/php.ini 创建PHP主配置文件
cd php-5.4.9/sapi/fpm/
cp init.d.php-fpm /etc/init.d/php-fpm 加入系统服务
chmod +x /etc/init.d/php-fpm 加权限
直接验证即可。