1、下载nginx
# wget http://nginx.org/download/nginx-1.16.1.tar.gz
2、安装源码安装依赖软件:pcre-devel zlib-devel gcc gcc-c++ make
检测依赖是否安装
#rpm -q pcre-devel zlib-devel gcc gcc-c++ make openssl openssl-devel
yum安装
# sudo yum -y install pcre-devel zlib-devel gcc gcc-c++ make openssl-devel
3、创建运行用户、组
# sudo useradd -M -s /sbin/nologin nginx
4、编译安装NGINX
#tar -zxvf nginx-1.16.1.tar.gz
#cd /home/centos/nginx/nginx-1.16.1
# ./configure –prefix=/home/centos/nginx/usr/local/nginx –with-http_ssl_module –with-stream –with-mail=dynamic –user=centos –group=centos –with-http_stub_status_module
&&make && make install
#cd /home/centos/nginx/usr/local/nginx/sbin
#sudo ./nginx
5、配置nginx配置文文件
二、安装mysql
yum安装mysql
yum install -y mysql-community-server
编辑mysql配置文件
vim /etc/my.cnf
启动并加入开机自启
systemctl start mysqld
systemctl enable mysqld
初始化数据库
mysql_secure_installation
根据提示输入root用户的密码,用户mysql登录
三、源码编译安装php
1、官网下载源码包并解压
wget https://www.php.net/distributions/php-7.4.4.tar.bz2
tar xf php-7.4.4.tar.bz2
cd php-7.4.4
2、安装库依赖
yum –y install libxml2-devel bzip2 bzip2-devel libxslt-devel libpng-devel sqlite-devel
3、编译安装
./configure
–prefix=/usr/local/php 指定php安装路径
–enable-fpm web与php使用使用fast-cgi方式通信
–with-mysqli 指定连接mysql的驱动,如果没有指定则使用本机的mysql驱动程序
–with-freetype 启用FreeType 2(字体引擎)
支持
–enable-mbstring 启用多字符串支持
–with-jpeg 启用图片支持
–with-zlib
–with-apxs2
指定Apache工具APXS,启用apache模块化安装php,在此次不使用
–enable-maintainer-zts 启动线程支持,当apche是event模型时使用
make &&make install
4、创建php配置文件php.ini与php-fpm配置文件php-fpm.conf
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin
编辑php.in配置文件
vim /usr/local/php/php.ini
cgi.fix_pathinfo=0 |
编辑php-fpm文件
指名用户名及组,并在系统创建
编辑nginx配置文件,反向代理到php-fpm
location ~* .php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; }
|
5、创建php连接测试脚本
echo "<?php phpinfo(); ?>" >>index.php
创建mysql数据库测试连接脚本
cat << EOF >> mysql_test.php
<?php
$link=new mysqli("ip:port","DB_USER","DB_PASSWD");
if(!$link) echo "FAILD!连接错误,用户名密码不对";
else echo "OK!可以连接";
?>
EOF