环境
防火墙,selinux关闭
应用 | IP | 操作系统 |
nginx | 192.168.248.15 | centos8 |
mysql | 192.168.248.16 | centos8 |
php | 192.168.248.17 | centos8 |
安装nginx
#安装依赖环境 [root@nginx ~]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget [root@nginx ~]# yum -y groups mark install 'Development Tools' #下载nginx包 [root@nginx ~]# wget http://nginx.org/download/nginx-1.20.0.tar.gz #创建nginx系统用户 [root@nginx ~]# useradd -r -M -s /sbin/nologin nginx #创建日志存放目录 [root@nginx ~]# mkdir -p /var/log/nginx [root@nginx ~]# chown -R nginx.nginx /var/log/nginx #编译安装nginx [root@nginx ~]# tar -xf nginx-1.20.0.tar.gz [root@nginx ~]# cd nginx-1.20.0 [root@nginx nginx-1.20.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log [root@nginx nginx-1.20.0]# make && make install #配置环境变量 [root@nginx nginx-1.20.0]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh [root@nginx nginx-1.20.0]# . /etc/profile.d/nginx.sh #修改配置文件 [root@nginx ~]# vim /usr/local/nginx/conf/nginx.conf location / { root html; #添加index.php index index.php index.html index.htm; } location ~ .php$ { # 设置监听端口 fastcgi_pass 192.168.248.17:9000; # 设置nginx的默认首页文件 fastcgi_index index.php; # 设置脚本文件请求的路径 fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name; 将$scripts修改为php根网站目录 #引入fastcgi的配置文件 include fastcgi_params; } #检查语法是否有误 [root@nginx ~]# nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful #创建ndex.php [root@nginx ~]# cat > /usr/local/nginx/html/index.php <<EOF > <?php > phpinfo(); > ?> > EOF #启动服务 [root@nginx ~]# nginx
安装配置mysql
#mysql包比较大已经提前下载好了 wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz #安装依赖环境 [root@mysql ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs #创建用户 [root@mysql ~]# useradd -r -M -s /sbin/nologin mysql #安装mysql [root@mysql ~]# tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@mysql ~]# ln -sv /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64/ /usr/local/mysql [root@mysql ~]# cd /usr/local/ [root@mysql local]# chown -R mysql.mysql mysql* #添加环境变量 [root@mysql local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/myslq.sh [root@mysql local]# source /etc/profile.d/myslq.sh [root@mysql local]# ln -s /usr/local/mysql/include/ /usr/include/mysql [root@mysql local]# echo '/usr/local/mysql/lib' >/etc/ld.so.conf.d/mysql.conf [root@mysql local]# ldconfig #创建数据存放目录 [root@mysql local]# mkdir /opt/mydata [root@mysql local]# chown -R mysql.mysql /opt/mydata/ #初始化数据库不用密码 [root@mysql local]# mysqld --initialize-insecure --user=mysql --datadir=/opt/mydata #生成配置文件 [root@mysql local]# cat > /etc/my.cnf <<EOF [mysqld] basedir=/usr/local/mysql datadir=/opt/mydata socket=/tmp/mysql.sock port=3306 pid-file=/opt/mydata/mysql.pid user=mysql skip-name-resolve EOF #配置服务启动脚本 [root@mysql local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld [root@mysql local]# sed -ri 's#^(basedir=).*#1/usr/local/mysql#g' /etc/init.d/mysqld [root@mysql local]# sed -ri 's#^(datadir=).*#1/opt/mydata#g' /etc/init.d/mysqld #启动MySQL [root@mysql local]# service mysqld start #设置密码 [root@mysql local]# mysql -e "set password = password('123')"
安装php
[root@localhost tmp]# yum -y install php* [root@localhost tmp]# vim /etc/php-fpm.d/www.conf ...................... ;listen = /run/php-fpm/www.sock #注释此行 listen = 0.0.0.0:9000 #添加监听端口 ........................... ........................... ; must be separated by a comma. If this value is left blank, connections will be ; accepted from any ip address. ; Default Value: any listen.allowed_clients = 192.168.248.15 #nginx主机的ip [root@localhost tmp]# cat /var/www/html/index.php <?php phpinfo(); ?> [root@localhost tmp]# chown -R nginx.nginx /var/www/html/ [root@localhost tmp]# systemctl start php-fpm
网站访问测试