1. 安装编译工具及库文件
yum install -y make apr* autoconf automake curl
\ curl-devel gcc gcc-c++ cmake gtk+-devel zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl
\ kernel-headers compat* cpp glibc libgomp libstdc++-devel keyutils-libs-devel libarchive
\ libsepol-devel libselinux-devel krb5-devel libXpm* freetype freetype-devel freetype* fontconfig fontconfig-devel libjpeg* libpng*
\ php-common php-gd gettext gettext-devel ncurses* libtool* libxml2 libxml2-devel patch policycoreutils bison
2. 安装依赖文件
2.1 编译安装cmake
wget https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz
tar -zxvf cmake-3.3.2.tar.gz
cd cmake-3.3.2.tar.gz
./configure --prefix=/usr/local/soft/cmake
make
make install
vim /etc/profile 在path路径中增加cmake执行文件路径:
export PATH=$PATH:/usr/local/cmake/bin
使配置立即生效:
source /etc/profile
cmake --version
2.2 安装 pcre
wget https://ftp.pcre.org/pub/pcre/pcre-8.39.tar.gz
tar -zxvf pcre-8.39.tar.gz
cd pcre-8.39
./configure --prefix=/usr/local/soft/pcre
make && make install
2.3 安装 libmcrypt
wget https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure --prefix=/usr/local/soft/libmcrypt
make && make install
2.4 安装GD库
wget https://jaist.dl.sourceforge.net/project/gd2/gd-2.0.35.tar.gz
tar -zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --enable-m4_pattern_allow --prefix=/usr/local/soft/gd --with-jpeg=/usr/lib --with-png=/usr/lib --with-xpm=/usr/lib --with-freetype=/usr/lib --with-fontconfig=/usr/lib
make && make install
3.安装nginx
3.1 配置nginx支持php
nginx.conf文件 的 http {} 里面加入 include conf/*.conf;
server { listen 80 default_server; listen 80; #listen 443 ssl; server_name www.test.com; #access_log /data/wwwlogs/xxx.xxxx.log #error_log /data/wwwlogs/xxx.xxxxx_error.log; set $root /www/test; #ssl_certificate cert/www.weigeee.com.pem; #ssl_certificate_key cert/www.weigeee.com.key; index index.html index.php; location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_split_path_info ^((?U).+.php)(/?.+)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $root$fastcgi_script_name; include fastcgi_params; } location ~ .*\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$ { root $root; } location / { root $root; index index.html index.php; if ( -f $request_filename) { break; } if ( !-e $request_filename) { rewrite ^(.*)$ /index.php/$1 last; break; } } }
3.2 nginx快捷启动配置
在/etc/init.d下创建nginx启动脚本文件: nginx
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/soft/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/soft/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 echo -n $"Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval killall -9 nginx } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
修改脚本权限:
chmod 755 nginx
将脚本文件加入到chkconfig中:
chkconfig --add nginx
设置nginx开机在3和5级别自动启动:
chkconfig --level 35 nginx on
创建软连接:
cd /usr/bin
ln -s /etc/init.d/nginx
示例:
nginx start
nginx stop
nginx restart
4.安装php7.2
./configure --prefix=/usr/local/soft/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-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel MySQL pcre-devel openssl openssl-devel curl curl-devel cp ./php.ini-development /usr/local/soft/php/etc/php.ini cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm cp /usr/local/soft/php/etc/php-fpm.conf.default /usr/local/soft/php/etc/php-fpm.conf cp /usr/local/soft/php/etc/php-fpm.d/www.conf.default /usr/local/soft/php/etc/php-fpm.d/www.conf # 加入服务 chmod +x /etc/init.d/php-fpm chkconfig --add php-fpm # 将PHP加入全局变量 vim /etc/profile export PATH=$PATH:/usr/local/soft/php/bin #保存并在命令行执行 source /etc/profile # 启动 systemctl start php-fpm
5.安装MySQL
groupadd mysql#添加mysql组
useradd -g mysql mysql -s /sbin/nologin #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统 mkdir -p /data/mysql #创建MySQL数据库存放目录 chown -R mysql:mysql /data/mysql #设置MySQL数据库目录权限 cd /lnmp/src wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz #修改文件夹名字 #将解压后的文件夹修改名字,文件夹名字改为mysql #创建data文件夹 mkdir /usr/local/soft/mysql/data #授权目录和用户 chown -R mysql:mysql mysql/ chmod -R 755 mysql/ #安装并初始化 datadir就是安装路径,basedir就是根目录 /usr/local/soft/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/soft/mysql/data --basedir=/usr/local/soft/mysql #最后一行会有默认生成的密码,记下来 A temporary password is generated for root@localhost: n2ta1yWih9-/ #复制启动脚本到资源目录 cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动 chmod 755 /etc/init.d/mysqld #增加执行权限 chkconfig mysqld on #加入到服务里面 vi /etc/rc.d/init.d/mysqld #编辑
datadir=/usr/local/soft/mysql/data #MySQL程序安装路径
basedir=/usr/local/soft/mysql/ #MySQl数据库存放目录
service mysqld start #启动 # 编辑/etc/my.cnf [mysqld] datadir=/usr/local/soft/mysql/data basedir=/usr/local/soft/mysql/ socket=/usr/local/soft/mysql/data/mysql/mysql.sock user=mysql port=3306 character-set-server=utf8 [mysqld_safe] log-error=/usr/local/soft/mysql/logs/mysqld.log pid-file=/usr/local/soft/mysql/logs/mysqld.pid vim /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行 export PATH=$PATH:/usr/local/soft/mysql/bin source /etc/profile #使配置立即生效 mkdir /var/lib/mysql #创建目录 ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock #添加软链接 # 开放远程连接 GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; grant all privileges on *.* to 'root'@'%' identified by 'root'; flush privileges;
6.安装redis
6.1 安装phpredis 扩展(让php7可以使用redis)