系统:centos7最小安装
工具:VMware
版本:
1. mysql-5.5.62
2. php-5.5.33
3. nginx-1.12.0
安装lrzsz工具和wget工具
#安装lrzsz工具
yum -y install lrzsz
#安装wget
yum -y install wget
1. 安装mysql
安装依赖包:
yum -y install make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof cmake
tar xvf mysql-5.5.62.tar.gz
创建数据存储文件夹和日志存储文件夹
mkdir /data
mkdir /data/mysql
mkdir /data/logs
mkdir /data/logs/mysql
#赋权
chown -R mysql:mysql /data/logs/mysql
#创建报错日志
cd /data/logs/mysql
touch error.log
创建mysql用户组和用户
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
利用cmake工具进行编译,具体功能此处不做过多解释,如需了解请参考:
centos7源码编译php: https://blog.csdn.net/qq_26741767/article/details/85858606
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULE_CHARSET=utf8 -DDEFAULE_COLLATION=utf8_general_ci -DEXTAR_CHARSETS=all -DSYSCONFIDIR=/data/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DWITH_INNOBASE_STORANGE_ENGIN=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysql -DWITH_BOOST=boost -DWITH_SYSTEMD=1
编译安装
make
make install
为mysql文件赋权
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /data/mysql
设置环境变量并使其生效
#环境变量
echo 'PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile
#全局变量
echo 'export PATH' >> /etc/profile
#变量生效
source /etc/profile
修改my.cnf配置文件
#备份默认生成的配置文件
mv /etc/my.cnf /etc/my.cnf.bak
vi /etc/my.cnf
#配置内容可以参考如下:
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
tmpdir=/tmp
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/data/logs/mysql/error.log
pid-file=/data/mysql/mysql.pid
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
初始化:
cd /usr/local/mysql
scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql
添加系统脚本
#拷贝脚本到init.d目录
cp support-files/mysql.server /etc/init.d/mysql
#赋予权限、设置开机自启并启动
chmod +x /etc/init.d/mysql
chkconfig mysql on
启动数据库
systemctl restart mysql
更新mysql的帐号密码了:
#输入mysql,进入mysql命令台(图标会变为mysql>)
mysql \
#更新帐号密码(mysql命令逗号不可省略)
#1. 查看数据库
show databases; \
#2. 使用mysql默认的数据库
use mysql; \
#3. 更新root用户的密码
update user set password=password("root") where user="root";
#4. 刷新
flush privileges;
#5. 退出数据库
quit;
#6. 使用用户密码重新连接数据库
mysql -u root -p \
#密码不会显示,可以直接输入密码后回车
root
2. 安装php
安装依赖
yum install epel-release libmcrypt libmcrypt-devel mcrypt mhash libxslt-devel postgresql-devel
解压缩安装包
tar xvf php-5.5.33.tar.gz
编译
cd php-5.5.33
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --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-session --enable-ftp --enable-pdo --enable-tokenizer --with-pdo-mysql --with-pdo-pgsql
编译安装
make
#make test建议进行,可以检测是否缺失什么模块
make test
make install
修改fpm配置php-fpm.conf.default文件名称
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
复制php.ini配置文件
cp php.ini-production /usr/local/php/etc/php.ini
复制php-fpm启动脚本到init.d
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
赋予执行权限
chmod +x /etc/init.d/php-fpm
添加为启动项,设置开机启动
chkconfig --add php-fpm
chkconfig php-fpm on
创建群组和用户
groupadd www
useradd -s /sbin/nologin -g www -M www
添加环境变量并使其生效
vi /etc/profile
#在最后添加以下内容:
export PATH="$PATH:/usr/local/php/bin:"
#使其生效
source /etc/profile
启动php-fpm
systemctl start php-fpm
1. 安装nginx
创建群组和用户
groupadd -r nginx
useradd -s /sbin/nologin -g nginx -M nginx
解压安装包
tar xvf nginx-1.12.0.tar.gz
创建目录
mkdir /var/tmp/nginx
mkdir /var/tmp/nginx/client
mkdir /data/nginx
编译
cd nginx-1.12.0
./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/bin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --error-log-path=/data/logs/nginx/error.log --http-log-path=/data/logs/nginx/access.log --pid-path=/data/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi --http-scgi-temp-path=/var/tmp/nginx/scgi --with-pcre
编译安装
make
make install
启动
/usr/local/nginx/bin/nginx
添加系统启动
vi /etc/rc.local
#在最后添加以下内容:
/usr/local/nginx/bin/nginx -c /usr/local/nginx/conf/nginx.conf &
添加环境变量并生效
vi /etc/profile
#在最后添加以下内容:
export PATH="$PATH:/usr/local/nginx/bin:"
#使其生效
source /etc/profile
添加nginx脚本到系统服务
vi /etc/rc.d/init.d/nginx
#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: /usr/local/nginx/conf/nginx.conf
# pidfile: /data/nginx/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/bin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/nginx.lock
make_dirs() {
# make required directories
user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=[]∗[]∗.*/\1/g' -`
if [ -z "`grep $user /etc/passwd`" ]; then
useradd -M -s /bin/nologin $user
fi
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
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
}
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
添加为启动项,设置开机启动
chmod 775 /etc/rc.d/init.d/nginx
chkconfig --add nginx
chkconfig nginx on
修改nginx配置文件nginx.conf
vi /usr/local/nginx/conf/nginx.conf
启用以下内容:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
创建/etc/nginx/fastcgi_params并修改其内容
#创建/etc/nginx/fastcgi_params
mkdir /etc/nginx
#编辑/etc/nginx/fastcgi_params
vi /etc/nginx/fastcgi_params
#将其内容更改为如下内容:
fastcgi_param GATEWAY_INTERFACE CGI/1.1;
fastcgi_param SERVER_SOFTWARE nginx;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param DOCUMENT_URI $document_uri;
fastcgi_param DOCUMENT_ROOT $document_root;
fastcgi_param SERVER_PROTOCOL $server_protocol;
fastcgi_param REMOTE_ADDR $remote_addr;
fastcgi_param REMOTE_PORT $remote_port;
fastcgi_param SERVER_ADDR $server_addr;
fastcgi_param SERVER_PORT $server_port;
fastcgi_param SERVER_NAME $server_name;
重新加载nginx并重启
systecmtl reload nginx
systemctl restart nginx
```
开放端口
```linux
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
```