1.安装nginx
wget http://nginx.org/download/nginx-1.12.2.tar.gz #下载nginx安装包
tar -zxvf nginx-1.12.2.tar.gz #解压nginx安装包
cd nginx-1.12.2 #进入nginx目录
yum -y install gcc gcc-c++ make libtool zlib zlib-devel pcre pcre-devel perl-devel perl-ExtUtils-Embed perl-WWW-Curl wget #安装nginx需要的依赖包
cd nginx-1.12.0/
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_ssl_module #编译nginx
make&&makin install
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/ #创建软连接
vim /lib/systemd/system/nginx.service #交给systemd托管nginx
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
PIDFile =/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service
2.安装mysql
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm #创建mysql仓库
yum -y install mysql-community-server #安装mysql
systemctl start mysqld
systemctl enable mysqld
grep 'temporary password' /var/log/mysqld.log #查看mysql密码
mysql -uroot -p #登录mysql
alter user root@'localhost' identified by '密码‘;
show variables like '%password%'; 查看密码策略
set global validate_password_length=6;
set global validate_password_policy=0;#修改密码策略
alter user root@’localhost‘ identified by ’密码‘;
3.安装php
rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm #搭建php仓库
yum -y install php70w-tidy php70w-common php70w-devel php70w-pdo php70w-mysql php70w-gd php70w-ldap php70w-mbstring php70w-mcrypt php70w-fpm
php -v #查看是否安装
systemctl start php-fpm
systemctl enable php-fpm
修改nginx配置文件以支持PHP。
执行以下命令打开配置文件“default.conf”。
vim /etc/nginx/conf.d/default.conf
按i键进入编辑模式。
修改打开的“default.conf”文件。
在所支持的主页面格式中添加php格式的主页,如下所示:
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
取消如下内容的注释,并设置字体加粗部分为nginx的默认路径,如下图所示:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
按Esc键退出编辑模式,并输入:wq保存后退出
执行以下命令,重新载入nginx的配置文件
service nginx reload
浏览器访问测试
在/usr/share/nginx/html/目录下创建“info.php”的测试页面
执行以下命令创建并打开“info.php”的测试文件
vim /usr/share/nginx/html/info.php
按i键进入编辑模式。
修改打开的“info.php”文件,将如下内容写入文件
<?php
phpinfo();
?>
按Esc键退出编辑模式,并输入:wq保存后退出。
使用浏览器访问“http://服务器IP地址/info.php”,显示如下页面,说明环境搭建成功