1、編譯部署Nginx 1.Xphp
安裝配置: [root@localhost ~]# groupadd nginx [root@localhost ~]# useradd -s /sbin/nologin -g nginx -M nginx [root@localhost ~]# systemctl stop firewalld [root@localhost ~]# systemctl disable firewalld #關掉selinux #服務器文件描述符等 [root@localhost ~]# yum install gcc gcc-c++ glibc automake pcre zlip zlib-devel openssl-devel pcre-devel wget lrzsz [root@localhost ~]# cd /usr/local/src/ [root@localhost src]# wget http://nginx.org/download/nginx-1.12.0.tar.gz [root@localhost src]# tar -zxvf nginx-1.12.0.tar.gz [root@localhost src]# cd nginx-1.12.0 [root@localhost nginx-1.12.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre [root@localhost nginx-1.12.0]# make [root@localhost nginx-1.12.0]# make install 注: --prefix:Nginx安裝目錄 --user:Nginx用戶 --group:Nginx用戶所屬組 --with-http_ssl_module:提供https支持 --with-http_flv_module:搭建flv視頻服務器使用的 --with-http_stub_status_module:開啓Stub Status模塊,該模塊會產生一個服務器狀態和信息頁 --with-http_gzip_static_module:開啓Gzip靜態模塊,該模塊用於發送預壓縮文件 --with-pcre:perl執行文件路徑 配置服務: [root@localhost nginx-1.12.0]# vi /usr/lib/systemd/system/nginx.service [Unit] Description=The nginx HTTP and reverse proxy server After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStartPre=/usr/bin/rm -f /run/nginx.pid ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/bin/kill -s HUP $MAINPID KillMode=process KillSignal=SIGQUIT TimeoutStopSec=5 PrivateTmp=true [Install] WantedBy=multi-user.target 驗證: [root@localhost nginx-1.12.0]# chmod a+x /usr/lib/systemd/system/nginx.service [root@localhost nginx-1.12.0]# /usr/local/nginx/sbin/nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful [root@localhost nginx-1.12.0]# systemctl start nginx [root@localhost nginx-1.12.0]# ps -ef | grep nginx root 24412 1 0 16:31 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 24413 24412 0 16:31 ? 00:00:00 nginx: worker process root 24415 10541 0 16:31 pts/0 00:00:00 grep --color=auto nginx 訪問: http://192.168.146.136
2、安裝PHP 7.2.10html
yum安裝方式:mysql
安裝php: [root@localhost ~]# yum -y remove httpd-tools.x86_64 [root@localhost ~]# whereis php [root@localhost ~]# rm -rf /usr/lib64/php /etc/php /etc/php.d/ /etc/php.ini /usr/local/php /usr/share/php /usr/local/php [root@localhost ~]# yum -y remove php* [root@localhost ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm [root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm [root@localhost ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml 配置文件: [root@localhost ~]# cp /usr/lib64/httpd/modules/libphp7-zts.so /usr/local/apache2.4.25/modules/ [root@localhost ~]# cp /usr/lib64/httpd/modules/libphp7.so /usr/local/apache2.4.25/modules/ 相關啓動命令: [root@localhost ~]# systemctl enable php-fpm [root@localhost ~]# systemctl start php-fpm [root@localhost ~]# systemctl status php-fpm
編譯安裝方式:linux
新增賬號: [root@localhost ~]# groupadd www [root@localhost ~]# useradd -s /sbin/nologin -g www -M www 安裝依賴: [root@localhost ~]# yum install gcc autoconf gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel readline readline-devel libxslt libxslt-devel systemd-devel openjpeg-devel libtool會生產libphp7.so 安裝php7.2.10: [root@localhost ~]# wget http://cn2.php.net/distributions/php-7.2.10.tar.gz [root@localhost ~]# tar zxvf php-7.2.10.tar.gz [root@localhost ~]# cd php-7.2.10 [root@localhost php-7.2.10]# ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-zlib-dir \ --with-freetype-dir \ --enable-mbstring \ --with-libxml-dir=/usr \ --enable-xmlreader \ --enable-xmlwriter \ --enable-soap \ --enable-calendar \ --with-curl \ --with-zlib \ --with-gd \ --with-pdo-sqlite \ --with-pdo-mysql \ --with-mysqli \ --with-mysql-sock \ --enable-mysqlnd \ --disable-rpath \ --enable-inline-optimization \ --with-bz2 \ --with-zlib \ --enable-sockets \ --enable-sysvsem \ --enable-sysvshm \ --enable-pcntl \ --enable-mbregex \ --enable-exif \ --enable-bcmath \ --with-mhash \ --enable-zip \ --with-pcre-regex \ --with-jpeg-dir=/usr \ --with-png-dir=/usr \ --with-openssl \ --enable-ftp \ --with-kerberos \ --with-gettext \ --with-xmlrpc \ --with-xsl \ --enable-fpm \ --with-fpm-user=www \ --with-fpm-group=www \ --with-fpm-systemd \ --disable-fileinfo \ --disable-phpdbg \ --disable-dtrace \ --enable-opcache [root@localhost php-7.2.10]# make [root@localhost php-7.2.10]# make test [root@localhost php-7.2.10]# make install 配置文件: [root@localhost php-7.2.10]# cp php.ini-production /usr/local/php/etc/php.ini [root@localhost php-7.2.10]# cd /usr/local/php/etc [root@localhost etc]# cp php-fpm.conf.default php-fpm.conf [root@localhost etc]# vim php-fpm.conf error_log = /usr/local/php/var/php-fpm.log pid = /usr/local/php/var/run/php-fpm.pid [root@localhost etc]]# cd /usr/local/php/etc/php-fpm.d [root@localhost php-fpm.d]]# cp www.conf.default 管理php-fpm服務: [root@localhost php-fpm.d]]# cd /root/php-7.2.10 [root@localhost php-7.2.10]# cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/ [root@localhost ~]# systemctl enable php-fpm [root@localhost ~]# systemctl start php-fpm [root@localhost ~]# systemctl status php-fpm 添加環境變量: [root@localhost ~]# vim /etc/profile 在末尾追加: export PATH=$PATH:'/usr/local/php/bin/' [root@localhost ~]# source /etc/profile 驗證版本: [root@localhost ~]# php -v PHP 7.2.10 (cli) (built: Jan 21 2019 23:25:27) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
3、配置nginx 1.12支持php7.2.10nginx
在網站目錄下創建一個文index.php的文件,驗證php是否正常(下圖表示成功): [root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf location / { root html; index index.html index.htm index.php; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } [root@localhost ~]# vi /usr/local/nginx/html/index.php <?php phpinfo(); ?> http://192.168.146.136/
4、部署MySQL 5.6.16c++
一、編譯安裝MySQL前的準備工做 安裝編譯源碼所需的工具和庫 [root@localhost ~]# yum install gcc gcc-c++ ncurses-devel perl autoconf libtool -y 安裝cmake,從http://www.cmake.org下載源碼並編譯安裝 [root@localhost ~]# cd /root/soft [root@localhost soft]# wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz 若是提示SSL下載不了,就接--no-check-certificate參數 [root@localhost soft]# tar -xzvf cmake-2.8.10.2.tar.gz [root@localhost soft]# cd cmake-2.8.10.2 [root@localhost cmake-2.8.10.2]# ./bootstrap [root@localhost cmake-2.8.10.2]# make [root@localhost cmake-2.8.10.2]# make install [root@localhost cmake-2.8.10.2]# cd ~ 二、設置MySQL用戶和組 [root@localhost ~]# groupadd mysql [root@localhost ~]# useradd -r -g mysql mysql 三、新建MySQL所須要的目錄 新建mysql安裝目錄 [root@localhost ~]# mkdir -p /usr/local/mysql 新建mysql數據庫數據文件目錄 [root@localhost ~]# mkdir -p /data/mysqldb 四、下載MySQL源碼包並解壓 [root@localhost ~]# cd /root/soft [root@localhost soft]# wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.16.tar.gz [root@localhost soft]# tar -zxv -f mysql-5.6.16.tar.gz [root@localhost soft]# cd mysql-5.6.16 從mysql5.5起,mysql源碼安裝開始使用cmake了,設置源碼編譯配置腳本。 [root@localhost mysql-5.6.16]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1 [root@localhost mysql-5.6.16]# rm CMakeCache.txt [root@localhost mysql-5.6.16]# make [root@localhost mysql-5.6.16]# make install [root@localhost mysql-5.6.16]# cd ~ 五、修改mysql相關目錄全部者和組 修改mysql安裝目錄權限: [root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# chown -R mysql:mysql . [root@localhost mysql]# cd ~ 修改mysql數據庫文件目錄權限: [root@localhost ~]# cd /data/mysqldb [root@localhost mysqldb]# chown -R mysql:mysql . [root@localhost mysqldb]# cd ~ 六、初始化mysql數據庫 [root@localhost ~]# cd /usr/local/mysql [root@localhost ~]# scripts/mysql_install_db --user=mysql --datadir=/data/mysqldb 七、生成my.cnf配置文件 [root@localhost ~]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf 注:若是/etc/my.cnf文件存在,則覆蓋。 八、複製mysql服務啓動腳本及加入PATH路徑 [root@localhost ~]# cp support-files/mysql.server /etc/init.d/mysqld [root@localhost ~]# vi /etc/profile PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH [root@localhost ~]# source /etc/profile [root@localhost ~]# echo $PATH 九、啓動mysql服務並加入開機自啓動(可選這個步驟,之後能夠本身啓動的) [root@localhost ~]# vi /etc/my.cnf #填入下面這行 datadir = /data/mysqldb [root@localhost ~]# service mysqld start [root@localhost ~]# chkconfig mysqld on 十、檢查mysql服務是否啓動 [root@localhost ~]# netstat -tulnp | grep 3306 [root@localhost ~]# mysql -u root -p 密碼爲空,若是能登錄上,則安裝成功。 十一、修改MySQL用戶root的密碼 [root@localhost ~]# /usr/local/mysql/bin/mysql_secure_installation 密碼123456 12.測試php鏈接數據庫 將網站目錄下index.php內容替換成以下,驗證數據庫是否正常(以下圖表示正常): [root@localhost ~]# vi /usr/local/nginx/html/test.php <?php $mysqli = new mysqli("localhost", "root", "123456"); if(!$mysqli) { echo"database error"; }else{ echo"php env successful"; } $mysqli->close(); ?> 1三、可能會出現的錯誤 問題: ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) 解決: 新建一個連接或在mysql中加入-S參數,直接指出mysql.sock位置。 [root@localhost ~]# ln -s /usr/local/mysql/data/mysql.sock /tmp/mysql.sock [root@localhost ~]# /usr/local/mysql/bin/mysql -u root -S /usr/local/mysql/data/mysql.sock
5、部署測試網站web
部署一個網站(CMS)做爲測試,國內比較有名的CMS有織夢、phpcms等,國外有worepress、drupal等。這裏以drupal 8爲例。詳細可參考:https://www.drupal.org/docs/user_guide/en/index.html 一、創建數據庫、數據庫用戶和密碼、受權用戶權限 [root@localhost ~]# mysql -u root -p Enter password: mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | +--------------------+ 4 rows in set (0.00 sec) mysql> CREATE DATABASE drupal CHARACTER SET utf8 COLLATE utf8_general_ci; mysql> CREATE USER drupal@localhost IDENTIFIED BY '123456'; mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY '123456'; mysql> flush privileges; mysql> exit 二、下載設置網站 [root@localhost ~]# cd /usr/local/nginx/html/ [root@localhost gxm]# wget https://ftp.drupal.org/files/projects/drupal-8.6.1.tar.gz [root@localhost gxm]# tar -zxvf drupal-8.6.1.tar.gz [root@localhost gxm]# rm -f drupal-8.6.1.tar.gz [root@localhost gxm]# mv drupal-8.6.1/* . #權限設置 三、輸入以下地址啓動安裝程序