Centos 7 安装PHP5.5 5.6 7.2

安装和启用EPELRemi存储库

yum update
yum upgrade

yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

接下来,安装yum-utils,它是与yum集成的各种实用程序,以增强其默认功能,为其提供更高级的包管理选项,并使其更易于使用。它的一些重要功能包括操作存储库,在运行中启用或禁用包等,而无需任何手动配置。

yum install yum-utils

yum-utils提供的最重要的程序之一是yum-config-manager,您可以使用它来激活Remi存储库作为安装各种PHP版本的默认存储库。例如,如果要在CentOS 7上安装PHP 5.5PHP 5.6PHP 7.2,只需启用它并如图所示进行安装(以下命令三选一)。

yum-config-manager --enable remi-php55 [ 安装PHP 5.5 ] 
yum-config-manager --enable remi-php56 [ 安装PHP 5.6 ]
yum-config-manager --enable remi-php72 [ 安装PHP 7.2 ]

在启用了PHP的选定版本后,您就可以安装PHP(这里,我们选择安装PHP 5.6)以及所有需要的模块了,如下所示

yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo php-mbstring php-common php-pdo php-devel php-fpm

需要注意的重要事项:如果您出于某种原因想要降级PHP版本,则需要删除现有的PHP版本,然后使用所需的模块重新安装新的PHP。

Centos 添加新用户,并授root权限,禁用root帐号登陆

1.添加新用户user

adduser user
passwd user

新创建的用户并不能使用sudo命令,需要给他添加授权,授权需要修改/etc/sudoers文件内容,此文件默认为只读权限,要想修改内容的话,需先给此文件添加w(可写)权限。

chmod -v u+w /etc/sudoers

然后就可以添加内容了:

vi /etc/sudoers

在此处增加user用户权限声明:
## Allow root to run any commands anywher
root ALL=(ALL) ALL
user ALL=(ALL) ALL #这个是新增的一行权限声明
:wq保存退出,这时候要记得将写权限收回:

chmod -v u-w /etc/sudoers

2.禁用root用户:
修改 /etc/ssh/sshd_config文件

vi /etc/ssh/sshd_config

将#PermitRootLogin yes
修改为
PermitRootLogin no
重启ssh服务

 service sshd restart

大功告成!

Iptables配置禁止外网访问

iptables:
开22外网端口
iptables -A INPUT -p tcp –dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp –sport 22 -j ACCEPT
允许整个地址段访问:
iptables -A INPUT -s 10.25.96.0/20 -p tcp -j ACCEPT

禁止某个IP
iptables -A INPUT -p tcp -s 192.168.1.2 -j DROP
显示IPtables行数
iptables -L -n –line-number
删除某条规则
iptables -D INPUT 2c

保存
service iptables save

重启iptables
service iptables restart

========================================================

How To Install Nginx on CentOS 7

About Nginx

Nginx is a high performance web server software. It is a much more flexible and lightweight program than Apache HTTP Server.This tutorial will teach you how to install and start Nginx on your CentOS 7 server.

Prerequisites

The steps in this tutorial require the user to have root privileges. You can see how to set that up by following steps 3 and 4 in the Initial Server Setup with CentOS 7 tutorial.

Step One—Add Nginx Repository

To add the CentOS 7 EPEL repository, open terminal and use the following command:

sudo yum install epel-release

Step Two—Install Nginx

Now that the Nginx repository is installed on your server, install Nginx using the following yum command:

sudo yum install nginx

After you answer yes to the prompt, Nginx will finish installing on your virtual private server (VPS).

Step Three—Start Nginx

Nginx does not start on its own. To get Nginx running, type:

sudo systemctl start nginx

If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

sudo firewall-cmd --permanent --zone=public --add-service=http 
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload

You can do a spot check right away to verify that everything went as planned by visiting your server’s public IP address in your web browser (see the note under the next heading to find out what your public IP address is if you do not have this information already):

http://server_domain_name_or_IP/

You will see the default CentOS 7 Nginx web page, which is there for informational and testing purposes. It should look something like this:

If you see this page, then your web server is now correctly installed.Before continuing, you will probably want to enable Nginx to start when your system boots. To do so, enter the following command:

sudo systemctl enable nginx

Congratulations! Nginx is now installed and running!

How To Find Your Server’s Public IP Address

To find your server’s public IP address, find the network interfaces on your machine by typing:

ip addr
1. lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
. . .
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000


. . .You may see a number of interfaces here depending on the hardware available on your server. The lo interface is the local loopback interface, which is not the one we want. In our example above, the eth0 interface is what we want.Once you have the interface name, you can run the following command to reveal your server’s public IP address. Substitute the interface name you found above:

ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

Server Root and Configuration

If you want to start serving your own pages or application through Nginx, you will want to know the locations of the Nginx configuration files and default server root directory.

Default Server Root

The default server root directory is /usr/share/nginx/html. Files that are placed in there will be served on your web server. This location is specified in the default server block configuration file that ships with Nginx, which is located at

/etc/nginx/conf.d/default.conf.

Server Block Configuration

Any additional server blocks, known as Virtual Hosts in Apache, can be added by creating new configuration files in

/etc/nginx/conf.d

Files that end with .conf in that directory will be loaded when Nginx is started.

Nginx Global Configuration

The main Nginx configuration file is located at /etc/nginx/nginx.conf. This is where you can change settings like the user that runs the Nginx daemon processes, and the number of worker processes that get spawned when Nginx is running, among other things.

See More

Once you have Nginx installed on your cloud server, you can go on to install a LEMP Stack.