源码安装LNMP
文章目录
源码安装LNMP 一. nginx的安装与配置 1. 安装 2. nginx安装后配置 3. 配置service file
二. 安装MySQL 1. 安装依赖包,创建用户,并解压 2. 修改属主 3. 配置环境变量,man文档,lib库,头文件 4. 建立数据存放目录,并修改属主 5. 初始化数据库,并保存密码 6. 生成配置文件 7. 配置服务启动脚本 8. 配置service文件,设置开机自启 9. 启动,安装lib库,设置密码
三. PHP的源码安装 1. 解压 2. 安装依赖包 3. 编译安装 4. 配置环境变量,lib,头文件 5. 配置php-fpm 6. 查看
四. 配置nginx 1. 配置Nginx支持PHP功能 2. 配置PHP网络界面 3. 开机自启 4. 访问
一. nginx的安装与配置
[root@node7 ~]# ls
anaconda- ks.cfg nginx- 1.22 .0 .tar.gz
mysql- 5.7 .38 - linux- glibc2.12 - x86_64.tar.gz php- 7.4 .30 .tar.gz
[root@node7 ~]#
1. 安装
创建系统用户nginx
[root@node7 ~]# useradd - r - M - s / sbin/ nologin nginx
安装依赖环境
[root@node7 ~]# yum - y groups mark install 'Development Tools'
[root@node7 ~]# yum - y install pcre- devel openssl openssl- devel gd- devel gcc gcc- c+ + make
创建日志存放目录
[root@node7 ~]# mkdir - p / var/ log / nginx
[root@node7 ~]# chown - R nginx.nginx / var/ log / nginx
[root@node7 ~]# ll - d / var/ log / nginx
drwxr- xr- x. 2 nginx nginx 6 Sep 2 10 : 57 / var/ log / nginx
[root@node7 ~]#
编译安装
[root@node7 ~]# tar xf nginx- 1.22 .0 .tar.gz
[root@node7 ~]# cd nginx- 1.22 .0
[root@node7 nginx- 1.22 .0 ]# ./ configure \
> - - prefix= / usr/ local/ nginx \
> - - user= nginx \
> - - group= nginx \
> - - with - debug \
> - - with - http_ssl_module \
> - - with - http_realip_module \
> - - with - http_image_filter_module \
> - - with - http_gunzip_module \
> - - with - http_gzip_static_module \
> - - with - http_stub_status_module \
> - - http- log - path= / var/ log / nginx/ access .log \
> - - error - log - path= / var/ log / nginx/ error .log
[root@node7 nginx- 1.22 .0 ]# make
[root@node7 nginx- 1.22 .0 ]# make install
2. nginx安装后配置
[root@node7 ~]# ls / usr/ local/ nginx/
conf html logs sbin
[root@node7 ~]#
配置环境变量
[root@node7 ~]# echo 'export PATH= / usr/ local/ nginx/ sbin: $PATH' > / etc/ profile.d/ nginx.sh
[root@node7 ~]# source / etc/ profile.d/ nginx.sh
[root@node7 ~]#
启动nginx
[root@node7 ~]# nginx
[root@node7 ~]# ss - antl
State Recv- Q Send- Q Local Address: Port Peer Address: Port Process
LISTEN 0 128 0.0 .0 .0 : 80 0.0 .0 .0 : *
LISTEN 0 128 0.0 .0 .0 : 22 0.0 .0 .0 : *
LISTEN 0 128 [: : ]: 22 [: : ]: *
[root@node7 ~]#
关闭nginx
[root@node7 ~]# nginx - s stop
[root@node7 ~]# ss - antl
State Recv- Q Send- Q Local Address: Port Peer Address: Port Process
LISTEN 0 128 0.0 .0 .0 : 22 0.0 .0 .0 : *
LISTEN 0 128 [: : ]: 22 [: : ]: *
[root@node7 ~]#
[root@node7 ~]# systemctl disable - - now firewalld
Removed / etc/ systemd/ system / multi- user.target.wants/ firewalld.service.
Removed / etc/ systemd/ system / dbus- org.fedoraproject.FirewallD1.service.
[root@node7 ~]# setenforce 0
[root@node7 ~]# vim / etc/ selinux/ config
3. 配置service file
[root@node7 ~]# cd / usr/ lib/ systemd/ system
[root@node7 system ]# cp sshd.service nginx.service
[root@node7 system ]# vim nginx.service
[root@node7 system ]# cat nginx.service
[Unit]
Description= web server daemon
After= network.target
[Service]
Type = foring
ExecStart= / usr/ local/ nginx/ sbin/ nginx
ExecStop= / usr/ local/ nginx/ sbin/ nginx - s stop
ExecReload= / usr/ local/ nginx/ sbin/ nginx - s reload
KillMode= process
Restart= on - failure
RestartSec= 42 s
[Install]
WantedBy= multi- user.target
[root@node7 system ]# systemctl daemon- reload
[root@node7 system ]#
开机自启
[root@node7 ~]# systemctl enable - - now nginx
Created symlink / etc/ systemd/ system / multi- user.target.wants/ nginx.service → / usr/ lib/ systemd/ system / nginx.service.
[root@node7 ~]# ss - antl
State Recv- Q Send- Q Local Address: Port Peer Address: Port Process
LISTEN 0 128 0.0 .0 .0 : 80 0.0 .0 .0 : *
LISTEN 0 128 0.0 .0 .0 : 22 0.0 .0 .0 : *
LISTEN 0 128 [: : ]: 22 [: : ]: *
[root@node7 ~]#
二. 安装MySQL
1. 安装依赖包,创建用户,并解压
[root@node7 ~]# yum - y install ncurses- devel openssl- devel openssl cmake mariadb- devel ncurses- compat- libs
[root@node7 ~]# useradd - r - M - s / sbin/ nologin mysql
[root@node7 ~]# tar xf mysql- 5.7 .38 - linux- glibc2.12 - x86_64.tar.gz - C / usr/ local/
2. 修改属主
[root@node7 ~]# cd / usr/ local/
[root@node7 local]# ls
bin include libexec sbin
etc lib mysql- 5.7 .38 - linux- glibc2.12 - x86_64 share
games lib64 nginx src
[root@node7 local]# mv mysql- 5.7 .38 - linux- glibc2.12 - x86_64 mysql
[root@node7 local]# chown - R mysql.mysql mysql
[root@node7 local]# ll - d mysql
drwxr- xr- x. 9 mysql mysql 129 Sep 2 18 : 55 mysql
[root@node7 local]#
3. 配置环境变量,man文档,lib库,头文件
[root@node7 mysql]# pwd
/ usr/ local/ mysql
[root@node7 mysql]# ls
LICENSE README bin docs include lib man share support- files
[root@node7 mysql]# echo 'export PATH= / usr/ local/ mysql/ bin: $PATH' > / etc/ profile.d/ mysql.sh
[root@node7 mysql]# source / etc/ profile.d/ mysql.sh
[root@node7 mysql]# vim / etc/ man_db.conf
MANDATORY_MANPATH / usr/ local/ mysql/ man
[root@node7 mysql]# vim / etc/ ld.so.conf.d/ mysql.conf
[root@node7 mysql]# cat / etc/ ld.so.conf.d/ mysql.conf
/ usr/ local/ mysql/ lib
[root@node7 mysql]# ldconfig
[root@node7 mysql]#
[root@node7 mysql]# ln - s / usr/ local/ mysql/ include / usr/ include/ mysql
[root@node7 mysql]#
4. 建立数据存放目录,并修改属主
[root@node7 ~]# mkdir - p / opt/ data
[root@node7 ~]# chown - R mysql.mysql / opt/ data
[root@node7 ~]# ll - d / opt/ data
drwxr- xr- x. 2 mysql mysql 6 Sep 2 19 : 01 / opt/ data
[root@node7 ~]#
5. 初始化数据库,并保存密码
[root@node7 ~]# mysqld - - initialize - - user mysql - - datadir / opt/ data
2022 - 09 - 02 T11: 02 : 42.806518 Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use - - explicit_defaults_for_timestamp server option ( see documentation for more details) .
2022 - 09 - 02 T11: 02 : 43.133944 Z 0 [Warning] InnoDB: New log files created, LSN= 45790
2022 - 09 - 02 T11: 02 : 43.165481 Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022 - 09 - 02 T11: 02 : 43.226570 Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: c4c4dc3c- 2 aae- 11 ed- a794- 000 c2903678a.
2022 - 09 - 02 T11: 02 : 43.229239 Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022 - 09 - 02 T11: 02 : 43.707490 Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022 - 09 - 02 T11: 02 : 43.707520 Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022 - 09 - 02 T11: 02 : 43.707905 Z 0 [Warning] CA certificate ca.pem is self signed.
2022 - 09 - 02 T11: 02 : 43.922480 Z 1 [Note] A temporary password is generated for root@localhost: jFffy?rJb7; 8
[root@node7 ~]#
[root@node7 ~]# echo 'jFffy?rJb7; 8 ' > pass
[root@node7 ~]# cat pass
jFffy?rJb7; 8
[root@node7 ~]#
6. 生成配置文件
[root@node7 ~]# > / etc/ my.cnf
[root@node7 ~]# vi / etc/ my.cnf
[root@node7 ~]# cat / etc/ my.cnf
[mysqld]
basedir = / usr/ local/ mysql
datadir = / opt/ data
socket = / tmp/ mysql.sock
port = 3306
pid- file = / opt/ data / mysql.pid
user = mysql
skip - name - resolve
sql- mode = STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION
[root@node7 ~]#
7. 配置服务启动脚本
[root@node7 ~]# cd / usr/ local/ mysql/ support- files /
[root@node7 support- files ]# cp mysql.server mysqld
[root@node7 support- files ]# vim mysqld
basedir= / usr/ local/ mysql
datadir= / opt/ data
[root@node7 support- files ]# chown - R mysql.mysql mysqld
[root@node7 support- files ]# ll - d mysqld
- rwxr- xr- x. 1 mysql mysql 10602 Sep 2 19 : 06 mysqld
[root@node7 support- files ]#
8. 配置service文件,设置开机自启
[root@node7 ~]# cd / usr/ lib/ systemd/ system
[root@node7 system ]# cp sshd.service mysqld.service
[root@node7 system ]# vi mysqld.service
[root@node7 system ]# cat mysqld.service
[Unit]
Description= mysqld server daemon
After= network.target sshd- keygen.target
[Service]
Type = forking
ExecStart= / usr/ local/ mysql/ support- files / mysqld start
ExecStop= / usr/ local/ mysql/ support- files / mysqld stop
ExecReload= / bin/ kill - HUP $MAINPID
[Install]
WantedBy= multi- user.target
[root@node7 system ]# systemctl daemon- reload
[root@node7 system ]#
9. 启动,安装lib库,设置密码
[root@node7 ~]# systemctl enable - - now mysqld
Created symlink / etc/ systemd/ system / multi- user.target.wants/ mysqld.service → / usr/ lib/ systemd/ system / mysqld.service.
[root@node7 ~]# ss - antl
State Recv- Q Send- Q Local Address: Port Peer Address: Port Process
LISTEN 0 128 0.0 .0 .0 : 80 0.0 .0 .0 : *
LISTEN 0 128 0.0 .0 .0 : 22 0.0 .0 .0 : *
LISTEN 0 128 [: : ]: 22 [: : ]: *
LISTEN 0 80 * : 3306 * : *
[root@node7 ~]# cat pass
jFffy?rJb7; 8
[root@node7 ~]# mysql - uroot - p'jFffy?rJb7; 8 ';
mysql> set password = password( 'run123456') ;
Query OK, 0 rows affected, 1 warning ( 0.00 sec )
mysql> quit
Bye
[root@node7 ~]# mysql - uroot - p'run123456';
mysql> quit
Bye
[root@node7 ~]#
三. PHP的源码安装
1. 解压
[root@node7 ~]# tar xf php- 7.4 .30 .tar.gz
[root@node7 ~]# ls
anaconda- ks.cfg pass
mysql- 5.7 .38 - linux- glibc2.12 - x86_64.tar.gz php- 7.4 .30
nginx- 1.22 .0 php- 7.4 .30 .tar.gz
nginx- 1.22 .0 .tar.gz
[root@node7 ~]#
2. 安装依赖包
[root@node7 ~]# yum - y install libxml2 libxml2- devel openssl openssl- devel bzip2 bzip2- devel libcurl libcurl- devel libicu- devel libjpeg libjpeg- devel libpng libpng- devel openldap- devel pcre- devel freetype freetype- devel gmp gmp- devel libmcrypt libmcrypt- devel readline readline- devel libxslt libxslt- devel mhash mhash- devel php- mysqlnd sqlite- devel libzip- devel https: / / vault.centos.org/ centos/ 8 / PowerTools/ x86_64/ os/ Packages/ oniguruma- devel- 6.8 .2 - 2. el8.x86_64.rpm
3. 编译安装
[root@node7 ~]# cd php- 7.4 .30
[root@node7 php- 7.4 .30 ]# ./ configure - - prefix= / usr/ local/ php7 \
> - - with - config- file- path= / etc \
> - - enable- fpm \
> - - enable- inline- optimization \
> - - disable- debug \
> - - disable- rpath \
> - - enable- shared \
> - - enable- soap \
> - - with - openssl \
> - - enable- bcmath \
> - - with - iconv \
> - - with - bz2 \
> - - enable- calendar \
> - - with - curl \
> - - enable- exif \
> - - enable- ftp \
> - - enable- gd \
> - - with - jpeg \
> - - with - zlib- dir \
> - - with - freetype \
> - - with - gettext \
> - - enable- json \
> - - enable- mbstring \
> - - enable- pdo \
> - - with - mysqli= mysqlnd \
> - - with - pdo- mysql= mysqlnd \
> - - with - readline \
> - - enable- shmop \
> - - enable- simplexml \
> - - enable- sockets \
> - - with - zip \
> - - enable- mysqlnd- compression- support \
> - - with - pear \
> - - enable- pcntl \
> - - enable- posix
[root@node7 php- 7.4 .30 ]# make
[root@node7 php- 7.4 .30 ]# make install
4. 配置环境变量,lib,头文件
[root@node7 ~]# cd / usr/ local/ php7/
[root@node7 php7]# ls
bin etc include lib php sbin var
[root@node7 php7]# echo 'export PATH= / usr/ local/ php7/ bin: / usr/ local/ php7/ : sbin: $PATH' > / etc/ profile.d/ php7.sh
[root@node7 php7]# source / etc/ profile.d/ php7.sh
[root@node7 php7]#
[root@node7 php7]# ln - s / usr/ local/ php7/ include / usr/ include/ php
[root@node7 php7]#
[root@node7 php7]# vim / etc/ ld.so.conf.d/ php.conf
[root@node7 php7]# cat / etc/ ld.so.conf.d/ php.conf
/ usr/ local/ php7/ lib
[root@node7 php7]# ldconfig
[root@node7 ~]# php - v
PHP 7.4 .30 ( cli) ( built: Sep 2 2022 19 : 31 : 45 ) ( NTS )
Copyright ( c) The PHP Group
Zend Engine v3.4.0 , Copyright ( c) Zend Technologies
[root@node7 ~]#
5. 配置php-fpm
[root@node7 ~]# cd php- 7.4 .30
[root@node7 php- 7.4 .30 ]# \cp php.ini- production / etc/ php.ini
[root@node7 php- 7.4 .30 ]# cp sapi/ fpm/ init.d.php- fpm / etc/ init.d/ php- fpm
[root@node7 php- 7.4 .30 ]# chmod + x / etc/ rc.d/ init.d/ php- fpm
[root@node7 php- 7.4 .30 ]# ll / etc/ rc.d/ init.d/ php- fpm
- rwxr- xr- x. 1 root root 2402 Sep 2 19 : 39 / etc/ rc.d/ init.d/ php- fpm
[root@node7 php- 7.4 .30 ]#
[root@node7 etc]# pwd
/ usr/ local/ php7/ etc
[root@node7 etc]# ls
pear.conf php- fpm.conf php- fpm.conf.default php- fpm.d
[root@node7 etc]#
[root@node7 etc]# cp php- fpm.conf.default php- fpm.conf
[root@node7 etc]# ls
pear.conf php- fpm.conf php- fpm.conf.default php- fpm.d
[root@node7 etc]#
[root@node7 etc]# cd php- fpm.d/
[root@node7 php- fpm.d]# cp www.conf.default www.conf
[root@node7 php- fpm.d]# ls
www.conf www.conf.default
[root@node7 php- fpm.d]# vim www.conf
listen = 127.0 .0 .1 : 9000
6. 查看
[root@node7 ~]# cd / etc/ init.d/
[root@node7 init.d]# ls
README functions php- fpm
[root@node7 init.d]# service php- fpm start
Starting php- fpm done
[root@node7 init.d]# ss - antl
State Recv- Q Send- Q Local Address: Port Peer Address: Port Process
LISTEN 0 128 0.0 .0 .0 : 80 0.0 .0 .0 : *
LISTEN 0 128 0.0 .0 .0 : 22 0.0 .0 .0 : *
LISTEN 0 128 127.0 .0 .1 : 9000 0.0 .0 .0 : *
LISTEN 0 128 [: : ]: 22 [: : ]: *
LISTEN 0 80 * : 3306 * : *
[root@node7 init.d]# service php- fpm stop
Gracefully shutting down php- fpm . done
[root@node7 init.d]# service php- fpm start
Starting php- fpm done
[root@node7 init.d]#
四. 配置nginx
1. 配置Nginx支持PHP功能
[root@node7 ~]# cd / usr/ local/ nginx/ conf/
[root@node7 conf]# ls
fastcgi.conf koi- win scgi_params
fastcgi.conf.default mime.types scgi_params.default
fastcgi_params mime.types.default uwsgi_params
fastcgi_params.default nginx.conf uwsgi_params.default
koi- utf nginx.conf.default win- utf
[root@node7 conf]# vim nginx.conf
[root@node7 conf]# cat nginx.conf
user nginx;
worker_processes 1 ;
error_log logs/ error .log ;
#error_log logs/ error .log notice;
#error_log logs/ error .log info;
pid logs/ nginx.pid;
events {
worker_connections 1024 ;
}
http {
include mime.types;
default_type application/ octet- stream ;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for" ';
#access_log logs/ access .log main;
sendfile on ;
#tcp_nopush on ;
#keepalive_timeout 0 ;
keepalive_timeout 65 ;
#gzip on ;
server {
listen 80 ;
server_name localhost;
#charset koi8- r;
#access_log logs/ host.access .log main;
location / {
root html;
index index.php index.html index.htm; / / 添加一个index.PHP
}
#error_page 404 / 404. html;
# redirect server error pages to the static page / 50 x.html
#
error_page 500 502 503 504 / 50 x.html;
location = / 50 x.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$ {
root html;
fastcgi_pass 127.0 .0 .1 : 9000 ;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME / usr/ local/ nginx/ html$fastcgi_script_name;
include fastcgi_params;
}
/ /
# deny access to .htaccess files , if Apache's document root
# concurs with nginx's one
#
#location ~ / \.ht {
# deny all;
#}
}
# another virtual host using mix of IP - , name - , and port- based configuration
#
#server {
# listen 8000 ;
# listen somename: 8080 ;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key ;
# ssl_session_cache shared : SSL: 1 m;
# ssl_session_timeout 5 m;
# ssl_ciphers HIGH:
# ssl_prefer_server_ciphers on ;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
[root@node7 conf]# nginx - s reload
取消location几行注释
2. 配置PHP网络界面
[root@node7 ~]# cd / usr/ local/ nginx/ html/
[root@node7 html]# ls
50 x.html index.html
[root@node7 html]# vi index.php
[root@node7 html]# cat index.php
< ?php
phpinfo( ) ;
?>
[root@node7 html]#
[root@node7 html]# ls
50 x.html index.html index.php
[root@node7 html]# mv index.html / opt/ / / 将nginx界面移走,这样用ip 访问时就可以直接访问PHP界面
[root@node7 html]# ls
50 x.html index.php
[root@node7 html]# systemctl restart nginx
[root@node7 ~]# ss - antl
State Recv- Q Send- Q Local Address: Port Peer Address: Port Process
LISTEN 0 128 0.0 .0 .0 : 80 0.0 .0 .0 : *
LISTEN 0 128 0.0 .0 .0 : 22 0.0 .0 .0 : *
LISTEN 0 128 127.0 .0 .1 : 9000 0.0 .0 .0 : *
LISTEN 0 128 [: : ]: 22 [: : ]: *
LISTEN 0 80 * : 3306 * : *
[root@node7 ~]#
3. 开机自启
[root@node7 ~]# ll / etc/ rc.local
lrwxrwxrwx. 1 root root 13 Sep 23 2021 / etc/ rc.local - > rc.d/ rc.local
[root@node7 ~]# ll / etc/ rc.d/ rc.local
- rw- r- - r- - . 1 root root 474 Sep 23 2021 / etc/ rc.d/ rc.local
[root@node7 ~]# chmod + x / etc/ rc.d/ rc.local
[root@node7 ~]# vim / etc/ rc.d/ rc.local
[root@node7 ~]# head / etc/ rc.d/ rc.local
#
/ usr/ local/ nginx/ sbin/ nginx
service mysqld start
service php- fpm start
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
[root@node7 ~]#
4. 访问