一 、centos7 最小化安装之后,需要先开启网络服务:
ip addr
查看网卡 我的是enp0s3
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 修改boot 的值为yes
二、网络服务开启成功后,安装net-tools
yum install -y net-tools
三、安装wget,为更换阿里源做准备
yum install -y wget
四、更换yum源为阿里源
cd /etc/yum.repos.d
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum update
五、安装nginx
cd /usr/local/src
依赖包安装
yum -y install openssl openssl-devel pcre-devel
添加用户和用户组
/usr/sbin/groupadd -f www
/usr/sbin/useradd -g www www
下载源码包
wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar -zxvf nginx-1.14.0.tar.gz
编译前配置
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module
make && make install
添加到全局访问
cp /usr/local/nginx/sbin/nginx /usr/bin
开启 nginx服务
nginx
停止nginx服务
nginx -s stop
平滑重启nginx服务
nginx -s reload
访问虚拟机nginx失败的原因:
80端口没有添加到防火墙
firewall-cmd --state
firewall-cmd --zone=public --add-port=80/tcp --permanent
systemctl stop firewalld.service
systemctl start firewalld.service
六、安装php
cd /usr/local/src
依赖包安装
yum -y install libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel
wget http://hk2.php.net/get/php-7.2.8.tar.gz/from/this/mirror
tar -zxvf mirror
编译前配置
./configure \
--prefix=/usr/local/php \
--exec-prefix=/usr/local/php \
--bindir=/usr/local/php/bin \
--sbindir=/usr/local/php/sbin \
--includedir=/usr/local/php/include \
--libdir=/usr/local/php/lib/php \
--mandir=/usr/local/php/php/man \
--with-config-file-path=/usr/local/php/etc \
--with-mysql-sock=/var/run/mysql/mysql.sock \
--with-mhash \
--with-openssl \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-iconv \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--with-freetype-dir \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--without-gdbm \
--enable-fast-install \
--disable-fileinfo
编译后安装
make && make install
安装成功后配置服务等
cp /usr/local/src/php-7.2.8/php.ini-development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cp /usr/local/src/php-7.2.8/sapi/fpm/php-fpm.service /lib/systemd/system/php-fpm.service
加入环境变量
vim /etc/profile
PATH=$PATH:/usr/local/php/bin
export PATH
更新环境变量
source /etc/profile
开启php-fpm
cp /usr/local/php/sbin/php-fpm /usr/bin
php-fpm
关闭php-fpm
pkill php-fpm
开启nginx转发php请求到php-fpm服务
vi /usr/local/nginx/conf/nginx.conf 找到被注释的转发php请求的代码并打开
修改 # include fastcgi_params; 为 include fastcgi.conf;
至此,全部安装完成。
备注:
检查端口被哪个进程占用
netstat -lnp|grep 9000
查看进程的详细信息
ps 11100
杀掉进程
kill -9 11100