Centos 7.2 上搭建mysql + php + nginx 简洁流程
简化教程,只要一步步照着操作就可以了。把复杂的事情简单化。
**
**
#安装编译环境
yum install -y gcc gcc-c++ gcc-devel g++ g++-devel;
yum install -y wget
yum install -y tar
#创建mysql用户组及用户
groupadd -f mysql
useradd -g mysql mysql
#编译mysql
#安装依赖
yum install -y ncurses ncurses-devel
yum install -y cmake
#下载压缩包
官方地址:https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.35.tar.gz
下载后上传到服务器上你想存放的位置
#解压mysql包
tar -xf mysql-5.6.35.tar.gz
cd mysql-5.6.35.tar.gz
#创建mysql的data数据目录
mkdir -p /data/mysql/data
chown -R mysql:mysql /data/mysql
#编译,主要注意几个目录以及端口(大约十来分钟完成)
cmake -DCMAKE_INSTALL_PREFIX=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysql/data -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DSYSCONFDIR=/data/mysql -DEXTRA_CHARSETS=all -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/data/mysql/boost
#安装
make -j 4 && make install
#配置数据库
cd /data/mysql
#安装autoconf库依赖
yum -y install autoconf
#初始化数据库
./scripts/mysql_install_db --basedir="/data/mysql" --datadir="/data/mysql/data"
chown -R mysql:mysql 、/data/mysql/data/
#复制服务到init.d目录
cp /data/mysql/support-files/mysql.server /etc/init.d/mysql
#将mysql服务加入chkconfig管理列表 ,然后就可以用service进行操作
chkconfig /etc/init.d/mysql
#开机自启动
chkconfig mysql on
#软链接(快捷方式),方便直接使用mysql客户端和备份命令
ln -s /data/mysql/bin/mysql /bin/mysql
ln -s /data/mysql/bin/mysqldump /bin/mysqldump
#新建日志目录和文件
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql /var/log/mariadb/
#最后检查mysql目录下 my.cnf 配置文件,无误后启动mysql服务,碰到权限问题则给mysql读写权限,启动出现错误时,有可能是存在进程,可以运行service mysql stop再运行service mysql start
service mysql start
#关闭命令
service mysql stop
#重启命令
service mysql restart
#客户端第一次登陆数据库,没有密码的
mysql -uroot -p
#修改默认密码
set password for 用户名@localhost = password('新密码');
**
**
#安装依赖
yum install -y libxml2-devel
yum install -y bzip2-devel
yum install -y libcurl-devel
yum install -y libjpeg-devel libpng-devel freetype-devel
#手动安装libmcrypt依赖
下载地址:https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/
tar -xf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
#配置 自定义安装目录
./configure --prefix=/usr/local/libmcrypt
#开始安装
make -j 4 && make install
cd ../
php下载地址:http://cn2.php.net/distributions/php-7.2.9.tar.gz
tar -xf php-7.2.9.tar.gz
cd php-7.2.9
#配置信息
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip
#查看openssl路径
which openssl
#配置openss
export PHP_OPENSSL_DIR=yes
./configure -with-openssl-dir=/usr/bin/openssl
/usr/include/openssl是openssl路径
#开始安装
make -j 4 && make install
#配置相应的文件
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/sbin/php-fpm /usr/local/bin
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
#配置php用户
vim /usr/local/etc/php-fpm.d/www.conf
默认user和group的设置为nobody,将其改为自己新建的用户和组
#启动php-fpm服务
/usr/local/bin/php-fpm
#php安装完成后查看9000端口和php版本
netstat -ntlp | grep 9000
php -v
先下载安装pcre和zlib以及nginx
pcre下载地址:https://jaist.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz
zlib下载地址:https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
nginx下载地址:http://nginx.org/download/nginx-1.9.15.tar.gz
#解压依赖包
tar -xf pcre-8.39.tar.gz
tar -xf zlib-1.2.10.tar.gz
tar -xf nginx-1.9.15.tar.gz
cd nginx-1.9.15
yum install -y openssl openssl-devel
#配置(注意:pcre和zlib的配置路径跟你安装的路径要一致)
./configure --sbin-path=/usr/local/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.39 --with-zlib=/usr/local/src/zlib-1.2.11
#开始安装
make -j 4 && make install
#配置nginx
(1)创建根目录和日志目录:
mkdir /data/wwwroot
mkdir -p /data/logs/nginx
(2)修改配置文件
user www;
worker_processes 8;
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;
error_log /data/logs/nginx/error.log;
pid nginx.pid;
events {
worker_connections 65535;
multi_accept on;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data/logs/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 120;
add_header Access-Control-Allow-Origin "*";
server_names_hash_bucket_size 128;
gzip on;
server {
listen 80;
server_name localhost;#此处为你自己的域名
rewrite ^(.*) https://$server_name$1 permanent;#将HTTP访问方式强制转接到HTTPS访问方式上
}
server{
listen 443 ssl;
server_name localhost; #这里配置域名
root /data/wwwroot;
ssl on;
ssl_certificate 这里是ssl证书的路径.crt;
ssl_certificate_key 这里是ssl证书的路径.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
index index.html index.htm index.php;
}
location ~ \.php {
root /data/wwwroot;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/php$fastcgi_script_name;
include fastcgi_params;
set $path_info "";
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
}
include 'conf/*.conf';
}
(3)用www用户启动nginx
创建用户组
groupadd www
创建www用户:
useradd -g www www
启动nginx:
/usr/local/nginx/nginx
关闭nginx:
/usr/local/nginx/nginx -s stop
启动完成后,需要检查云服务器的安全组配置,一键放通常用端口
参考文章:
https://www.cnblogs.com/myIvan/p/9533474.html
https://www.cnblogs.com/achengmu/p/9517337.html