PHP(Hypertext Preprocessor 超文本预处理器)是通用服务器端脚本编程语言,主要用于web开发实现动态web页面,也是最早实现将脚本嵌入HTML源码文档中的服务器端脚本语言之一。同时,php还提供了一个命令行接口,因此,其也可以在大多数系统上作为一个独立的shell来使用
LNMP 架构
环境准备lnmp需要 安装 nginxmysqlphp 软件
准备工作 关闭防火墙,防护
[root@localhost ~]#systemctl stop firewalld[root@localhost ~]#setenforce 0[root@localhost ~]#cd /opt[root@localhost opt]#ls[root@localhost opt]#rz -Erz waiting to receive.[root@localhost opt]#rz -Erz waiting to receive.[root@localhost opt]#rz -Erz waiting to receive.[root@localhost opt]#rz -Erz waiting to receive.[root@localhost opt]#lsDiscuz_X3.4_SC_UTF8.zipmysql-boost-5.7.20.tar.gznginx-1.22.0.tar.gzphp-7.1.10.tar.bz2[root@localhost opt]#tar xf nginx-1.22.0.tar.gz [root@localhost opt]#cd nginx-1.22.0/[root@localhost nginx-1.22.0]#[root@localhost nginx-1.22.0]#[root@localhost nginx-1.22.0]#[root@localhost nginx-1.22.0]#[root@localhost nginx-1.22.0]#[root@localhost nginx-1.22.0]#lsautoCHANGESCHANGES.ruconfconfigurecontribhtmlLICENSEmanREADMEsrc[root@localhost nginx-1.22.0]#yum -y install pcre-devel zlib-devel gcc gcc-c++ make
(一)编译安装nginx
1、安装依赖包
yum -y install pcre-devel zlib-devel gcc gcc-c++ make
2、创建运行用户、组
[root@localhost nginx-1.22.0]#useradd -M -s /sbin/nologin nginx
(Nginx 服务程序默认以 nobody 身份运行,建议为其创建专门的用户账号,以便更准确地控制其访问权限) useradd -M -s /sbin/nologin nginx
3、编译安装nginx
./configure \--prefix=/usr/local/nginx \--user=nginx \--group=nginx \--with-http_stub_status_module
[root@localhost nginx-1.22.0]#make -j 2[root@localhost nginx-1.22.0]#make install
[root@localhost nginx-1.22.0]#ln -s /usr/local/nginx/sbin/nginx/usr/bin
tee /lib/systemd/system/nginx.service <<eof[Unit]Description=nginxAfter=network.target[Service]Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStart=/usr/local/nginx/sbin/nginxExecReload=/bin/kill -1 $MAINPIDExecStop=/bin/kill -3 $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.targeteof
[root@localhost nginx-1.22.0]#systemctl daemon-reload[root@localhost nginx-1.22.0]#systemctl enable --now nginx.service[root@localhost nginx-1.22.0]#systemctl status nginx.service
(二)编译安mysql
1、安装Mysql环境依赖包
yum -y install \ncurses \ncurses-devel \bison \cmakeyum -y install gcc gcc-c++ cmake bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-develncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel
2、创建运行用户
[root@localhost nginx-1.22.0]#useradd -M -s /sbin/nologinmysql[root@localhost nginx-1.22.0]#cd /opt[root@localhost opt]#lsDiscuz_X3.4_SC_UTF8.zipmysql-boost-5.7.20.tar.gznginx-1.22.0nginx-1.22.0.tar.gzphp-7.1.10.tar.bz2[root@localhost opt]#tar xf mysql-boost-5.7.20.tar.gz [root@localhost opt]#cd mysql-5.7.20/[root@localhost mysql-5.7.20]#lsboost config.h.cmake extralibmysql mysys_sslscriptstestclientsBUILD configure.cmakeincludelibmysqldpackagingsqlunittestclientCOPYINGINSTALLlibservicesplugin sql-common VERSIONcmake dbug libbinlogeventsmanrapidstoragevioCMakeLists.txtDocs libbinlogstandalonemysql-test README stringswincmd-line-utilsDoxyfile-perfschemalibevent mysysregexsupport-fileszlib[root@localhost mysql-5.7.20]#
3、编译安装
cmake \-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \-DSYSCONFDIR=/etc \-DSYSTEMD_PID_DIR=/usr/local/mysql \-DDEFAULT_CHARSET=utf8\-DDEFAULT_COLLATION=utf8_general_ci \-DWITH_EXTRA_CHARSETS=all \-DWITH_INNOBASE_STORAGE_ENGINE=1 \-DWITH_ARCHIVE_STORAGE_ENGINE=1 \-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \-DMYSQL_DATADIR=/usr/local/mysql/data \-DWITH_BOOST=boost \-DWITH_SYSTEMD=1
[root@localhost mysql-5.7.20]#make -j 2[root@localhost mysql-5.7.20]#make install
4、修改mysql 配置文件
[root@localhost mysql-5.7.20]#vim /etc/my.cnf
[client]port = 3306socket=/usr/local/mysql/mysql.sock [mysqld]user = mysqlbasedir=/usr/local/mysqldatadir=/usr/local/mysql/dataport = 3306character-set-server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket=/usr/local/mysql/mysql.sockbind-address = 0.0.0.0skip-name-resolvemax_connections=2048default-storage-engine=INNODBmax_allowed_packet=16Mserver-id = 1 sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
5、更改mysql安装目录和配置文件的属主属组
[root@localhost mysql-5.7.20]#chown -R mysql:mysql /usr/local/mysql/[root@localhost mysql-5.7.20]#chown mysql:mysql /etc/my.cnf
6、设置路径环境变量
[root@localhost mysql-5.7.20]#echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile[root@localhost mysql-5.7.20]#source /etc/profile
7、初始化数据库
[root@localhost mysql-5.7.20]#cd /usr/local/mysql/bin/
./mysqld \--initialize-insecure \--user=mysql \--basedir=/usr/local/mysql \--datadir=/usr/local/mysql/data
8、添加mysqld系统服务
[root@localhost bin]#cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/[root@localhost bin]#systemctl daemon-reload[root@localhost bin]#systemctl start mysqld.service[root@localhost bin]#systemctl status mysqld.service
[root@localhost bin]#systemctl enable mysqld.service
9、修改mysql 的登录密码
[root@localhost bin]#mysqladmin -u root -p password "abc123"
mysqladmin -u root -p password “abc123”
给root账号设置密码为abc123,提示输入的是原始密码(为空)要求输入的是原密码直接回车即可
10、授权远程登录
[root@localhost bin]#mysql -uroot -pabc123
(三)编译安装php软件
1、安装环境依赖包
yum -y install gd \libjpeg libjpeg-devel \libpng libpng-devel \freetype freetype-devel \libxml2 libxml2-devel \zlib zlib-devel \curl curl-devel \openssl openssl-devel
2、编译安装
./configure \--prefix=/usr/local/php \--with-mysql-sock=/usr/local/mysql/mysql.sock \--with-mysqli \--with-zlib \--with-curl \--with-gd \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--with-openssl \--enable-fpm \--enable-mbstring \--enable-xml \--enable-session \--enable-ftp \--enable-pdo \--enable-tokenizer \--enable-zip
[root@localhost php-7.1.10]#make -j 2[root@localhost php-7.1.10]#make install
3、调整PHP配置文件
[root@localhost php-7.1.10]#ls php.ini-development php.ini-development[root@localhost php-7.1.10]#cp php.ini-development/usr/local/php/lib/php.ini[root@localhost php-7.1.10]#vim /usr/local/php/lib/php.ini
修改内容date.timezone = Asia/Shanghaimysqli.default_socket = /usr/local/mysql/mysql.sock
调整主配置文件:
[root@localhost php-7.1.10]#cd /usr/local/php/lib/[root@localhost lib]#lsphpphp.ini[root@localhost lib]#cd php/[root@localhost php]#lsArchiveConsoledoc OSpearcmd.phppeclcmd.phpSystem.phpXMLbuilddata extensionsPEARPEAR.php Structures test[root@localhost php]#cd ..[root@localhost lib]#lsphpphp.ini[root@localhost lib]#cd ..[root@localhost php]#lsbinetcincludelibphpsbinvar[root@localhost php]#pwd/usr/local/php[root@localhost php]#cd etc/[root@localhost etc]#lspear.confphp-fpm.conf.defaultphp-fpm.d[root@localhost etc]#pwd/usr/local/php/etc[root@localhost etc]#cp php-fpm.conf.defaultphp-fpm.conf[root@localhost etc]#lspear.confphp-fpm.confphp-fpm.conf.defaultphp-fpm.d[root@localhost etc]#vim php-fpm.conf
调整进程服务配置文件:
调整扩展配置文件:
[root@localhost etc]#cd php-fpm.d/[root@localhost php-fpm.d]#lswww.conf.default[root@localhost php-fpm.d]#cp www.conf.default www.conf[root@localhost php-fpm.d]#lswww.confwww.conf.default[root@localhost php-fpm.d]#
php有三个配置文件:
php.ini 主配置文件
php-fpm.conf 进程服务配置文件
www.conf扩展配置文件
#调整主配置文件:
cp /opt/php-7.1.10/php.ini-development /usr/local/php/lib/php.ini
vim /usr/local/php/lib/php.ini
–1170行–修改
mysqli.default_socket = /usr/local/mysql/mysql.sock
–939行–取消注释,修改
date.timezone = Asia/Shanghai
#调整进程服务配置文件:
cd /usr/local/php/etc/
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
–17行–去掉”;”注释
pid = run/php-fpm.pid
#调整扩展配置文件:
cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf
4、路径优化
[root@localhost php-fpm.d]#ln -s /usr/local/php/bin/* /usr/local/bin/[root@localhost php-fpm.d]#ln -s /usr/local/php/sbin/* /usr/local/sbin/
5、启动php-fpm
[root@localhost php-fpm.d]#cd /opt/php-7.1.10/sapi/fpm/[root@localhost fpm]#lsconfig.m4init.d.php-fpm Makefile.fragphp-fpm.8.in php-fpm.service status.html.inwww.conf.inCREDITSinit.d.php-fpm.inphp-fpmphp-fpm.conf php-fpm.service.intestsfpmLICENSEphp-fpm.8php-fpm.conf.instatus.html www.conf[root@localhost fpm]#pwd/opt/php-7.1.10/sapi/fpm[root@localhost fpm]#cp /opt/php-7.1.10/sapi/fpm/php-fpm.service /usr/lib/systemd/system/[root@localhost fpm]#[root@localhost fpm]#systemctl daemon-reload [root@localhost fpm]#systemctl start php-fpm.service[root@localhost fpm]#systemctl status php-fpm.service● php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled) Active: active (running) since 三 2024-02-28 15:47:25 CST; 17s ago Main PID: 42918 (php-fpm) CGroup: /system.slice/php-fpm.service ├─42918 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) ├─42919 php-fpm: pool www └─42920 php-fpm: pool www2月 28 15:47:25 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager.2月 28 15:47:25 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...[root@localhost fpm]#ss -natp |grep 9000LISTEN 0128127.0.0.1:9000 *:* users:(("php-fpm",pid=42920,fd=0),("php-fpm",pid=42919,fd=0),("php-fpm",pid=42918,fd=6))[root@localhost fpm]#
(四)配置 Nginx支持PHP解析
[root@localhost fpm]#vim /usr/local/nginx/conf/nginx.conf
[root@localhost fpm]#nginx -s reload[root@localhost fpm]#systemctl restart nginx.service
1、修改配置文件
2、写php测试页面
[root@localhost html]#vim /usr/local/nginx/html/index.php 3、去浏览器验证
4、验证数据库工作是否正常
CREATE DATABASE bbs;GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';flush privileges;
重新编辑测试页:
Success!!";else echo "Fail!!";?>
浏览器访问
(五)安装论坛
[root@localhost ~]#cd /opt[root@localhost opt]#lsdir_SC_UTF8mysql-5.7.20 nginx-1.22.0 php-7.1.10说明.htmDiscuz_X3.4_SC_UTF8.zipmysql-boost-5.7.20.tar.gznginx-1.22.0.tar.gzphp-7.1.10.tar.bz2[root@localhost opt]#unzip Discuz_X3.4_SC_UTF8.zip
[root@localhost opt]#cd dir_SC_UTF8/[root@localhost dir_SC_UTF8]#lsreadmeuploadutility[root@localhost dir_SC_UTF8]#cp -r upload/ /usr/local/nginx/html/bbs/[root@localhost dir_SC_UTF8]#cd/usr/local/nginx/html/bbs/[root@localhost bbs]#lsadmin.phparchiver crossdomain.xmlforum.phpindex.phpmember.phpportal.phpsourceuc_clientapiconfig data group.phpinstallmisc.phprobots.txtstaticuc_serverapi.phpconnect.phpfavicon.icohome.php mplugin.phpsearch.phptemplate[root@localhost bbs]#chmod -R 777 ./config/[root@localhost bbs]#chmod -R 777 ./data/[root@localhost bbs]#chmod -R 777 ./uc_client/[root@localhost bbs]#chmod -R 777 ./uc_server/
1、部署 Discuz
2、调整论坛目录的权限:
调整论坛目录的权限:
cd /usr/local/nginx/html/bbs/
chown -R nginx.nginx./config/
chown -R nginx.nginx ./data/
chown -R nginx.nginx ./uc_client/
chown -R nginx.nginx./uc_server/
都要处理
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/
3、论坛页面访问
数据库默认端口号3306
(六)安装博客
[root@zzcentos1 opt]#cp -r wordpress/usr/local/nginx/html/[root@zzcentos1 opt]#cd /usr/local/nginx/html/[root@zzcentos1 html]#ls50x.htmlbbsindex.htmlindex.phpwordpress[root@zzcentos1 html]#chmod-R 777 wordpress/ [root@zzcentos1 html]#ls50x.htmlbbsindex.htmlindex.phpwordpress[root@zzcentos1 html]#
建数据库名
CREATE DATABASE blog;GRANT all ON blog.* TO 'bloguser'@'%' IDENTIFIED BY 'admin123';GRANT all ON blog.* TO 'bloguser'@'localhost' IDENTIFIED BY 'admin123';flush privileges;wordpress/wp-admin
去浏览器访问