一、安装前准备
[root@localhost ~]
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl \
apr-devel \
apr-util-devel
二、安装Nginx
1. 安装nginx依赖包
nginx的Rewrite模块和HTTP核心模块会使用到PCRE正则表达式语法:
yum -y install pcre pcre-devel
nginx的各种模块中需要使用gzip压缩:
yum -y install zlib zlib-devel
安全套接字层密码库:
yum -y install openssl openssl-devel
2. 下载nginx包并解压(到/usr/local/src目录中)
cd /usr/local/src
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar -zxvf nginx-1.12.2.tar.gz
3. 编译安装(到/usr/local/nginx目录中)
cd nginx-1.12.2
./configure --prefix=/usr/local/nginx
make
make install
4. 创建并设置nginx运行账号:
groupadd nginx
useradd -M -g nginx -s /sbin/nologin nginx
cd /usr/local/nginx/conf
vim nginx.conf,设置user参数如下:
user nginx nginx
其他配置参数暂时无需改动。
5. 设置nginx为系统服务
vim /lib/systemd/system/nginx.service
文件内容:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
6. 设置nginx开机自启动
systemctl enable nginx.service
7. 开启nginx服务:
systemctl start nginx.service
查看nginx是否启动成功:
ps aux | grep nginx
在虚拟机浏览器中访问测试:
http://localhost
出现以下界面则表示可以成功访问:
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201007213916900.png
8. 防火墙开放80端口(nginx默认使用80端口,可在nginx.conf中配置,若无需进行远程访问则不需要开放端口)
永久开放80端口:
firewall-cmd --zone=public --add-port=80/tcp --permanent
重启防火墙:
firewall-cmd --reload
查看防火墙开启状态:
systemctl status firewalld
查看80端口是否开放成功:
firewall-cmd --zone=public --query-port=80/tcp
可在windows宿主主机浏览器直接访问虚拟机ip测试是否可以成功访问。
三、安装mysql数据库
yum -y install \
ncurses-devel \
autoconf \
cmake
cd /opt
tar xf mysql-5.6.26.tar.gz
cd mysql-5.6.26/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/home/mysql/ \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
make && make install
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod 755 /etc/init.d/mysqld
chkconfig --add /etc/init.d/mysqld
chkconfig mysqld --level 35 on
echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile
echo $PATH
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql/ \
--datadir=/home/mysql/
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/home/mysql
service mysqld start
显示Starting MySQL.. SUCCESS!
netstat -anpt | grep 3306
mysqladmin -uroot -p password "abc123"
mysql -uroot -p
mysql> exit
Bye
四、安装PHP
yum -y install \
gd \
libpng \
libpng-devel \
pcre \
pcre-devel \
libxml2-devel \
libjpeg-devel
tar xjvf php-5.6.11.tar.bz2
cd php-5.6.11
./configure \
--prefix=/usr/local/php5 \
--with-gd \
--with-zlib \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring
make && make install
cp php.ini-development /usr/local/php5/php.ini
ln -s /usr/local/php5/bin/* /usr/local/bin/
ln -s /usr/local/php5/sbin/* /usr/local/sbin/
vi /etc/httpd.conf //在合适位置新增
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
vi /usr/local/httpd/htdocs/index.php
<?php
phpinfo();
?>
在网页测试“http://192.168.80.183/index.php”
转载请注明原文地址:https://blackberry.8miu.com/read-35725.html