centos下LNMP环境搭建

news/2025/7/8 16:42:21

为什么80%的码农都做不了架构师?>>>   hot3.png

新买的云服务器,默认用户只有root,为了防止误操作,还是添加一个管理员为妙。

[root@localhost ~]# useradd maohao

添加管理员权限

[root@localhost home]# vi /etc/sudoers

## Allow root to run any commands anywhere 
root    ALL=(ALL)     ALL

#添加
maohao    ALL=(ALL)    ALL

设置密码

[root@localhost home]# passwd maohao
Changing password for user maohao.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.

编辑防火墙

[maohao@localhost ~]$ sudo cat /etc/sysconfig/iptables

[sudo] password for maohao: 
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

重启防火墙

[maohao@localhost ~]$ sudo /etc/init.d/iptables restart

精简开机启动项

#设置格式
[maohao@localhost ~]$ LANG=en
#查看
[maohao@localhost ~]$ chkconfig --list|grep 3:on
#设置
[maohao@localhost ~]$ chkconfig --list|grep 3:on|grep -vE "crond|sshd|network|rsyslog|sysstat"|awk '{print "chkconfig " $1 " off"}'|bash

切换用户

[root@localhost home]# su mahao

开始干活了……

3

2

1

begin!

一、更新源

[maohao@localhost ~]$ sudo yum update -y

二、进行nginx源的安装

[maohao@localhost ~]$ sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm

确认是否成功,查看信息

[mahao@localhost ~]$ yum info nginx
nginx version: nginx/1.12.2

版本太低,卸载

[maohao@localhost ~]$ sudo yum remove nginx
#查看
[maohao@localhost ~]$ which nginx
/usr/bin/which: no nginx in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/mahao/bi

准备安装环境

[maohao@localhost ~]$ sudo yum -y install gcc gcc-c++ autoconf automake make
[maohao@localhost ~]$ sudo yum -y install zlib zlib-devel openssl openssl--devel pcre pcre-devel 
[maohao@localhost ~]$ sudo mkdir tools
[maohao@localhost ~]$ cd tools 
[maohao@localhost tools]$  sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf pcre-8.41.tar.gz
[maohao@localhost tools]$ cd pcre-8.41
[maohao@localhost pcre-8.41]$ sudo ./configure
[maohao@localhost pcre-8.41]$ sudo make
[maohao@localhost pcre-8.41]$ sudo make install
[maohao@localhost pcre-8.41]$ cd ../
[maohao@localhost tools]$ sudo wget http://zlib.net/zlib-1.2.11.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf zlib-1.2.11.tar.gz
[maohao@localhost tools]$ cd zlib-1.2.11
[maohao@localhost zlib-1.2.11]$ sudo ./configure
[maohao@localhost zlib-1.2.11]$ sudo make
[maohao@localhost zlib-1.2.11]$ sudo make install
[maohao@localhost zlib-1.2.11]$ cd ../
[maohao@localhost tools]$ sudo wget http://www.openssl.org/source/openssl-fips-2.0.16.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf openssl-fips-2.0.16.tar.gz
[maohao@localhost tools]$ cd openssl-fips-2.0.16
[maohao@localhost openssl-fips-2.0.16]$ sudo yum -y install openssl openssl-devel# 简单粗暴一点的方法
[maohao@localhost ~]$ sudo yum install gcc-c++  
[maohao@localhost ~]$ sudo yum -y install pcre*  
[maohao@localhost ~]$ sudo yum -y install openssl*  


三、安装Nginx并设置开机启动

[maohao@localhost ~]$ sudo useradd nginx -s /sbin/nologin
[maohao@localhost ~]$ cd tools
[maohao@localhost tools]$ sudo wget http://nginx.org/download/nginx-1.9.9.tar.gz
[maohao@localhost tools]$ sudo tar -zxvf nginx-1.9.9.tar.gz
[maohao@localhost tools]$ cd nginx-1.9.9 
[maohao@localhost tools]$ sudo ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module 
[maohao@localhost tools]$ sudo make &&make install 

修改配置文件

[maohao@localhost sbin]$ sudo vi /usr/local/nginx/conf/nginx.conf

找到这些  把标红的#全去掉,橘黄色的部分替换成暗红色部分

 #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 $document_root$fastcgi_script_name;
 #    include        fastcgi_params;
 #}
保存退出

重启

[mahao@localhost ~]$ sudo /usr/local/nginx/sbin/nginx -s reload

四、安装php

[maohao@localhost ~]$ sudo yum install php -y
[maohao@localhost ~]$ sudo yum install php-fpm -y

执行php -v查看版本

[maohao@localhost ~]$ php -v
PHP 5.3.3 (cli) (built: Mar 22 2017 12:27:09) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

5.3的版本很不爽

#检查当前安装的PHP包
[maohao@localhost ~]$ sudo yum list installed | grep php
#删除
[maohao@localhost ~]$ sudo yum remove php.x86_64 php-cli.x86_64 php-common.x86_64

php5.6安装

[maohao@localhost ~]$ sudo rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
[maohao@localhost ~]$ sudo yum -y --enablerepo=webtatic install php56w-devel
[maohao@localhost ~]$ sudo yum -y install php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-opcache.x86_64

这才看着舒服一点嘛 

[maohao@localhost ~]$ php -v
PHP 5.6.32 (cli) (built: Oct 29 2017 19:00:01) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

下载安装PHP FPM设置启动

[mahao@localhost ~]$ sudo yum -y install php56w-fpm
#设置php-fpm开机启动
[mahao@localhost ~]$ sudo chkconfig php-fpm on
#启动php-fpm
[mahao@localhost ~]$ sudo /etc/init.d/php-fpm start

安装5.6的DOM扩展

[maohao@localhost ~]$ sudo yum install php56w-xml

 

五、安装mysql

[maohao@localhost ~]$ sudo yum install -y mysql mysql-server
[maohao@localhost ~]$ mysql -V
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

纳尼?5.1 卧槽,神马情况?卸载重装吧

[maohao@localhost ~]$ sudo rpm -qa | grep -i mysql

php56w-mysql-5.6.32-1.w6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64

 查看mysql

[maohao@localhost ~]$ sudo rpm -qa | grep -i mysql
php56w-mysql-5.6.32-1.w6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-5.1.73-8.el6_8.x86_64

终止mysql

[maohao@localhost init.d]$ sudo service mysqld stop
Stopping mysqld:                                           [  OK  ]

删除包

[maohao@localhost init.d]$ sudo rpm -ev mysql-server-5.1.73-8.el6_8.x86_64
[maohao@localhost init.d]$ sudo rpm -ev mysql-libs-5.1.73-8.el6_8.x86_64 --nodeps
[maohao@localhost init.d]$ sudo rpm -ev mysql-5.1.73-8.el6_8.x86_64
[maohao@localhost init.d]$ sudo find / -name mysql
/usr/share/mysql
/usr/lib64/mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/lib64/perl5/DBD/mysql
[maohao@localhost init.d]$ sudo rm -rf /usr/share/mysql
[maohao@localhost init.d]$ sudo rm -rf /usr/lib64/mysql/
[maohao@localhost init.d]$ sudo rm -rf /etc/my.cnf
#检查
[maohao@localhost init.d]$ sudo rpm -qa|grep -i mysql
php56w-mysql-5.6.32-1.w6.x86_64
perl-DBD-MySQL-4.013-3.el6.x86_64

安装5.5源

[maohao@localhost]$ sudo rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
[maohao@localhost]$ sudo rpm -Uvh http://mirror.steadfast.net/epel/6/i386/epel-release-6-8.noarch.rpm
#查看
[maohao@localhost]$ yum --enablerepo=remi,remi-test list mysql mysql-server

#最后两行是这样就是成功了

mysql.x86_64                      5.5.58-1.el6.remi                 remi
mysql-server.x86_64           5.5.58-1.el6.remi                remi

 安装mysql5.5

[maohao@localhost]$ sudo yum --enablerepo=remi,remi-test install mysql mysql-server

启动

[maohao@localhost ]$ sudo /etc/init.d/mysqld start

Initializing MySQL database:  Installing MySQL system tables...
171201 11:25:06 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171201 11:25:06 [Note] /usr/libexec/mysqld (mysqld 5.5.58) starting as process 2270 ...
OK
Filling help tables...
171201 11:25:08 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
171201 11:25:08 [Note] /usr/libexec/mysqld (mysqld 5.5.58) starting as process 2277 ...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]
 

 设置root密码

[maohao@localhost]$ sudo /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQLSERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
#这里的旧密码默认的是空,直接回车
Enter current password for root (enter for none):  
OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..... Success!By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.Remove anonymous users? [Y/n] y... Success!Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] y... Success!By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.Remove test database and access to it? [Y/n] y- Dropping test database...... Success!- Removing privileges on test database...... Success!Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.Reload privilege tables now? [Y/n] y... Success!Cleaning up...All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.Thanks for using MySQL!

设置开机启动,重启

[maohao@localhost ~]$ sudo chkconfig mysqld on
[maohao@localhost ~]$ sudo /etc/init.d/mysqld restart

 

转载于:https://my.oschina.net/marhal/blog/1583453


https://dhexx.cn/news/show-3787553.html

相关文章

百度闪电裁员20人被疑违反劳动法

百度闪电裁员20人被疑违反劳动法 <script language"JavaScript" type"text/javascript">function doZoom(size){document.getElementById(pzoom).style.fontSizesizepx;}</script> ◇字体&#xff1a;&#xff3b;大 中 小&#xff3d; 发表评…

深度学习时代的计算机视觉

人工智能&#xff0c;作为计算机科学的一个分支。 从1956年夏季麦卡赛、明斯基、罗切斯特和申农等一批有远见卓识的年轻科学家首次提出&#xff0c;到2006年机器学习泰斗Geoffrey Hinton和他的学生RuslanSalakhutdinov在《科学》上发表了一篇开启深度学习在学术界和工业界浪潮…

《软件测试管理》第14章 软件测试常见问题——(一)基础知识部分

基础知识常见问题1、 如何描述一个缺陷&#xff1f;看到这个问题&#xff0c;也许有些读者会觉得可笑&#xff1a;哪个测试人员不会描述缺陷&#xff1f;但是现实中却真的存在很多测试人员提交的缺陷需要向开发人员进行解释或者演示后&#xff0c;才能让人明白他真正要表达的意…

只有初学者才能看懂的 Spring Boot

技术语言革新极快的今天&#xff0c;尤其对于需要技术沉淀的后端工程师来说&#xff0c;靠什么实力逆风翻盘&#xff1f; 在 Java 框架尚且繁荣的当下&#xff0c;Spring Boot 无疑最火最实用的&#xff0c;也是必不可少的开源框架&#xff0c;完全有实力稳坐 Java 后端框架的…

ATM跨行查询也开始收费了

昨天看自己的农户帐单记录&#xff0c;发现有两笔0.3元&#xff0c;原来跨行查询也开始收费了。 Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId913385

第11周学习进度

时间 学习花费的时间代码量博客量了解到的知识点第11周 周一晚上&#xff08;9:00-10:00&#xff09;看了一些jsp的视频 周二&#xff08;8:00-9:50&#xff09;软件工程概论 周二&#xff0c;周三&#xff0c;周四下午都拿出了两个小时来学android 15003代码的规范&#xff…

有中国特色的测试论坛

看了很多论坛&#xff0c;也和很多行业的兄弟交流过。多数对测试论坛的帖子颇有感触&#xff0c;于是很多高手不爱上测试论坛。仔细看看&#xff0c;主要有下面几类&#xff1a;发帖子找测试工具下载地址、license的&#xff0c;尤其是测试工具&#xff0c;这个最多。在论坛互喷…

物联网技术周报第 117 期: 使用 Node-RED、Docker 和 resin.io 将 Serverless 扩展到物联网边缘...

新闻\\\ 《物联网时代OS&#xff1a;亚马逊开源Amazon FreeRTOS!》Amazon FreeRTOS 是微控制器的操作系统&#xff0c;它使小型、低功耗的边缘设备易于编程、部署、安全&#xff0c;连接和管理。Amazon FreeRTOS 基于 FreeRTOS 内核&#xff0c;这是一款面向微控制器的流行开源…

为什么一些书店买不到《Web性能测试实战》

原因通常有两个&#xff1a;1、这本书已经卖光了。2、 分类放错了&#xff0c;多数书店把本书放到了“Web开发类”。下次准备把书换成《软件性能测试模型及应用》&#xff0c;这样就会被放到软件工程类了。Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId888202