1. 程式人生 > >contos7.4 安裝lump環境php7.2+mysql7.2+nginx(最全面,無誤的)

contos7.4 安裝lump環境php7.2+mysql7.2+nginx(最全面,無誤的)

centos最新版本安裝最新的php , nginx , mysql

背景介紹:

   我在百度上看到大量的所謂lnmp安裝,百分之八十一個抄一個,還給抄錯了,剩下的百分之二十還有場景侷限, 我現在用純淨的系統開始用壓縮包安裝(因為我可以很方便的找到我的壓縮包,以及安裝的檔案)配置,我會盡量讓這個過程詳細一點;後面我會陸續記錄gitserver安裝,ftp安裝配置等等,(有可能今天一起發出來)

準備工作:(php,nginx,mysql需要的一些依賴,可能需要一陣子,耐心等待就好)

#這裡的大家都可以執行一下,已經安裝的會跳過的,不要跳著安裝,大家最好把yum 換成最新的(如果國內網易的,或者阿里的)

 yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers perl* httpd-devel postgresql-devel

#安裝所需其它依賴

1.下載pcre(支援nginx 偽靜態)

 wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.41.tar.gz

tar -xzvf pcre-8.41.tar.gz

cd   pcre-8.41

./configure --prefix=/usr/local/pcre   #配置

make && make install  #編譯安裝

2.安裝cmake (用於編譯c++)

 wget https://cmake.org/files/v3.10/cmake-3.10.1.tar.gz

 tar -xzvf cmake-3.10.1.tar.gz

 cd cmake-3.10.1

./bootstrap

make && make install     

開始安裝環境 : (/usr/local/src):

1.下載最新的php  :

wget http://cn2.php.net/distributions/php-7.2.0.tar.gz

2.下載最新的nginx:

wget http://nginx.org/download/nginx-1.13.7.tar.gz

3.下載最新的mysql :

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz

4.解壓縮

for tar in *.tar.gz;  do tar xvf $tar; done     #這裡是批量解壓縮

========安裝配置nginx:

進入nginx

cd nginx-1.13.7

 ./configure --prefix=/usr/local/nginx   #編譯配置設定

make  && make install #老規矩 安裝

echo 'PATH=/echo 'PATH=/usr/local/php/bin/:$PATH' >> /etc/profile  #配置環境變數

source /etc/profile  #立即生效

cd /usr/local/nginx/conf  #來到nginx 配置目錄下

 egrep -v "#|^$" nginx.conf.default >nginx.conf #精簡配置,方面進去修改

 vi /lib/systemd/system/nginx.service  #建立nginx 啟動檔案

 內容如下: 

[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target

 systemctl start nginx.service  #啟動nginx

 systemctl enable nginx.service #設定開機啟動


==========安裝php :

  配置: ./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-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath -enable-inline-optimization --enable-gd-jis-conv --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-pcntl --with-curl --with-fpm-user=nginx --enable-ftp --enable-session --enable-xml --with-apxs2=/usr/bin/apxs --with-pdo-pgsql --with-pdo-pgsql --with-pdo-pgsql --with-libxml-dir=/usr --enable-calendar --with-pgsql -disable-rpath --enable-inline-optimization --with-bz2 --enable-sysvshm --enable-exif --with-mhash

然後 make && make install   #編譯安裝

 echo 'PATH=/usr/local/nginx/sbin/:$PATH' >> /etc/profile  #寫入環境變數

source /etc/profile    #讓配置生效

cp php-fpm /etc/init.d/php-fpm    #設定啟動指令碼

報錯: [21-Dec-2017 16:08:42] ERROR: [pool www] please specify user and group other than root
解決 :  adduser nginx  # 新增使用者

              groupadd nginx #新增使用者組

            useradd -g nginx nginx #新建使用者同時增加工作組
vim  vim /usr/local/php/etc/php-fpm.d/www.conf  #修改
  user = nginx
  group = nginx   然後儲存 

再啟就啟動成功

========安裝mysql

進入mysql:
  groupadd -r mysql #新增mysql組

  useradd -g mysql -r -s /sbin/nologin mysql #新增mysql 使用者

  mv mysql-5.7.20-linux-glibc2.12-x86_64 /usr/local/mysql  #移動

./bin/mysqld --user=mysql --basedir=/usr/local/mysql  --datadir=/usr/local/mysql/data --initialize

安裝成功如下圖:


Note:是我們的臨時密碼;

 cp support-files/mysql.server /etc/init.d/mysqld  #加入系統程序

 echo 'PATH=/usr/local/mysql/bin/:$PATH' >> /etc/profile  #寫入環境變數

 source /etc/profile    #讓配置生效

 chkconfig mysqld on #開機啟動

mysql -u root -p #進入資料庫

updatemysql.usersetauthentication_string=password('123qwe')whereuser='root'andHost ='localhost'; #修改密碼

flushprivileges;#立刻生效

quit; 退出