一、安装准备
首先由于nginx的一些模块依赖一些lib库,所以在安装nginx之前,必须先安装这些lib库,这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 所以执行如下命令安装
[html] view plaincopy
$ yum install gcc-c++
$ yum install pcre pcre-devel
$ yum install zlib zlib-devel
$ yum install openssl openssl--devel
二、安装Nginx
安装之前,最好检查一下是否已经安装有nginx
[html] view plaincopy
$ find -name nginx
如果系统已经安装了nginx,那么就先卸载
[html] view plaincopy
$ yum remove nginx
首先进入/usr/local目录
[html] view plaincopy
$ cd /usr/local
从官网下载最新版的nginx
[html] view plaincopy
$ wget http://nginx.org/download/nginx-1.13.2.tar.gz
解压nginx压缩包
[html] view plaincopy
$ tar -zxvf nginx-1.13.2.tar.gz
会产生一个nginx-1.13.2 目录,这时进入nginx-1.13.2目录
[html] view plaincopy
$ cd nginx-1.13.2
接下来安装,使用--prefix参数指定nginx安装的目录,make、make install安装
[html] view plaincopy
$ ./configure $默认安装在/usr/local/nginx
$ make
$ make install
如果没有报错,顺利完成后,最好看一下nginx的安装目录
[html] view plaincopy
$ whereis nginx
三、安装PHP7
下载php7
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.7.tar.gz/from/this/mirror
解压php7
tar -xvf php7.tar.gz
进入php目录
cd php-7.1.7
安装依赖包
# 直接复制下面一行(不包括本行)
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
编译配置(如果出现错误,基本都是上一步的依赖文件没有安装所致)
错误描述:
#yum install libmcrypt libmcrypt-devel mcrypt mhash
Setting up Install Process
No package php-mcrypt available.
Error: Nothing to do
我们会看到centos yum从仓库中根本找不到这几个包。但我不想使用源码编译就想使用yum安装,怎么办?
解决方法:
yum install epel-release //扩展包更新包
yum update //更新yum源
yum install libmcrypt libmcrypt-devel mcrypt mhash 就ok了
嫌麻烦的可以从这一步起参考PHP官方安装说明:http://php.net/manual/zh/install.unix.nginx.php
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mcrypt \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-libmbfl \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache
正式安装
make && make install
配置环境变量
vi /etc/profile
在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
执行命令使得改动立即生效
source /etc/profile
配置php-fpm
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
启动php-fpm
/etc/init.d/php-fpm start
提示 cannot get uid for user ‘nginx’
解决 adduser nginx 就ok
安装mysql5.7
# 下载mysql源安装包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安装mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
shell> yum install mysql-community-server
启动服务
shell> systemctl start mysqld
重启 restart
查看启动状态
systemctl status mysqld
设置开机启动
shell> systemctl enable mysqld
shell> systemctl daemon-reload
修改root默认密码
mysql安装完成之后,在/var/log/mysqld.log文件中给root生成了一个默认密码。通过下面的方式找到root默认密码,然后登录mysql进行修改:
shell> grep ‘temporary password‘ /var/log/mysqld.log
mysql> set password for ‘root‘@‘localhost‘=password(‘MyNewPass4!‘);
mysql> FLUSH PRIVILEGES;
—————
mysqld_safe --skip-grant-tables --skip-networking &
合盖子不休眠
vim /etc/systemd/logind.conf
HandleLidSwitch= suspend 改为lock
重启服务systemctl restart systemd-logind生效
查看默认的target,执行:
systemctl get-default
开机以命令模式启动,执行:
systemctl set-default multi-user.target
开机以图形界面启动,执行:
systemctl set-default graphical.target
iptables
重启
systemctl restart iptables
or
/etc/rc.d/init.d/iptables restart
1) 重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop
2. 即使安装了iptables也需要开放80端口。
----如下去装iptables-servie
yum install iptables-services
vi /etc/sysconfig/iptables
添加如下一行
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT