PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通

QQ:420220301 微信/手机:150-3210-7690
当前位置:首页 > CMS教程 > Fastadmin

LNMP 环境搭建 编译安装

管理员 2024-12-14
Fastadmin
4

CentOS7.8 + Nginx1.16.1 + MySQL-5.7.28 + PHP7.2.30

一、开始

1. 查看是否已安装 wget
rpm -qa wget

否则安装

yum -y install wget
2.安装编译器
yum -y install gcc gcc-c++

二、安装 Nginx

1. 安装依赖包
yum -y install pcre pcre-devel zlib zlib-devel openssl openssl-devel
2. 下载 Nginx 包并解压
cd /usr/local/srcwget http://nginx.org/download/nginx-1.16.1.tar.gztar -zxvf nginx-1.16.1.tar.gz
3. 编译安装
cd nginx-1.16.1./configure --prefix=/usr/local/nginxmake && make install
4. 创建并设置 Nginx 运行账号
groupadd nginxuseradd -M -g nginx -s /sbin/nologin nginxcd /usr/local/nginx/confvim nginx.conf,设置user参数如下user nginx

其他配置参数暂时无需改动

5. 设置 Nginx 为系统服务
vim /lib/systemd/system/nginx.service

文件内容

[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s stopPrivateTmp=true[Install]WantedBy=multi-user.target
6. 设置 Nginx 开机自启动
systemctl enable nginx.service
7. 开启 Nginx 服务
systemctl start nginx.service

查看nginx是否启动成功

ps aux | grep nginx

在虚拟机浏览器中访问测试

curl localhost

出现以下界面则表示可以成功访问
5eac184331859.png

三、安装 MySQL

1. 卸载已有 MySQL

查看是否已安装 MySQL

rpm -qa mysql

有则卸载

rpm -e --nodeps 文件名称

是否存在与 MySQL 相关的文件或目录

whereis mysql

是则删除
查看是否存在 mariadb

rpm -qa | grep mariadb

存在则卸载

rpm -e --nodeps 文件名 //文件名是上一个命令查询结果

存在 /etc/my.cnf 则需要先删除

rm /etc/my.cnf
2. 安装依赖包
yum -y install gcc gcc-c++ cmake ncurses ncurses-devel bison
3. 下载解压
cd /usr/local/srcwget https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gz#如果下载速度过慢 可以用下面这个源wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-boost-5.7.28.tar.gztar -zxvf mysql-boost-5.7.28.tar.gz
4. 编译安装
cd mysql-5.7.28cmake -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_BOOST=boostmake && make install
5. 建立所需目录、添加用户
mkdir -p /data/mysql/datauseradd -s /sbin/nologin mysqlchown -R mysql:mysql /data/mysql
6. 配置 my.cnf
vim /etc/my.cnf

配置如下

[client]port = 3306socket = /data/mysql/mysql.sock[mysqld]port = 3306socket = /data/mysql/mysql.sockuser = mysqlbasedir = /usr/local/mysqldatadir = /data/mysql/datapid-file = /data/mysql/mysql.pidlog_error = /data/mysql/mysql-error.logslow_query_log = 1long_query_time = 1slow_query_log_file = /data/mysql/mysql-slow.logskip-external-lockingkey_buffer_size = 32Mmax_allowed_packet = 1024Mtable_open_cache = 128sort_buffer_size = 768Knet_buffer_length = 8Kread_buffer_size = 768Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mthread_cache_size = 16query_cache_size = 16Mtmp_table_size = 32Mperformance_schema_max_table_instances = 1000explicit_defaults_for_timestamp = true#skip-networkingmax_connections = 500max_connect_errors = 100open_files_limit = 65535log_bin=mysql-binbinlog_format=mixedserver_id   = 232expire_logs_days = 10early-plugin-load = ""default_storage_engine = InnoDBinnodb_file_per_table = 1innodb_buffer_pool_size = 128Minnodb_log_file_size = 32Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 50[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehash[myisamchk]key_buffer_size = 32Msort_buffer_size = 768Kread_buffer = 2Mwrite_buffer = 2M
7. 初始化
cd /usr/local/mysql/bin./mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/data
8. 拷贝可执行配置文件
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
9. 启动
service mysqld start
10. 设置开机启动
systemctl enable mysqld
11. 测试
ps aux | grep mysql
12. 修改密码
mysql -uroot -p#无需密码直接进入#修改密码set password=password('123456');

如果出现 -bash: mysql: command not found

方法一:映射链接ln -s /usr/local/mysql/bin/mysql /usr/bin方法二:添加环境变量vim /etc/profile# 添加一行PATH=/usr/local/mysql/bin:$PATH# 保存退出source /etc/profile

四、安装 PHP

1. 安装依赖包
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel
2. 下载 PHP 包并解压
cd /usr/local/srcwget https://php.net/distributions/php-7.2.30.tar.gztar -zxvf php-7.2.30.tar.gz
3. 编译安装
cd php-7.2.30./configure --prefix=/usr/local/php --enable-fileinfo --enable-fpm --with-config-file-path=/usr/local/php/etc --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/data/mysql/mysql.sock --without-pear  --enable-bcmathmake && make install
4. 将配置文件复制到正确位置
cp php.ini-development /usr/local/php/etc/php.inivim /usr/local/php/etc/php.ini#找到 upload_max_filesize 上传的文件最大为 2M 可以调大些
5. 创建并设置 php-fpm 运行账号
groupadd wwwuseradd -M -g www -s /sbin/nologin wwwcd /usr/local/php/etccp php-fpm.conf.default php-fpm.confcp php-fpm.d/www.conf.default php-fpm.d/www.confvim php-fpm.d/www.conf搜索 user 设置运行账号user = wwwgroup = www
6. 配置 Nginx 支持 PHP
vim /usr/local/nginx/conf/nginx.conf

5c80bae206190.png
重启nginx服务

systemctl start nginx.service
7. 设置 php-fpm 为系统服务
vim /etc/systemd/system/php-fpm.service

文件内容

[Unit]Description=php-fpmAfter=network.target[Service]Type=forkingExecStart=/usr/local/php/sbin/php-fpmPrivateTmp=True[Install]WantedBy=multi-user.target
8. 设置 php-fpm 服务开机自启动
systemctl enable php-fpm.service
9. 启动 php-fpm
systemctl start php-fpm.service

查看是否启动成功

ps aux | grep php-fpmphp -v#如果报错:php: command not found 执行方法一:映射链接ln -s /usr/local/php/bin/php /usr/bin/php方法二:添加环境变量vim /etc/profile# 添加一行PATH=/usr/local/php/bin:$PATH# 保存退出source /etc/profile

五、配置虚拟主机

cd /usr/local/nginx/confmkdir conf.dvim nginx.conf

添加下面这句
QQ截图20200506134103.png

cd conf.d#以下以 fastadmin.net 为例vim fastadmin.net.conf
server {    listen       80;    server_name  fastadmin.net;    root /data/www/fastadmin.net/public;    #charset koi8-r;    #access_log  logs/host.access.log  main;    location / {        index  index.php index.html index.htm;        if (!-e $request_filename) {           rewrite  ^(.*)$  /index.php?s=/$1  last;           #break;        }    }    #error_page  404              /404.html;    # redirect server error pages to the static page /50x.html    #    error_page   500 502 503 504  /50x.html;    location = /50x.html {        root   html;    }    # proxy the PHP scripts to Apache listening on 127.0.0.1:80    #    #location ~ .php$ {    #    proxy_pass   http://127.0.0.1;    #}    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000    #    location ~ .php {        fastcgi_pass   127.0.0.1:9000;        fastcgi_index  index.php;        #fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;        #include        fastcgi_params;        set $path_info "";        set $real_script_name $fastcgi_script_name;        if ($fastcgi_script_name ~ "^(.+?.php)(/.+)$") {            set $real_script_name $1;            set $path_info $2;        }        fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;        fastcgi_param SCRIPT_NAME $real_script_name;        fastcgi_param PATH_INFO $path_info;        include fastcgi_params;    }    # deny access to .htaccess files, if Apache's document root    # concurs with nginx's one    #    #location ~ /.ht {    #    deny  all;    #}}

重载 Nginx

service nginx reload

结束


希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, Fastadmin, ClassCMS, LeCMS, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。

相关推荐

扫码关注

qrcode

QQ交谈

回顶部