CentOS 7.2 下編譯安裝PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法詳解(mini版本)_php執行個體

來源:互聯網
上載者:User

一、安裝前的準備工作

1、yum update #更新系統

2、yum install gcc gcc-c++ autoconf automake cmake bison m4 libxml2 libxml2-devel libcurl-devel libjpeg-devel libpng-devel libicu-devel #安裝php、MySQL、Nngix所依賴的包

3、下載以下包 #我把所有源檔案都下載在root目錄,讀者可自行修改源檔案存放目錄

3.1 libmcrypt-2.5.8.tar.gz

3.2 mcrypt-2.6.8.tar.gz

3.3 mhash-0.9.9.9.tar.gz

3.4 zlib-1.2.8.tar.gz

解壓並安裝如:

#tar -zvxf libmcrypt-2.5.8.tar.gz#cd libmcrypt-2.5.8#./configure#make && make insatll

4、在安裝軟體時如果提示有什麼依賴包沒有安裝的可以再執行yum install * -y (*表示相關包)

二、編譯安裝Nginx

1、去官網http://nginx.org/en/download.html下載最nginx-1.10.1.tar.gz的穩定版本

2、編譯步驟如下

  1、通過winSCP上傳nginx-1.10.1.tar.gz到/root目錄下

    1.1 groupadd -r nginx #建立nginx組

    1.2 useradd -r -g nginx -s /bin/false nginx #建立無登入許可權的nginx使用者

    1.3 id nginx #查看nginx組及使用者

  2、tar -zvxf nginx-1.10.1.tar.gz

  3、cd nginx-1.10.1

  4、可通過./configure --help查看編譯配置參數,也可參考http://nginx.org/en/docs/configure.html,下列參數要寫在一行中

./configure    --prefix=/usr/local/nginx    --modules-path=/usr/local/nginx/modules    --with-http_ssl_module    --pid-path=/usr/local/nginx/nginx.pid    --user=nginx    --group=nginx

  5、make && make install #編譯並安裝

  6、啟動nginx

    6.1 cd /usr/local/nginx

    6.2 sbin/nginx #啟動,可使用sbin/nginx -?查看nginx相關操作命令

  7、在/usr/lib/systemd/system目錄下建立nginx.service檔案,這樣就可以通過systemctl stop|start|reload nginx.service來操作nginx,也可參考https://www.nginx.com/resources/wiki/start/topics/examples/systemd/,內容如下:

 [Unit]    Description=The NGINX HTTP and reverse proxy server    After=syslog.target network.target remote-fs.target nss-lookup.target    [Service]    Type=forking    PIDFile=/usr/local/nginx/nginx.pid    ExecStartPre=/usr/local/nginx/sbin/nginx -t    ExecStart=/usr/local/nginx/sbin/nginx    ExecReload=/usr/local/nginx/sbin/nginx -s reload    ExecStop=/usr/local/nginx/sbin/nginx -s stop    PrivateTmp=true    [Install]    WantedBy=multi-user.target

三、編譯安裝MySQL

1、去官網http://dev.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.14.tar.gz下載帶boost的5.7.14版本

2、編譯步驟如下

  1、用winSCP上傳mysql-boost-5.7.14.tar.gz到/root目錄下

  2、groupadd mysql

  3、useradd -r -g mysql -s /bin/false mysql

  4、用cmake編譯mysql, 相關參數可以參考https://dev.mysql.com/doc/refman/5.7/en/source-configuration-options.html,下列參數要寫在一行

cmake    -DCMAKE_INSTALL_PREFIX=/usr/local/mysql    -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock    -DSYSCONFDIR=/usr/local/mysql/etc    -DSYSTEMD_PID_DIR=/usr/local/mysql    -DDEFAULT_CHARSET=utf8     -DDEFAULT_COLLATION=utf8_general_ci    -DWITH_INNOBASE_STORAGE_ENGINE=1    -DWITH_ARCHIVE_STORAGE_ENGINE=1    -DWITH_BLACKHOLE_STORAGE_ENGINE=1    -DWITH_PERFSCHEMA_STORAGE_ENGINE=1     -DMYSQL_DATADIR=/usr/local/mysql/data     -DWITH_BOOST=boost    -DWITH_SYSTEMD=1

   5、make && make install

  6、配置mysql並初始化資料庫

    6.1 cd /usr/local/mysql #進入編譯目錄

    6.2 chown -R mysql . #修改目錄所有者

    6.3 chgrp -R mysql . #修改目錄組

    6.4 cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld #配置mysqld服務

    6.5 cp /usr/local/mysql/support-files/my-default.cnf /usr/local/mysql/my.cnf #配置my.cnf

      6.5.1 複製以下內容到my.cnf檔案中的[mysqld]下   

 user = mysql         basedir = /usr/local/mysql         datadir = /usr/local/mysql/data         port = 3306         server_id = /usr/local/mysql/mysqld.pid         socket = /usr/local/mysql/mysql.sock

    6.5 chkconfig mysqld on #設定mysqld開機自啟

    6.6 bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data #初始化資料庫

    6.7 bin/mysqld --user=mysql & #啟動mysql, 如果報Please read "Security" section of the manual to find out how to run mysqld as root!,就在my.cnf中加入user=root, 表示以root使用者啟動

  7、修改root使用者登入密碼並允許root使用者遠程登入

    7.1 mysql -u root --skip-password

    7.2 ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

    7.3 允許root使用者遠程登入

    7.3.1 use mysql;

    7.3.2 update user set host='%' where user='root' and host='localhost'; #允許       (update user set host='localhost' where user='root'; #禁用)

    7.3.3 flush privileges;

    7.3.4 service mysqld restart

  8、解決service mysqld start|stop報MySQL server PID file could not be found!或者Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe), 其實可通過閱讀此檔案解決相關錯誤

    8.1 chmod 777 /usr/local/mysql #因我設定mysqld.pid檔案儲存在/usr/local/mysql目錄,所以保證其有可寫入權限    

8.2 通過winSCP修改/etc/init.d/mysqld檔案

    8.2.1 basedir=/usr/local/mysql #手動指定

    8.2.2 datadir=/usr/local/mysql/data #手動指定

    8.2.3 mysqld_pid_file_path=/usr/local/mysql/mysqld.pid #手動指定

    8.2.4 把此檔案中所有未注釋的含有mysqld_safe的字元替換成mysqld

四、編譯安裝php

1、去官網http://php.net/downloads.php下載php7.0.10版本

2、編譯步驟如下

  1、用winSCP上傳php-7.0.10.tar.gz到/root目錄下

  2、tar -zvxf php-7.0.10.tar.gz #解壓

  3、配置編譯php參數, 可使用./configure --help命令查看所有編譯設定項目, 下列參數要寫在一行中

 ./configure     --prefix=/usr/local/php    --exec-prefix=/usr/local/php    --datadir=/usr/local/php    --with-config-file-path=/usr/local/php/etc    --with-mysqli=mysqlnd    --with-pdo-mysql=mysqlnd    --with-fpm-user=nginx    --with-fpm-group=nginx    --with-gd    --with-iconv    --enable-mbstring    --enable-fpm    --enable-mysqlnd

  4、make && make install #編譯並安裝

  5、cd /usr/local/php #進入編譯目錄

  6、修改相關設定檔

    6.1 cp /usr/local/php/etc/php.ini.default /usr/local/php/etc/php.ini #php.ini中相關配置依項目需要自行修改,配置nginx支援php參考http://php.net/manual/zh/install.unix.nginx.php

    6.2 cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf #去掉[global]項下pid前的;

    6.3 cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf #大致在23、24行修改user和group如:user = nginx,group = nginx

  7、chmod 777 /usr/local/php/var/run #預設PID檔案是寫在/usr/local/php/var/run這個目錄中,所以修改目錄許可權

  8、sbin/php-fpm #啟動php, 可通過sbin/php-fpm -h 查看相關操作命令列表

  9、在/usr/lib/systemd/system目錄下建立php-fpm.service檔案,這樣就可以通過systemctl stop|start|reload php-fpm.service來操作php-fpm,內容如下:

 [Unit]    Description=The PHP FastCGI Process Manager    After=syslog.target network.target    Before=nginx.service    [Service]    Type=forking    PIDFile=/usr/local/php/var/run/php-fpm.pid    ExecStart=/usr/local/php/sbin/php-fpm    ExecStop=/bin/kill -QUIT `cat /usr/local/php/var/run/php-fpm.pid`    ExecReload=/bin/kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`    PrivateTmp=true    [Install]    WantedBy=multi-user.target

五、至此在我的VirturBox中CentOS7.2下成功搭建了LNMP環境

以上所述是小編給大家介紹的CentOS 7.2 下編譯安裝PHP7.0.10+MySQL5.7.14+Nginx1.10.1的方法詳解(mini版本),希望對大家有所協助,如果大家有任何疑問請給我留言,小編會及時回複大家的。在此也非常感謝大家對雲棲社區網站的支援!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.