CentOS7 一键安装LNMP环境

说明:此安装属于网络安装,所以首先请保证外网是可以正常访问的。

[root@localhost ~]# ping baidu.com
PING baidu.com (123.125.114.144) 56(84) bytes of data.
64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=1 ttl=53 time=19.1 ms
64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=2 ttl=53 time=18.5 ms
64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=3 ttl=53 time=18.6 ms
64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=4 ttl=53 time=18.7 ms
64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=5 ttl=53 time=18.6 ms
64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=6 ttl=53 time=18.9 ms
  • 开始运行如下命令

yum -y install wget screen curl python

yum仓库会更新下,然后下载wget、screen、curl、python

下载完成之后,开始运行

wget http://mirrors.linuxeye.com/oneinstack-full.tar.gz

从网络上下载一个压缩包,里面包含一键安装的脚本和安装包,大概275M。

接下来依次解压该文件,进入解压目录,开始执行sh脚本

tar xzf oneinstack-full.tar.gz
cd oneinstack
./install.sh

CentOS7 一键安装LNMP环境_第1张图片

全部选好了等着安装就好了,是不是so easy~~

大概安装了将近50分钟,看到以下输出信息

####################Congratulations########################
Total OneinStack Install Time: -450 minutes

Nginx install dir:              /usr/local/nginx

Database install dir:           /usr/local/mysql
Database data dir:              /data/mysql
Database user:                  root
Database password:              123456

PHP install dir:                /usr/local/php

Pure-FTPd install dir:          /usr/local/pureftpd
Create FTP virtual script:      ./pureftpd_vhost.sh

redis install dir:              /usr/local/redis

index url:                      http://192.168.0.222/

Please restart the server and see if the services start up fine.
Do you want to restart OS ? [y/n]:    

最后提示你重启系统,那就重启呗,选择 Y 即可。


重启之后查看相关进程。

[root@localhost ~]# ps -ef|grep php
root      2802     1  0 19:44 ?        00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
www       2803  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2804  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2805  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2806  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2807  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2808  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2809  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2810  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2811  2802  0 19:44 ?        00:00:00 php-fpm: pool www
www       2812  2802  0 19:44 ?        00:00:00 php-fpm: pool www
root      3037  2964  0 19:45 pts/0    00:00:00 grep --color php
[root@localhost ~]# ps -ef|grep mysql
root      1535     1  0 19:44 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/mysql.pid
mysql     2786  1535  0 19:44 ?        00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/mysql-error.log --open-files-limit=65535 --pid-file=/data/mysql/mysql.pid --socket=/tmp/mysql.sock --port=3306
root      3048  2964  0 19:45 pts/0    00:00:00 grep --color mysql
[root@localhost ~]# ps -ef|grep nginx
root      2957     1  0 19:44 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www       2959  2957  0 19:44 ?        00:00:00 nginx: worker process
root      3060  2964  0 19:46 pts/0    00:00:00 grep --color nginx

进程全部是自动启起来了。那么接下来我们得实践下,这个环境是否能正确运行。

依次运行

[root@localhost ~]# cd /data/wwwroot/
[root@localhost wwwroot]# mkdir blog
[root@localhost wwwroot]# cd blog/
[root@localhost blog]# vi index.php

echo "hello world!\n";

我们就是在/data/wwwroot下面建了一个blog的目录,然后在blog下面新建了一个index.php的文件,内容输出hello world。

在blog目录运行

php index.php

可以看到输出了 hello world,这就说明php已经安装成功了。


接下来准备配置nginx

cd /usr/local/nginx/conf
mkdir vhost
cd vhost
touch blog.conf

开始编辑 vi blog.conf 内容如下:

  server {
    listen 80;
    server_name blog.com;
    root /data/wwwroot/blog;
    index index.html index.htm index.php;

    location ~ [^/]\.php(/|$) {
      #fastcgi_pass remote_php_ip:9000;
      fastcgi_pass unix:/dev/shm/php-cgi.sock;
      fastcgi_index index.php;
      include fastcgi.conf;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|mp4|ico)$ {
      expires 30d;
      access_log off;
    }
    location ~ .*\.(js|css)?$ {
      expires 7d;
      access_log off;
    }
    location ~ /\.ht {
      deny all;
    }
  }

保存之后 重新加载nginx

[root@localhost vhost]# service nginx reload
Reloading nginx configuration (via systemctl):             [  OK  ]

在nginx里面配置了server_name 为blog.com 所以我们需要配置hosts

echo ‘192.168.0.222 blog.com’ >> /etc/hosts

追加一句进去即可。

然后我们可以通过curl blog.com 就可以访问我们的网站了

[root@localhost ~]# curl blog.com
hello world!
[root@localhost ~]# 

成功的输出了 hello world! 说明nginx 和 php 都ok了。


最后就差mysql了,运行 mysql -uroot -p123456

  • 注意:-u是用户名 -p是密码 -u后面和-p后面是不加空格的
[root@localhost ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.19-log MySQL Community Server (GPL)

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 [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

MySQL [(none)]> use mysql;
Database changed
MySQL [mysql]> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| engine_cost               |
| event                     |
| func                      |
| general_log               |
| gtid_executed             |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| server_cost               |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
31 rows in set (0.00 sec)

MySQL [mysql]> 

我们可以看到mysql正常工作的,到这一步我们的LNMP环境就全部搭建完成,并测试成功了。

你可能感兴趣的:(开发环境)