一、安裝Nginx
①安裝依賴擴充套件
# yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers make gd gd2 gd-devel gd2-devel libxslt libxslt-devel libaio libaio-devel
②下載Nginx原始碼包
# wget http://nginx.org/download/nginx-1.13.5.tar.gz
③建立使用者名稱和使用者組
# groupadd www
# useradd -r -g www www
④解壓並安裝
# tar -zxvf nginx-1.13.5.tar.gz
# cd nginx-1.13.5
# ./configure --user=www --group=www --prefix=/usr/local/nginx
# make && make install
⑤啟動nginx服務
# /usr/local/nginx/sbin/nginx &
⑥關閉防火牆或者開放80埠
# systemctl stop firewalld.service //關閉防火牆
# firewall-cmd --zone=public --add-port=80/tcp --permanent //開啟80埠
# firewall-cmd --reload
訪問IP,測試nginx是否安裝成功
二、安裝MySQL-5.7.19
①下載安裝包
# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
②建立mysql使用者和使用者組
# groupadd mysql
# useradd -r -r mysql mysql
③解壓安裝包並建立data目錄
# tar -zxf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
# mv mysql-5.7.19-linux-glibc2.12-x86_64 /usr/local/mysql
# cd /usr/local/mysql
# mkdir data logs
# echo "" > logs/error.log
④初始化MySQL
# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --port=3306
初始化之後會生成一個隨機的root賬號的密碼,如下(如果初始化的時候有指定log-error的路徑,則在log-error中檢視密碼);或者使用 --initialize-insecure 不生成隨機密碼
⑤授權
# cd /usr/local
# chown -R mysql:mysql mysql
⑥啟動MySQL服務
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
⑦資料庫配置
# vim /etc/my.cnf
[client]
port=3306
socket=/tmp/mysql.sock
default-character-set=utf8
[mysql]
no-auto-rehash
default-character-set=utf8
[mysqld]
user = mysql
port = 3306
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = mysql3306.pid
log-error=/usr/local/mysql/logs/error.log
skip_name_resolve = 1
open_files_limit = 65535
back_log = 1024
max_connections = 1500
max_connect_errors = 1000000
table_open_cache = 1024
table_definition_cache = 1024
table_open_cache_instances = 64
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 2250
query_cache_size = 0
query_cache_type = 0
interactive_timeout = 600
wait_timeout = 600
tmp_table_size = 96M
max_heap_table_size = 96M
###***slowqueryparameters
long_query_time = 0.1
slow_query_log = 1
slow_query_log_file = /usr/local/mysql/logs/slow.log
###***binlogparameters
log-bin=mysql-bin
binlog_cache_size=4M
max_binlog_cache_size=8M
max_binlog_size=1024M
binlog_format=MIXED
expire_logs_days=7
###***master-slavereplicationparameters
server-id=3306
#slave-skip-errors=all
[mysqldump]
quick
max_allowed_packet=32M
⑧拷貝服務檔案
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
⑨重啟MySQL服務
# /etc/init.d/mysqld restart
⑩配置環境變數
# vi /etc/profile
#最後一行新增以下兩行:
export MYSQL_HOME=/usr/local/mysql
export PATH=$PATH:$MYSQL_HOME/bin
#儲存退出
source /etc/profile
①①修改root密碼
mysql -uroot -p mysql
SET password=PASSWORD("123456");
①②設定開機自啟
chkconfig --add mysqld
chkconfig mysqld on
三、安裝PHP
①安裝依賴庫——libmcrypt
# wget http://downloads.sourceforge.net/mcrypt/libmcrypt-2.5.8.tar.gz
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8/
# ./configure
# make && make install
# /sbin/ldconfig
# cd libltdl/
# ./configure --enable-ltdl-install
# make && make install
# ln -sf /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
# ln -sf /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
# ln -sf /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
# ln -sf /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
# ldconfig
②安裝依賴庫——mhash
# wget http://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
# tar zxvf mhash-0.9.9.9.tar.gz
# cd mhash-0.9.9.9/
# ./configure
# make && make install
# ln -sf /usr/local/lib/libmhash.a /usr/lib/libmhash.a
# ln -sf /usr/local/lib/libmhash.la /usr/lib/libmhash.la
# ln -sf /usr/local/lib/libmhash.so /usr/lib/libmhash.so
# ln -sf /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
# ln -sf /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
# ldconfig
③安裝依賴庫——mcrypt
# wget http://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
# tar zxvf mcrypt-2.6.8.tar.gz
# cd mcrypt-2.6.8/
# ./configure
# make && make install
④下載PHP安裝包
# wget -O php-7.1.10.tar.gz http://hk1.php.net/get/php-7.1.10.tar.gz/from/this/mirror
⑤解壓安裝包編譯安裝
# tar -zxf php-7.1.10.tar.gz
# cd php-7.1.10
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli --with-pdo-mysql --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --disable-fileinfo --enable-maintainer-zts --enable-opcache --with-xsl --enable-freetype --enable-sysvshm
# make && make install
⑥修改配置檔案
# cp php.ini-development /usr/local/php/etc/php.ini
# cp ./sapi/fpm/php-fpm.conf /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
⑦php-fpm隨系統自啟動
# cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
⑧啟動PHP
# /usr/local/php/sbin/php-fpm
⑨設定PHP的環境變數
# vim /etc/profile
export PHP_HOME=/usr/local/php
export PATH=$PATH:$PHP_HOME/bin
#重啟生效
# source /etc/profile
⑩設定開啟自啟動
# cd /etc/init.d/
# chmod 744 php-fpm
# chkconfig --add php-fpm
# chkconfig php-fpm on
配置Nginx支援PHP
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
#fastcgi_pass 127.0.0.1:9000;
#fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
}