Lnmp安装有两种方式,一是一键安装,由于安装过程中升级系统文件,在编译golang的时候出现问题,有待于进一步解决;二是分布安装,该过程安装后可以正常编译相关程序。
1、查看环境:
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@localhost ~]#
2、关闭防火墙:
[root@localhost ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[root@localhost ~]# service iptables status
iptables: Firewall is not running.
[root@localhost ~]#
3、配置CentOS 6.0 第三方yum源(CentOS默认的标准源里没有nginx软件包)
[root@localhost src]# wget http:
[root@localhost src]# sh ./atomic
[root@localhost src]# yum check-update
4、安装开发包和库文件:
[root@localhost src]# yum -y install ntp make openssl openssl-devel pcre pcre-devel libpng libpng-devel libjpeg-6b libjpeg-devel-6b freetype freetype-devel gd gd-devel zlib zlib-devel gcc gcc-c++ libXpm libXpm-devel ncurses ncurses-devel libmcrypt libmcrypt-devel libxml2 libxml2-devel imake autoconf automake screen sysstat compat-libstdc++-33 curl curl-devel
5、卸载已安装的Apache、MySQL、PHP;(分别执行)
[root@localhost src]# yum remove httpd
[root@localhost src]# yum remove mysql
[root@localhost src]# yum remove php
6、安装Nginx;
[root@localhost src]# yum install nginx
[root@localhost src]# service nginx start
[root@localhost src]# chkconfig –levels 235 nginx on
7、安装MySQL;
[root@localhost src]# yum install mysql mysql-server mysql-devel
[root@localhost src]# service mysqld start
[root@localhost src]# chkconfig --levels 235 mysqld on
登录MySQL,删除空用户及修改用户密码;
[root@localhost src]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands
end
with ;
or
\g.
Your MySQL connection id is 2
Server version: 5.5.55 MySQL Community Server (GPL) by Atomicorp
Copyright (c) 2000, 2017, Oracle
and
/
or
its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation
and
/
or
its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;'
or
'\h'
for
help. Type '\c' to clear the current input statement.
mysql>
use
mysql
Reading table information
for
completion of table
and
column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>select user,host,password from mysql.user;
mysql> drop user ''@localhost;
Query OK, 0 rows affected (0.00 sec)
mysql>
delete
from user where user = '';
Query OK, 1 row affected (0.00 sec)
mysql> update mysql.user set password = password('root') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0
mysql> grant all privileges on *.* to root@'%' identified by 'root' with grant option;
Query OK, 0 rows affected (0.00 sec)
mysql>
flush
privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
flush
privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
exit
;Bye
8、安装PHP;
[root@localhost src]# 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
[root@localhost src]# yum install php-tidy php-common php-devel php-fpm php-mysql
[root@localhost src]# service php-fpm start
Starting php-fpm: No log handling enabled - turning on stderr logging
Created directory: /
var
/lib/net-snmp/mib_indexes
[ OK ]
[root@localhost src]# chkconfig --levels 235 php-fpm on
[root@localhost src]#
9、配置Nginx,支持PHP;
[root@localhost wwwroot]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# vi
default
.conf
server {
listen 80;
server_name localhost;
location / {
root /home/wwwroot;
index index.html index.htm index.php;
if
(!-e
$request_filename
){
rewrite ^(.*)$ /index.php?s=
$1
last;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
location ~ \.php$ {
root /home/wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include
fastcgi_params;
fastcgi_param SCRIPT_FILENAME
$document_root
$fastcgi_script_name
;
set
$path_info
""
;
set
$fastcgi_script_name_new
$fastcgi_script_name
;
if
(
$fastcgi_script_name
~*
"^(.+\.php)(/.+)$"
) {
set
$fastcgi_script_name_new
$1
;
set
$path_info
$2
;
}
fastcgi_param SCRIPT_FILENAME
$document_root
$fastcgi_script_name_new
;
fastcgi_param SCRIPT_NAME
$fastcgi_script_name_new
;
fastcgi_param PATH_INFO
$path_info
;
}
}
10、重启Nginx和php-fpm;
[root@localhost conf.d]# service nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
[root@localhost conf.d]# service php-fpm restart
Stopping php-fpm: [ OK ]
Starting php-fpm: [ OK ]
[root@localhost conf.d]#
11、测试,在Nginx解析的目录下创建info.php文件,并在浏览器访问http:
<?php
phpinfo();
?>