Shutting down the firewall
[[email protected] ~]# systemctl stop firewalld[[email protected] ~]# systemctl disable firewalld[[email protected] ~]# sed -ri ‘s/(SELINUX=).*/\1disabled/g‘ /etc/selinux/config[[email protected] ~]# setenforce 0
Configuring the source for installation 163
[[email protected] ~]# cd /etc/yum.repos.d///创建备份目录[[email protected] yum.repos.d]# mkdir /etc/repo-bf//将原yum仓库的文件备份到repo-bf[[email protected] yum.repos.d]# mv * /etc/repo-bf//下载163的源到yum仓库[[email protected] yum.repos.d]# curl -o 163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo//将改为版本的7[[email protected] yum.repos.d]# sed -i ‘s/\$releasever/7/g‘ /etc/yum.repos.d/163.repo[[email protected] yum.repos.d]# sed -i ‘s/enabled=0/enabled=1/g‘ /etc/yum.repos.d/163.repo//自动配置yum的软件仓库,也可以自己配置[[email protected] yum.repos.d]# yum -y install epel-release[[email protected] yum.repos.d]# yum clean all//安装编译环境[[email protected] yum.repos.d]# yum -y install gcc gcc-c++[[email protected] yum.repos.d]# yum -y install wget
Install dependent packages
//创建用户[[email protected] ~]# useradd -r -M -s /sbin/nologin nginx //安装编译环境[[email protected] ~]# yum -y groups list[[email protected] ~]# yum -y install pcre-devel openssl openssl-devel gd-devel
The package in the file, if it cannot be downloaded in Xshell, can be downloaded first and then passed in
//创建日志存放目录[[email protected] ~]# mkdir -p /var/log/nginx [[email protected] ~]# chown -R nginx.nginx /var/log/nginx //下载nginx,编译安装[[email protected] ~]# cd /usr/src/[[email protected] src]# wget http://64.123.28.133/files/21490000000827F6/nginx.org/download/nginx-1.14.0.tar.gz[[email protected] src]# tar xf nginx-1.14.0.tar.gz [[email protected] src]# cd nginx-1.14.0[[email protected] nginx-1.14.0]# yum -y install gcc gcc-c++[[email protected] nginx-1.14.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[[email protected] nginx-1.14.0]# make -j 4 && make install
Setting environment variables
[[email protected] nginx-1.14.0]# echo ‘export PATH=/usr/local/nginx/sbin:$PATH‘ > /etc/profile.d/nginx.sh[[email protected] nginx-1.14.0]# . /etc/profile.d/nginx.sh//启动[[email protected] nginx-1.14.0]# nginx
2. Install MySQL
//安装依赖包[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel创建用户和组[[email protected] ~]# groupadd -r -g 306 mysql[[email protected] ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
Download MySQL package in binary format
[[email protected] ~]# cd/usr/src/[[email protected] src]# wget https://downloads.mysql.com/archives/get/ file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz decompression software to/usr/local/[[email protected] ~]# Cd/usr/src/[[email protected] src]# lsdebug kernels mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz nginx-1.14.0 nginx-1.14.0.tar.gz[[ Email protected] src]# tar XF mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz-c/usr/local/[[email protected] src]# Ls/usr/local/bin etc games include Lib Lib64 libexec mysql-5.7.22-linux-glibc2.12-x86_64 nginx sbin Shar E src[[email protected] src]# cd/usr/local/[[email protected] local]# LN-SV Mysql-5.7.22-linux-glibc2.12-x86_64/mysql "MySQL", "mysql-5.7.22-linux-glibc2.12-x86_64/"//Modify the owner [[email Protected] local]# chown-r mysql.mysql/usr/local/mysql[[email protected] local]# ll/usr/local/mysql- Dlrwxrwxrwx. 1 MySQL MySQL 36 August 16:13/usr/local/mysql-mysql-5.7.22-linux-glibc2.12-x86_64///setting environment variables [[email protected] local]# echo ' export path=/usr/local/mysql/bin: $PATH ' >/etc/profile.d/mysql.sh[[ Email protected] local]#. /etc/profile.d/mysql.sh[[email protected] local]# echo $PATH/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/ local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin//set up data storage directory [[email protected] local]# cd/usr/local/ Mysql[[email protected] mysql]# mkdir/opt/data[[email protected] mysql]# chown-r mysql.mysql/opt/data/// Initializes the database and finally generates a temporary password [[email protected] mysql]#/usr/local/mysql/bin/mysqld--initialize--user=mysql--datadir= /opt/data/2018-08-24t08:20:10.891585z 1 [Note] A temporary password is generated for [email protected]: Neu8fscmem ( M
Configure MySQL
[[email protected] mysql]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql"/usr/local/include/mysql" -> "/usr/local/mysql/include/"[[email protected] mysql]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf[[email protected] mysql]# ldconfig -v
//生成配置文件[[email protected] ~]# cat > /etc/my.cnf <<EOF[mysqld]basedir = /usr/local/mysqldatadir = /opt/datasocket = /tmp/mysql.sockport = 3306pid-file = /opt/data/mysql.piduser = mysqlskip-name-resolveEOF
Configuring Startup Scripts
[[email protected] mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld[[email protected] mysql]# sed -ri ‘s#^(basedir=).*#\1/usr/local/mysql#g‘ /etc/init.d/mysqld[[email protected] mysql]# sed -ri ‘s#^(datadir=).*#\1/opt/data#g‘ /etc/init.d/mysqld
Start MySQL
[[email protected] mysql]# service mysqld startStarting MySQL.Logging to ‘/opt/data/localhost.localdomain.err‘.SUCCESS![[email protected] mysql]# ps -ef|grep mysqlroot 24348 1 0 16:25 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/data --pid-file=/opt/data/mysql.pidmysql 24526 24348 2 16:25 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/opt/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=localhost.localdomain.err --pid-file=/opt/data/mysql.pid --socket=/tmp/mysql.sock --port=3306root 24556 2316 0 16:25 pts/0 00:00:00 grep --color=auto mysql
[[email protected] mysql]# ss -antl
Modify temporary password
[[email protected] mysql]# mysql -uroot -pEnter password:mysql> set password = password(‘guohui123‘);Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> quit
Install PHP
Install dependent packages
[[email protected] ~]# yum-y install bzip2-devel curl-devel freetype-devel gcc libjpeg-devel libpng-devel libxslt-d Evel Libxml2-devel openssl-devel pcre-devel pcre-devel zlib-devel//download [[email protected] ~]# wget/HTTP/ Cn.php.net/distributions/php-7.2.8.tar.xz[[email protected] ~]# Tar XF php-7.2.8.tar.xz[[email protected ] ~]# CD php-7.2.8//configuration installation variable, "/usr/local/php" is the installation path, you can change to your favorite installation path. [[email protected] php-7.2.8]#./configure--prefix=/usr/local/php--with-curl--with-freetype-dir--WITH-GD-- With-gettext--with-iconv-dir--with-kerberos--with-libdir=lib64--with-libxml-dir--with-mysqli--with-openssl-- With-pcre-regex--with-pdo-mysql--with-pdo-sqlite--with-pear--with-png-dir--with-jpeg-dir--with-xmlrpc-- With-xsl--with-zlib--with-bz2--with-mhash--enable-fpm--enable-bcmath--enable-libxml-- Enable-inline-optimization--enable-gd-native-ttf--enable-mbregex--enable-mbstring--enable-opcache-- Enable-pcntl--enable-shmop--enable-soap--enable-sockets--enable-sysvsem--enable-sysvshm--enable-xml--enable-zip//Compile the source code, in the extract directory to execute the compile command: make[[email protected] php-7.2.8]# make//installation php[[email protected] php-7.2.8]# make install
//配置PHP将PHP源码包(/root/php-7.2.8)中的php.ini-development文件复制到/usr/local/php/下,更名为php.ini源码包在root下下载,所以在root下[[email protected] php-7.2.8]# cp /root/php-7.2.8/php.ini-development /usr/local/php/php.ini[[email protected] php-7.2.8]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf[[email protected] php-7.2.8]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf配置php.ini “cgi.fix_pathinfo=0”
[[email protected] php-7.2.8]# vim /usr/local/php/php.inicgi.fix_pathinfo=0启动php-fpm服务:启动完毕之后,php-fpm服务默认使用9000端口
[[email protected] php-7.2.8]# /usr/local/php/sbin/php-fpm[[email protected] php-7.2.8]# ss -anltLISTEN 0 128 127.0.0.1:9000 *:*
最后配置nginx编辑nginx配置文件/usr/local/nginx/conf/nginx.conf ,主要修改nginx的server,{}配置块中的内容,修改location块,追加index.php让nginx服务器默认支持index.php为首页:(在尾部追加了index.php)2.更换为下方内容location ~* \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
Edit Changes
[[email protected] php-7.2.8]# vim /usr/local/nginx/conf/nginx.conf1.index index.html index.htm; 更改成 index index.html index.htm index.php; 2.location ~* \.php$ {root html;fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
//这里面很多都是默认的,root是配置PHP程序放置的根目录,主要修改的就是fastcgi_param中的/scripts为$document_root
修改完成这些保存并退出,然后重启nginx:/usr/local/nginx/sbin/nginx -s reload
接下来编辑一个测试的php程序,在nginx下的html目录下创建test.php文件,打印一下php配置:[[email protected] ~]# cd /usr/local/nginx/html[[email protected] html]# touch test.php<?php phpinfo();?>
Then open the browser to enter the corresponding address to access
http://192.168.56.11/test.php
LINUX--LNMP architecture, similar to the lamp architecture