1、編譯安裝Nginxphp
# cd /usr/local/srchtml
# wget http://nginx.org/download/nginx-1.16.0.tar.gzmysql
# tar -zxvf nginx-1.16.0.tar.gznginx
# cd nginx-1.16.0c++
# yum install -y gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-develsql
# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/local/nginx/sbin/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --pid-path=/usr/local/nginx/run/nginx.pid --lock-path=/usr/local/nginx/run/nginx.lock --http-client-body-temp-path=/usr/local/nginx/run/client_body_temp --http-proxy-temp-path=/usr/local/nginx/run/proxy_temp --http-fastcgi-temp-path=/usr/local/nginx/run/fastcgi_temp --http-uwsgi-temp-path=/usr/local/nginx/run/uwsgi_temp --http-scgi-temp-path=/usr/local/nginx/run/scgi_temp --http-log-path=/usr/local/nginx/log/access.log --error-log-path=/usr/local/nginx/log/error.log --with-debug --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_degradation_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module
# make
# make installshell
安裝完畢,啓動/關閉/重啓Nginx命令以下:json
# /usr/local/nginx/sbin/nginx //啓動
# /usr/local/nginx/sbin/nginx -s stop //關閉
# /usr/local/nginx/sbin/nginx -s reload //重啓
附帶:查看啓動狀態
# ps -ef | grep nginxvim
設置Nginx開機啓動(參考自:https://www.jianshu.com/p/ca5ee5f7075c)瀏覽器
# vi /usr/lib/systemd/system/nginx.service
# 在文件中寫入啓動腳本
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/usr/local/nginx/sbin/nginx -s reload
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存上述腳本文件,並執行以下命令,完成Nginx開機啓動設置:
# systemctl enable nginx.service
重啓系統
# reboot
查看Nginx是否開機啓動成功,在瀏覽器輸入:http://localhost
爲了讓nginx命令有效,將nginx添加到系統環境變量中:
# vim /etc/profile
在profile文件中添加以下兩行代碼:
PATH=$PATH:/usr/local/nginx/sbin
export PATH
保存退出/etc/profile文件,執行以下命令讓profile當即生效:
# source /etc/profile
2、編譯安裝PHP 7.2
# cd /usr/local/src
# wget https://www.php.net/distributions/php-7.2.20.tar.gz
# tar -zxvf php-7.2.20.tar.gz
# cd php-7.2.20
# yum install -y gcc gcc-c++ make automake autoconf gd file bison patch mlocate flex diffutils 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 libcurl libcurl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers openldap-devellibxslt-devel kernel-devel libtool-libs readline-devel gettext-devel libcap-devel php-mcrypt libmcrypt libmcrypt-devel recode-devel gmp-devel icu libxslt libxslt-devel php-devel
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql-sock --with-mysqli --with-libxml-dir --with-openssl --with-mhash --with-pcre-regex --with-zlib --with-iconv --with-bz2 --with-curl --with-cdb --with-pcre-dir --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --with-gettext --with-gmp --with-mhash --with-libmbfl --with-onig --with-pdo-mysql --with-zlib-dir --with-readline --with-libxml-dir --with-xsl --with-pear --enable-fpm --enable-soap --enable-bcmath --enable-calendar --enable-dom --enable-exif --enable-fileinfo --enable-filter --enable-ftp --enable-gd-jis-conv --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --enable-pdo --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --enable-zip --enable-mysqlnd-compression-support
# make
# make install
建立php-fpm.conf、www.conf配置文件:
# cd /usr/local/php/etc
# cp php-fpm.conf.default php-fpm.conf
# cd /usr/local/php/etc/php-fpm.d
# cp www.conf.default www.conf
建立php.ini配置文件:
# find /usr/local/src/php-7.2.20 -name php.ini*
# cp /usr/local/src/php-7.2.20/php.ini-production /usr/local/php/etc/php.ini
手動啓動和關閉php:
# /usr/local/php/sbin/php-fpm
# /usr/bin/pkill -9 php-fpm
# pstree -p | grep php
設置php-fpm開機啓動:
首先,關閉php-fpm進程:
# /usr/bin/pkill -9 php-fpm
而後,修改php-fpm.conf中的 [pid = /run/php-fpm.pid] 配置項,該配置在後續的php-fpm.service文件中須要用到
# vi /usr/local/php/etc/php-fpm.conf
建立php-fpm.service文件:
# vi /usr/lib/systemd/system/php-fpm.service
# 在文件中寫入啓動腳本
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=/usr/bin/pkill -9 php-fpm
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存上述腳本文件,並執行以下命令,完成php-fpm開機啓動設置:
# systemctl enable php-fpm.service
這樣就能夠使用systemctl命令管理php-fpm:
# systemctl start php-fpm.service
# systemctl stop php-fpm.service
也能夠使用以下命令管理php-fpm:
# service php-fpm start
# service php-fpm stop
# service php-fpm restart
# service php-fpm reload
整合Nginx + PHP:
# vi /usr/local/nginx/conf/nginx.conf
# 修改默認的server{}配置爲以下內容:
server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; root "/usr/local/nginx/html"; location / { index index.html index.htm index.php l.php; autoindex off; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php(.*)$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^((?U).+\.php)(/?.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
保存文件,重啓Nginx服務器:
# nginx -s reload
在server{}的root目錄 /usr/local/nginx/html 中建立一個phpinfo.php文件,測試整合是否成功:
http://localhost/phpinfo.php
3、yum安裝MySQL 5.7
參考:http://www.javashuo.com/article/p-favipguq-bg.html
# 下載mysql源安裝包
shell> wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
# 安裝mysql源
shell> yum localinstall mysql57-community-release-el7-8.noarch.rpm
# 檢查mysql源是否安裝成功
shell> yum repolist enabled | grep "mysql.*-community.*"
說明:能夠修改vim /etc/yum.repos.d/mysql-community.repo源,改變默認安裝的mysql版本;
好比要安裝5.6版本,將5.7源的enabled=1改爲enabled=0。而後再將5.6源的enabled=0改爲enabled=1便可。
# 安裝MySQL
shell> yum install mysql-community-server
# 啓動MySQL服務
shell> systemctl start mysqld
# 查看MySQL的啓動狀態
shell> systemctl status mysqld
# 開機啓動
shell> systemctl enable mysqld
shell> systemctl daemon-reload
# 修改root本地登陸密碼
mysql安裝完成以後,在/var/log/mysqld.log文件中給root生成了一個默認密碼。
經過下面的方式找到root默認密碼,而後登陸mysql進行修改:
shell> grep 'temporary password' /var/log/mysqld.log
shell> mysql -uroot -p
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
或者
mysql> set password for 'root'@'localhost'=password('123456');