参考:https://www.cnblogs.com/phpshangxiaobai/p/10864525.html
(php7.3.5 + nginx1.16 + mysql8)
1、准备
#新建目录,/lnmp/php7、/lnmp/nginx mkdir -p /lnmp/php7 mkdir /lnmp/nginx #安装依赖 yum install gcc gcc-c++ automake pcre pcre-devel zlip zlib-devel openssl openssl-devel libxml2-devel libpng-devel curl-devel numactl
2、安装nginx
cd /lnmp yum -y install wget #安装wget wget http://nginx.org/download/nginx-1.16.0.tar.gz #下载nginx tar xvf nginx-1.16.0.tar.gz #解压 cd nginx-1.16.0 ./configure --prefix=/lnmp/nginx --with-http_ssl_module #安装到/lnmp/nginx make && make install #编译&安装 cp /lnmp/nginx/sbin/nginx /usr/bin/ nginx #开启 nginx -s stop #关闭 nginx -s reload #平滑重启
安装后可能会遇到的问题
#nginx配置位置:/lnmp/nginx/conf/nginx.conf #站点目录位置:/lnmp/nginx/html #搭好后,本地无法访问 #关闭防火墙 sudo systemctl stop firewalld #允许访问80端口 /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT #此时就可以访问了
4、安装php
cd /lnmp wget https://www.php.net/distributions/php-7.3.5.tar.gz tar xvf php-7.3.5.tar.gz cd php-7.3.5 ./configure --prefix=/lnmp/php7 --enable-fpm --with-mysqli --with-curl --with-pdo_mysql --with-pdo_sqlite --enable-mysqlnd --enable-mbstring --with-gd make && make install cp php.ini-development /lnmp/php7/lib/php.ini cd /lnmp/php7/etc/ #重命名 mv php-fpm.conf.default php-fpm.conf mv php-fpm.d/www.conf.default php-fpm.d/www.conf cp /lnmp/php7/sbin/php-fpm /usr/bin/ #修改配置文件php.ini,(/lnmp/php7/lib/php.ini) cgi.fix_pathinfo=0 php-fpm #开启 killall php-fpm #关闭
安装后可能会遇到的问题
#访问php文件,变成下载 vi /lnmp/nginx/conf/nginx.conf #找到下面这段,将注释去掉 ### location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ### #访问php文件,出现No input file specified 将上面的location ~ \.php$ {...} fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 替换为 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #保存重启nginx nginx -s reload
5、安装mysql
cd /lnmp #下载 wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz #解压 tar -Jxf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz #移到lnmp目录,重命名mysql mv mysql-8.0.18-linux-glibc2.12-x86_64 /lnmp/mysql cd /lnmp/mysql mkdir data #用于存放数据 #创建mysql用户组和mysql用户 groupadd mysql useradd -g mysql mysql #修改mysql目录权限 chown -R mysql.mysql /lnmp/mysql/ #初始化 bin/mysqld --initialize --user=mysql --basedir=/lnmp/mysql --datadir=/lnmp/mysql/data #初始化后,出现一大串,最后面的为临时密码 xxx xxx xxx A temporary password is generated for root@localhost: mhr#qEJO+7?h #修改配置文件 vim /etc/my.cnf ### [mysqld] basedir = /lnmp/mysql datadir = /lnmp/mysql/data socket = /tmp/mysql/mysql.sock character-set-server=utf8 port = 3306 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES [client] socket = /tmp/mysql/mysql.sock default-character-set=utf8 ### #新建&修改目录权限 mkdir -p /tmp/mysql/ chmod -R 777 /tmp/mysql chown -R mysql:mysql /tmp/mysql/ #配置mysql服务 cp -a ./support-files/mysql.server /etc/init.d/mysqld chmod +x /etc/rc.d/init.d/mysqld chkconfig --add mysqld #配置全局环境变量 vim /etc/profile #profile文件中添加 ### export PATH=$PATH:/lnmp/mysql/bin:/lnmp/mysql/lib export PATH ### #让环境变量设置立即生效 source /etc/profile #启动mysql service mysqld start #登录mysql mysql -uroot -pmhr#qEJO+7?h #修改密码 alter user 'root'@'localhost' identified by 'root';
来源:https://www.cnblogs.com/mg007/p/12637435.html