Centos7.3 LNMP+phpMyAdmin 最新环境搭建

来源:互联网 发布:奥地利 知乎 编辑:程序博客网 时间:2024/06/12 03:58

一、准备环境


yum install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-develyum install freetype-devel bzip2-devel libmcrypt libmcrypt-devel postgresql-develyum install aspell-devel readline-devel libxslt-devel net-snmp-devel unixODBC-develyum install libicu-devel libc-client-devel libXpm-devel libvpx-devel enchant-develyum install openldap openldap-devel db4-devel gmp-devel sqlite-devel mysql-develyum install pcre* pcre-devel gcc-c++ zlib* curl-devel libpng-devel freetype-develyum install libmcrypt-devel bzip2 bzip2-devel libcurl libcurl-devel libjpegyum install libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-develyum install libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

创建www用户以及www用户组

[root@ ~]#groupadd www[root@ ~]#useradd -g www www


查看是否有残留 php、nginx和apache同理

rpm -qa | gerp mysqlfind / -name mysql

二、编译安装nginx 1.13.2


下载解压进入并检查配置(可一步执行)

cd /wget nginx.org/download/nginx-1.13.2.tar.gztar -xzvf nginx-1.13.2.tar.gzcd nginx-1.13.2./configure


可选 全配置 选项一
./configure \--prefix=/usr/local/nginx \--sbin-path=/usr/local/nginx/sbin/nginx \--conf-path=/usr/local/nginx/conf/nginx.conf \--error-log-path=/var/log/nginx/error.log \--http-log-path=/var/log/nginx/access.log \--pid-path=/var/run/nginx/nginx.pid \--lock-path=/var/lock/nginx.lock  \--user=www \--group=www \--with-http_ssl_module \--with-http_stub_status_module \--with-http_gzip_static_module \--http-client-body-temp-path=/var/tmp/nginx/client/ \--http-proxy-temp-path=/var/tmp/nginx/proxy/ \--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \--http-scgi-temp-path=/var/tmp/nginx/scgi \--with-pcre


或者 仅module配置 选项二
./configure \--with-http_ssl_module \--with-http_stub_status_module \--with-http_gzip_static_module \--with-pcre


然后 编译安装
make && make install


查看nginx
whereis nginx


开启nginx

cd /usr/local/nginx/sbin/./nginx


三、yum安装mysql 5.7.19


下载安装

wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpmyum -y localinstall mysql57-community-release-el7-11.noarch.rpmyum -y install mysql-community-server


启动并加入开机启动

systemctl start mysqldsystemctl enable mysqldsystemctl daemon-reload


查看临时密码
grep 'temporary password' /var/log/mysqld.log


进入mysql
mysql -u root -pinput_temPASSWORD


设置密码
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('******');
show databases;


退出mysql
exit


重启服务
systemctl restart mysqld

四、编译安装php 7.1.8


下载解压进入

wget -c http://cn2.php.net/distributions/php-7.1.8.tar.gztar -xzvf php-7.1.8.tar.gzcd php-7.1.8


配置
./configure   \--prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--enable-fpm \--with-fpm-user=www \--with-fpm-group=www \--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-soap \--with-xmlrpc \--with-openssl \--with-mcrypt \--with-pcre-regex \--with-sqlite3 \--with-zlib \--enable-bcmath \--with-iconv \--with-bz2 \--enable-calendar \--with-curl \--with-cdb \--enable-dom \--enable-exif \--enable-fileinfo \--enable-filter \--with-pcre-dir \--enable-ftp \--with-gd \--with-openssl-dir \--with-jpeg-dir \--with-png-dir \--with-freetype-dir \--enable-gd-native-ttf \--enable-gd-jis-conv \--with-gettext \--with-gmp \--with-mhash \--enable-json \--enable-mbstring \--enable-mbregex \--enable-mbregex-backtrack \--with-libmbfl \--with-onig \--enable-pdo \--with-mysqli=mysqlnd \--with-pdo-mysql=mysqlnd \--with-zlib-dir \--with-pdo-sqlite \--with-readline \--enable-session \--enable-shmop \--enable-simplexml \--enable-sockets \--enable-sysvmsg \--enable-sysvsem \--enable-sysvshm \--enable-wddx \--with-libxml-dir \--with-xsl \--enable-zip \--enable-mysqlnd-compression-support \--with-pear \--enable-opcache


编译并安装
make && make install


编译正常结果

Build complete.Don't forget to run 'make test'.Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/Installing PHP CLI binary:        /usr/local/php/bin/Installing PHP CLI man page:      /usr/local/php/php/man/man1/Installing PHP FPM binary:        /usr/local/php/sbin/Installing PHP FPM defconfig:     /usr/local/php/etc/Installing PHP FPM man page:      /usr/local/php/php/man/man8/Installing PHP FPM status page:   /usr/local/php/php/php/fpm/Installing phpdbg binary:         /usr/local/php/bin/Installing phpdbg man page:       /usr/local/php/php/man/man1/Installing PHP CGI binary:        /usr/local/php/bin/Installing PHP CGI man page:      /usr/local/php/php/man/man1/Installing build environment:     /usr/local/php/lib/php/build/Installing header files:          /usr/local/php/include/php/Installing helper programs:       /usr/local/php/bin/  program: phpize  program: php-configInstalling man pages:             /usr/local/php/php/man/man1/  page: phpize.1  page: php-config.1Installing PEAR environment:      /usr/local/php/lib/php/[PEAR] Archive_Tar    - installed: 1.4.3[PEAR] Console_Getopt - installed: 1.4.1[PEAR] Structures_Graph- installed: 1.1.1[PEAR] XML_Util       - installed: 1.4.2[PEAR] PEAR           - installed: 1.10.5Wrote PEAR system config file at: /usr/local/php/etc/pear.confYou may want to add: /usr/local/php/lib/php to your php.ini include_path/root/php-7.1.8/build/shtool install -c ext/phar/phar.phar /usr/local/php/binln -s -f phar.phar /usr/local/php/bin/pharInstalling PDO headers:           /usr/local/php/include/php/ext/pdo/


将/php-7.1.8中的php.ini-production复制到/usr/local/php/etc并改为php.ini
将/usr/local/php/etc中的php-fpm.conf.default复制一个并改为php-fpm.conf
将/usr/local/php/etc/php-fpm.d中的www.conf.default复制并改为www.conf

查看版本

/usr/local/php/bin/php -v


启动php-fpm
/usr/local/php/sbin/php-fpm

五、安装phpMyAdmin 4.7.3


下载并解压上传到/root/www 即nginx中的目的位置


修改config.default.php 在phpMyAdmin\libraries

$cfg['PmaAbsoluteUri'] = 'http://x.x.x.x/phpMyAdmin/';(访问地址 否则可能2002)$cfg['Servers'][$i]['host'] = 'localhost';(或者为127.0.0.1)
  

六、nginx简单配置及脚本


默认web位置修改


打开 /usr/local/nginx/conf/nginx.conf

location / {            root   /root/www; 改为目的位置            index  index.php index.html index.htm;}

注意赋权 chmod 777 -R /root 此处为目的位置的根目录


关联php

location ~ \.php$ { 去掉#号注释            root           /root/www; 改为目的位置            fastcgi_pass   127.0.0.1:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  /root/www$fastcgi_script_name;            include        fastcgi_params;            index          index.php index.html;}


脚本


创建文件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 0nginx="/usr/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/etc/nginx/nginx.conf"[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginxlockfile=/var/lock/subsys/nginxmake_dirs() {   # make required directories   user=`$nginx -V 2>&1 | grep "configure arguments:.*--user=" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`   if [ -n "$user" ]; then      if [ -z "`grep $user /etc/passwd`" ]; then         useradd -M -s /bin/nologin $user      fi      options=`$nginx -V 2>&1 | grep 'configure arguments:'`      for opt in $options; do          if [ `echo $opt | grep '.*-temp-path'` ]; then              value=`echo $opt | cut -d "=" -f 2`              if [ ! -d "$value" ]; then                  # echo "creating" $value                  mkdir -p $value && chown -R $user $value              fi          fi       done    fi}start() {    [ -x $nginx ] || exit 5    [ -f $NGINX_CONF_FILE ] || exit 6    make_dirs    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}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 2esac


注意:nginx.pid文件(默认在/usr/local/nginx/logs)

脚本需修改的地方
修改成nginx执行程序的路径

nginx=”/usr/sbin/nginx”


修改成配置文件的路径
NGINX_CONF_FILE=”/etc/nginx/nginx.conf”


此项可暂不修改
lockfile


上传至 /etc/rc.d/init.d

查看nginx文件
:set ff? #可以看到dos或unix的字样. 如果的确是dos格式的。:set ff=unix #把它强制为unix格式的, 然后:wq存盘退出。

保存脚本文件后设置文件的执行权限:
chmod a+x /etc/init.d/nginx


就可以通过该脚本对nginx服务进行管理了:

/etc/init.d/nginx start/etc/init.d/nginx stop


使用chkconfig进行管理
先将nginx服务加入chkconfig管理列表:
chkconfig --add /etc/init.d/nginx


之后,就可以使用service对nginx进行启动,重启等操作了。
service nginx startservice nginx stop


设置终端模式开机启动:
chkconfig nginx on


七、php简单配置及脚本


将/root/php-7.1.8/sapi/fpm中的php-fpm复制到/etc/rc.d/init.d


注意:php-fpm.pid文件(根据配置应在/usr/local/php/var/run)


如有需要 可根据安装路径修改参数


原创粉丝点击