安装依赖
yum install gcc \
gcc-c++ \
libxml2 \
libxml2-devel \
openssl \
openssl-devel \
libcurl \
libcurl-devel \
freetype \
freetype-devel \
libjpeg \
libjpeg-devel \
libpng \
libpng-devel \
libxslt \
libxslt-devel \
systemd-devel \
libicu-devel \
libedit-devel
一.下载nginx包并解压(到/usr/local/src目录中)
cd /usr/local/src
wget http://nginx.org/download/nginx-1.9.9.tar.gz
tar -zxvf nginx-1.9.9.tar.gz
编译安装(到/usr/local/nginx目录中)
cd nginx-1.9.9
./configure --prefix=/usr/local/nginx
make
make install
创建并设置nginx运行账号:
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
vi 编辑nginx.conf文件,修改如下如下:
user nginx nginx
添加nginx为系统服务(service nginx start/restart/stop)
在/etc/init.d/目录下编写脚本,命名为nginx
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
killall -9 nginx
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
如果防火墙没开启80端口,默认是没法访问到nginx
二.安装Mysql
卸载已有mysql,查看是否已安装mysql/mariadb:
rpm -qa mysql
rpm -qa | grep mariadb
有则卸载:(nondeps:相对应的文件名)
rpm -e --nodeps
存在/etc/my.cnf,则需要先删除:
rm /etc/my.cnf
1.添加 MariaDB yum 仓库
在系统中/etc/yum.repos.d/目录下添加 MariaDB 的YUM配置文件MariaDB.repo文件。
vi /etc/yum.repos.d/MariaDB.repo
内容如下:
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.2/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
2.安装 MariaDB
yum install MariaDB-server MariaDB-client -y
MariaDB 安装完毕后,立即启动数据库服务守护进程
systemctl start mariadb
设置 MariaDB 在操作系统重启后自动启动服务
systemctl enable mariadb
查看 MariaDB 服务当前状态
systemctl status mariadb
通过以下命令进行安全配置,根据实际情况用Y/N回复以下问题:设置 MariaDB 的 root 账户密码,删除匿名用户,禁用 root 远程登录,删除测试数据库,重新加载权限表。
若想远程访问MySQL可以在nginx.conf设置反向代理,添加如下:
stream{
server {
listen 8881;
proxy_connect_timeout 1s;
proxy_timeout 3s;
proxy_pass 127.0.0.1:3306;
}
}
防火墙开通要监听的端口,监听的端口要大于1024
三.安装PHP
PHP的安装依赖包前面已经安装了,不需要重复操作
cd /usr/local/src
wget http://cn2.php.NET/distributions/php-7.2.8.tar.gz
tar zxvf php-7.2.8.tar.gz
enable 是启用 PHP 源码包自带,但是默认不启用的扩展。with 是指定扩展依赖的资源库的位置。
./configure --prefix=/usr/local/php7 \
--with-config-file-path=/usr/local/php7/etc \
--with-config-file-scan-dir=/usr/local/php7/etc/conf.d \
--disable-cgi \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-ftp \
--with-curl \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libedit \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-pgsql \
--with-xsl \
--with-zlib \
--with-mhash \
--with-png-dir=/usr/lib \
--with-jpeg-dir=/usr/lib\
--with-freetype-dir=/usr/lib \
--enable-mysqlnd \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-gd-jis-conv \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip \
--enable-calendar \
--enable-intl \
--enable-exif
make && make install
将php包解压目录中的配置文件放置到正确位置(configure命令中的--with-config-file-path设置的位置)
cp php.ini-development /usr/local/php7/etc/php.ini
创建并设置php-fpm运行账号
groupadd www-data
useradd -M -g www-data -s /sbin/nologin www-data
cd /usr/local/php7/etc
cp php-fpm.conf.default php-fpm.conf
vi php-fpm.conf
配置nginx支持php
location ~ \.php?.*$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
修改完成之后记得重启nginx服务: