Linux(centos)下LNMP環境安裝____Linux

來源:互聯網
上載者:User
Lnmp環境安裝1.安裝相關依賴使用 yum 程式安裝所需開發包(以下為標準的rpm包名稱)yum install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-devel zlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-devel freetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel mysql-devel net-snmp-devel curl-devel perl-DBI一、編譯PHP(1)指定PHP相關配置目錄和拓展,進入已經解壓好的源碼包裡,檢查安裝環境./configure --prefix=/usr/local/php \--exec-prefix=/usr/local/php \--bindir=/usr/local/php/bin \--sbindir=/usr/local/php/sbin \--includedir=/usr/local/php/include \--libdir=/usr/local/php/lib/php \--mandir=/usr/local/php/php/man \--with-config-file-path=/usr/local/php/etc \--with-mysql-sock=/tmp/mysql.sock \--with-mysqli \--with-pdo-mysql \--with-mcrypt=/usr/include \--with-mhash \--with-openssl \--with-gd \--with-iconv \--with-zlib \--enable-zip \--enable-inline-optimization \--disable-debug \--disable-rpath \--enable-shared \--enable-xml \--enable-bcmath \--enable-shmop \--enable-sysvsem \--enable-mbregex \--enable-mbstring \--enable-ftp \--enable-gd-native-ttf \--enable-pcntl \--enable-sockets \--with-xmlrpc \--enable-soap \--without-pear \--with-gettext \--enable-session \--with-curl \--with-jpeg-dir \--with-freetype-dir \--enable-opcache \--enable-fpm \--without-gdbm \--disable-fileinfo(2)make & make install3. 複製安裝包內的設定檔(php.ini-develoment/php.ini-production)到安裝目錄/usr/local/php/lib目錄下4. 修改PHP進程檔案:/etc/php-fpm.conf.default => etc/php-fpm.conf5. 啟動php的管理進程/usr/local/php/sbin/php-fpm6. 查看php進程[root@localhost php]# ps aux | grep phproot     14760  0.0  0.6 199736  6292 ?        Ss   15:36   0:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)www      14761  0.0  0.5 199736  5744 ?        S    15:36   0:00 php-fpm: pool wwwwww      14762  0.0  0.5 199736  5748 ?        S    15:36   0:00 php-fpm: pool wwwroot     14764  0.0  0.0 103256   856 pts/1    S+   15:36   0:00 grep php7.設定開機啟動(1) vi /etc/init.d/php-fpm#!/bin/sh  # chkconfig:   2345 15 95# description:  PHP-FPM (FastCGI Process Manager) is an alternative PHP FastCGI implementation \# with some additional features useful for sites of any size, especially busier sites.# DateTime: 2016-09-20# Source function library.  . /etc/rc.d/init.d/functions  # Source networking configuration.  . /etc/sysconfig/network  # Check that networking is up.  [ "$NETWORKING" = "no" ] && exit 0  phpfpm="/usr/local/php/sbin/php-fpm"  prog=$(basename ${phpfpm})  lockfile=/var/lock/subsys/phpfpmstart() {      [ -x ${phpfpm} ] || exit 5      echo -n $"Starting $prog: "      daemon ${phpfpm}    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      start  }  reload() {      configtest || return $?      echo -n $"Reloading $prog: "      killproc ${phpfpm} -HUP      RETVAL=$?      echo  }  force_reload() {      restart  }  configtest() {    ${phpfpm} -t}  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          ;;      status)          rh_status          ;;      *)          echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"          exit 2  esac(2) 設定php-fpm檔案可執行許可權chmod a+x /etc/init.d/php-fpm(3) 將php-fpm 加入到系統開機管理列表中chkconfig --add /etc/init.d/php-fpm(4) 設定開機啟動chkconfig php-fpm on(5) 查看當前php-fpm啟動狀態chkconfig php-fpm status相關錯誤解決(1)啟動PHP進程時,報錯[root@localhost php]# ./sbin/php-fpm [06-Jan-2018 15:14:41] WARNING: Nothing matches the include pattern '/usr/local/php/etc/php-fpm.d/*.conf' from /usr/local/php/etc/php-fpm.conf at line 125.[06-Jan-2018 15:14:41] ERROR: No pool defined. at least one pool section must be specified in config file[06-Jan-2018 15:14:41] ERROR: failed to post process the configuration[06-Jan-2018 15:14:41] ERROR: FPM initialization failed解決辦法:[root@localhost php]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf(2)啟動PHP進程時,報錯,是因為有了--with-fpm-user=www \--with-fpm-group=www \ 這兩個配置項的存在,這兩個配置也可以不加入,在安裝的時候[06-Jan-2018 15:22:31] ERROR: [pool www] cannot get uid for user 'www'[06-Jan-2018 15:22:31] ERROR: FPM initialization failed報錯原因: 系統內沒有www使用者和www組解決辦法:[root@localhost php]# useradd www[root@localhost php]# groupadd www二、編譯Nginx(1)進入nginx安裝包目錄,安裝之前記得先安裝pcre(正大運算式庫)./configure --prefix=/usr/local/nginx,安裝完目錄後如下[root@localhost nginx-1.13.8]# cd /usr/local/nginx/[root@localhost nginx]# lsconf(設定檔)  html(網頁檔案)  logs(記錄檔)  sbin(主要二進位檔案)Nginx相關使用命令:1.查看Nginx進程資訊:ps aux | grep nginx[root@localhost nginx]# ps aux | grep nginxroot     17290  0.0  0.0  20476   656 ?        Ss   16:04   0:00 nginx: master process ./sbin/nginxnobody   17291  0.0  0.1  20920  1256 ?        S    16:04   0:00 nginx: worker processroot     17293  0.0  0.0 103256   856 pts/1    S+   16:04   0:00 grep nginx2.結束進程kill -9 [pid號]: kill -9 2789pkill -9 [進程名稱]: pkill -9 httpkill -INT 進程號:kill -INT 17290 => 殺掉Nginx的主進程/sbin/nginx -s stop 3.重啟./sbin/Nginx -s reloadkill -HUP `cat logs/nginx.pid`4.檢測Nginx設定檔是否有語法錯誤./sbin/nginx -t5.nginx相關知識網站:https://www.nginx.com/resources/wiki/start/topics/tutorials/commandline/6.設定nginx開機自啟動(1)vi /etc/init.d/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/local/nginx/sbin/nginx"prog=$(basename $nginx)NGINX_CONF_FILE="/usr/local/nginx/conf/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(2) 設定/etc/init.d/nginx可執行許可權chmod a+x /etc/init.d/nginx(3) 將nginx服務加入到Linux系統開機服務管理列表chkconfig --add /etc/init.d/nginx(4) 設定nginx開機啟動chkconfig nginx on(5) 查看系統開機服務nginx服務是否在其中chkconfig(6) 查看nginx服務的狀態service nginx status(7) 轉換nginx各種狀態service nginx stop/start/restart/reload/status三、PHP與nginx進行整合,使其兩者能夠進行相互連信,修改nginx的設定檔ps: php-fpm 進程的連接埠號碼是9000,所以是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;}四、編譯MySQL(MariaDB)1.解壓tar安裝包2.輸入編譯參數cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DWITHOUT_TOKUDB=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STPRAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWIYH_READLINE=1 \ -DWIYH_SSL=system \ -DVITH_ZLIB=system \ -DWITH_LOBWRAP=0 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci3.編譯錯誤 cc: Internal error: Killed (program cc1原因:系統記憶體不足解決:cc: internal compiler error: Killed (program cc1)或者g++: internal compiler error: Killed (program cc1plus)Please submit a full bug report, 主要原因大體上是因為記憶體不足,有點坑 臨時使用交換分區來解決吧,交換分區即將磁碟分割當做虛擬記憶體來使用,使用完之後,再把虛擬分區刪除掉就好了建立 swap 交換分區dd if=/dev/zero of=/swapfile bs=64M count=16mkswap /swapfileswapon /swapfile下面是執行 make 命令過程中記憶體使用量情況編譯過程。。。。。。。。。。。。。。。。。。。。。。。結束後關閉交換分區swapoff /swapfilerm /swapfile4. 使用 `mysql` 使用者執行指令碼, 安裝資料庫到資料庫存放目錄[root@localhost mysql]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqlOKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !To do so, start the server, then issue the following commands:'./bin/mysqladmin' -u root password 'new-password''./bin/mysqladmin' -u root -h localhost password 'new-password'Alternatively you can run:'./bin/mysql_secure_installation'which will also give you the option of removing the testdatabases and anonymous user created by default.  This isstrongly recommended for production servers.See the MariaDB Knowledgebase at http://mariadb.com/kb or theMySQL manual for more instructions.You can start the MariaDB daemon with:cd '.' ; ./bin/mysqld_safe --datadir='/data/mysql'You can test the MariaDB daemon with mysql-test-run.plcd './mysql-test' ; perl mysql-test-run.pl5.啟動MySQL/etc/rc.d/init.d/mysqld start6. 在開發測試階段需要進行遠程登入串連資料庫,此時可以授權一個使用者mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;username: linux系統中的一個使用者,或者插入到mysql資料庫中user表裡已經存在的使用者password:資料庫用戶端連結資料庫的設定的 7. 設定MySQL開機啟動(1)複製檔案並重新命名cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql (2) 將MySQL加入到系統自啟動管理列表中chkconfig --add mysql(3) 設定開啟啟動chkconfig mysql on(4) 顯示服務列表chkconfig(5) 如果看到mysql的服務,並且3,4,5都是on的話則成功,如果是off,則鍵入chkconfig --level 345 mysql on(6) 查看3306連接埠netstat -an | grep mysql五、編譯Redis1. 下載源碼包:wget http://download.redis.io/releases/redis-4.0.6.tar.gz2. 解壓源碼包: tar zxvf redis-4.0.6.tar.gz,進入解壓目錄 3. Redis的源碼包是已經編譯配置過的,所以直接make就可以:make4. 檢查Redis編譯安裝環境(可選): make test 5. 安裝:make install PREFIX=/usr/local/redis Redis安裝目錄可選6. 複製設定檔到安裝目錄: cp /usr/local/src/redis-4.0.6/redis.conf ./7. 啟動Redis: ./bin/redis-server ./redis.conf 8. 串連Redis用戶端:./bin/redis-cli9. 設定Redis開機啟動(1)編輯檔案: vi /etc/init.d/redis#!/bin/sh## chkconfig:   2345 90 10# description:  Redis is a persistent key-value database# Simple Redis init.d script conceived to work on Linux systems# as it does use of the /proc filesystem.REDISPORT=6379EXEC=/usr/local/redis/bin/redis-serverCLIEXEC=/usr/local/redis/bin/redis-cliPIDFILE=/var/run/redis_6379.pidCONF="/usr/local/redis/redis.conf"case "$1" in    start)        if [ -f $PIDFILE ]        then                echo "$PIDFILE exists, process is already running or crashed"        else                echo "Starting Redis server..."                $EXEC $CONF        fi        ;;    stop)        if [ ! -f $PIDFILE ]        then                echo "$PIDFILE does not exist, process is not running"        else                PID=$(cat $PIDFILE)                echo "Stopping ..."                $CLIEXEC -p $REDISPORT shutdown                while [ -x /proc/${PID} ]                do                    echo "Waiting for Redis to shutdown ..."                    sleep 1                done                echo "Redis stopped"        fi        ;;    *)        echo "Please use start or stop as first argument"        ;;esac(2) 設定redis檔案的許可權chmod 755 /etc/init.d/redis(3) 將redis服務加入到系統開機啟動列表中chkconfig --add redis(4) 設定開機啟動chkconfig redis on(4) /etc/init.d/redis中的redis相關路徑應根據實際環境改變

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.