LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Nginx是一个小巧而高效的Linux下的Web服务器软件,是由 Igor Sysoev 为俄罗斯访问量第二的Rambler 站点开发的,已经在一些俄罗斯的大型网站上运行多年,相当的稳定。Nginx性能稳定、功能丰富、运维简单、处理静态文件速度快且消耗系统资源极少。
本案环境与说明:
环境
[[email protected] ~]# cat /etc/centos-release && uname -r CentOS release 6.6 (Final) 2.6.32-504.el6.x86_64
软件版本:
mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz nginx-1.7.8.tar.gz libmcrypt-2.5.6.tar.gz php-5.6.6.tar.gz
文中所用软件下载地址:
http://mirrors.sohu.com/
http://mirrors.cnnic.cn/apache/
ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt
Nginx 安装前的准备
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz
wget http://mirrors.sohu.com/php/php-5.6.6.tar.gz
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.6.tar.gz
wget http://mirrors.sohu.com/nginx/nginx-1.7.8.tar.gz
安装MySQL
[[email protected] ~]# useradd -s /sbin/nologin mysql [[email protected] ~]# tar zxvf mysql-5.7.6-m16-linux-glibc2.5-x86_64.tar.gz [[email protected] ~]# cd /usr/local/ [[email protected] local]# mv /root/mysql-5.7.6-m16-linux-glibc2.5-x86_64 . [[email protected] local]# ln -s mysql-5.7.6-m16-linux-glibc2.5-x86_64 mysql [[email protected] local]# cd mysql [[email protected] mysql]# mkdir /data/mysql [[email protected] mysql]# chown -R root . [[email protected] mysql]# chown -R mysql /data/mysql [[email protected] mysql]# chgrp -R mysql . [[email protected] mysql]# bin/mysql_install_db --user=mysql --datadir=/data/mysql [[email protected] mysql]# cp support-files/my-default.cnf /etc/my.cnf cp:是否覆盖"/etc/my.cnf"? y [[email protected] mysql]# cp support-files/mysql.server /etc/init.d/mysqld [[email protected] mysql]# chmod 755 /etc/init.d/mysqld [[email protected] mysql]# vim /etc/init.d/mysqld basedir=/usr/local/mysql datadir=/data/mysql [[email protected] mysql]# chkconfig --add mysqld [[email protected] mysql]# chkconfig mysqld on [[email protected] mysql]# service mysqld start Starting MySQL. SUCCESS!
安装PHP
1.环境配置
rpm -q libxml2-devel libjpeg-turbo libpng-devel freetype-devel gd-devel libmcrypt-devel openssl-devel libxml2-devel-2.7.6-14.el6_5.2.x86_64 libjpeg-turbo-1.2.1-3.el6_5.x86_64 libpng-devel-1.2.49-1.el6_2.x86_64 freetype-devel-2.3.11-14.el6_3.1.x86_64 package gd-devel is not installed package libmcrypt-devel is not installed openssl-devel-1.0.1e-30.el6.x86_64 [[email protected] ~]# yum install gd-devel
本案为配置扩展源,libmcrypt-devel使用tar包安装
[[email protected] ~]# tar zxvf libmcrypt-2.5.6.tar.gz [[email protected] ~]# cd libmcrypt-2.5.6 [[email protected] libmcrypt-2.5.6]# ./configure --prefix=/usr/local/libmcrypt [[email protected] libmcrypt-2.5.6]# make && make install
2.安装php
[[email protected] src]# tar zxvf php-5.6.6.tar.gz [[email protected] src]# useradd -s /sbin/nologin php-fpm [[email protected] src]# cd php-5.6.6 [[email protected] src]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt=/usr/local/libmcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-curl [[email protected] php-5.6.6]# make && make install [[email protected] php-5.6.6]# cp php.ini-production /usr/local/php/etc/php.ini [[email protected] php-5.6.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [[email protected] php-5.6.6]# mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [[email protected] php-5.6.6]# chmod 755 /etc/init.d/php-fpm [[email protected] php-5.6.6]# chkconfig --add php-fpm [[email protected] php-5.6.6]# chkconfig php-fpm on [[email protected] php-5.6.6]# service php-fpm start
安装nginx
1.环境检查
[[email protected] nginx-1.7.8]# rpm -q pcre-devel pcre-devel-7.8-6.el6.x86_64
2.安装
[[email protected] src]# tar nginx-1.7.8.tar.gz [[email protected] src]# cd nginx-1.7.8 [[email protected] nginx-1.7.8]# ./configure --prefix=/usr/local/nginx --with-pcre [[email protected] nginx-1.7.8]# make && make install
3.启动
[[email protected] conf]# /usr/local/nginx/sbin/nginx #启动服务 [[email protected] conf]# ps -aux | grep nginx Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ root 11541 0.0 0.0 24304 668 ? Ss 00:45 0:00 nginx: master process /usr/local/nginx/sbin/nginx nobody 11542 0.0 0.1 24728 1248 ? S 00:45 0:00 nginx: worker process root 11544 0.0 0.0 103256 840 pts/0 S+ 00:45 0:00 grep nginx
4.配置解析php
[[email protected] ~]# vi /usr/local/nginx/conf/nginx.conf #找如下内容并修改fastcgi_param行 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; include fastcgi_params; } [[email protected] ~]# /usr/local/nginx/sbin/nginx -s reload
5.测试
[[email protected] ~]# cat /usr/local/nginx/html/1.php <?php phpinfo(); ?> [[email protected] ~]# curl localhost/1.php
时间: 2024-10-25 13:25:34