編譯安裝LNMP

軟件:MySQL-5.7.2、PHP-7.1.5、Nginx-1.14.2

安裝mysql:
卸載系統自身mariadb:
[[email protected] ~]# rpm -qa |grep mariadb
mariadb-libs-5.5.64-1.el7.x86_64
[[email protected] ~]# rpm -e mariadb-libs-5.5.64-1.el7.x86_64 --nodeps

安裝依賴包:
[[email protected] ~]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel perl-Data-Dumper boost boost-doc boost-devel

創建源碼目錄:
[[email protected] ~]# mkdir /home/tools && cd /home/tools

解壓源碼包:
[[email protected] tools]# mv /root/mysql-boost-5.7.22.tar.gz .
[[email protected] tools]# ll
total 47840
-rw-r--r--. 1 root root 48985783 Jan 1 02:12 mysql-boost-5.7.22.tar.gz
[[email protected] tools]# tar zxvf mysql-boost-5.7.22.tar.gz
[[email protected] tools]# cd mysql-5.7.22/

創建目錄:
[[email protected] mysql-5.7.22]# mkdir /usr/local/mysql
[[email protected] mysql-5.7.22]# mkdir /usr/local/mysql/mydata
[[email protected] mysql-5.7.22]# mkdir /usr/local/mysql/conf
[[email protected] mysql-5.7.22]# groupadd mysql
[[email protected] mysql-5.7.22]# useradd -s /sbin/nologin -g mysql -M mysql
[[email protected] mysql-5.7.22]# chown -R mysql:mysql /usr/local/mysql*

預編譯:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/mydata \
-DSYSCONFDIR=/usr/local/mysql/conf \
-DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_DEBUG=0 -DMYSQL_MAINTAINER_MODE=0 \
-DWITH_SSL:STRING=bundled -DWITH_ZLIB:STRING=bundled \
-DWITH_SYSTEMD=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./boost

注意:---------------------------------------------------------------
-DWITH_SYSTEMD=1 ------>是否支持systemd方式管理MySQL
-DDOWNLOAD_BOOST=1 ------>自動下載boost支持
-DWITH_BOOST=./boost ------>本地boost目錄
爲了簡化本地連接MySQL,提供一種封裝形式的TCP/IP協議。
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock

編譯:
[[email protected] mysql-5.7.22]# make
[[email protected] mysql-5.7.22]# make install

初始化:
[[email protected] mysql-5.7.22]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/usr/local/mysql/mydata --basedir=/usr/local/mysql

修改配置文件:
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/mydata
socket=/usr/local/mysql/mysql.sock
log_error=/var/log/mysql.log
user=mysql
[client]
socket=/usr/local/mysql/mysql.sock

創建日誌文件:
[[email protected] ~]# touch /var/log/mysql.log
[[email protected] ~]# chown -R mysql:mysql /var/log/mysql.log

更新啓動腳本:
[[email protected] ~]# vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

systemd管理啓動:
[[email protected] ~]# systemctl start mysqld

配置環境變量:
[[email protected] ~]# echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/etc/profile
[[email protected] ~]# source /etc/profile

密碼配置:
[[email protected] ~]# mysqladmin -uroot password 000000
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

#################解決方法########################
在/etc/my.cnf中添加skip-grant-tables
然後重啓mysql
[[email protected] ~]# mysql
mysql> update mysql.user set authentication_string=password("000000") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
####新版的mysql數據庫下的user表中已經沒有Password字段了。
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
然後去掉my.cnf配置文件添加的那句,重啓mysql
[[email protected] ~]# mysql -uroot -p000000
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

安裝PHP
創建用戶:
[[email protected] ~]# groupadd nginx
[[email protected] ~]# useradd -s /sbin/nologin -g nginx -M nginx -u 122gin -u 122 -M nginx

安裝依賴包:
yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-devel libpng-devel freetype-devel libmcrypt-devel libxslt-devel libicu-devel
##在Centos默認yum源裏沒有libmcrypt-devel,需要安裝第三方yum源
[[email protected] ~]# wget http://www.atomicorp.com/installers/atomic
[[email protected] ~]# sh ./atomic
[[email protected] ~]# yum install libmcrypt-devel

解壓PHP包:
[[email protected] ~]# cd /home/tools/
[[email protected] tools]# mv /root/php-7.1.5.tar.gz .
[[email protected] tools]# tar zxvf php-7.1.5.tar.gz
[[email protected] tools]# cd php-7.1.5

預編譯:
./configure --prefix=/usr/local/php-7.1.5 \
--with-config-file-path=/usr/local/php-7.1.5/etc \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--enable-fpm \
--with-fpm-user=nobody \
--with-fpm-group=nobody \
--with-pdo-mysql=mysqlnd \
--with-iconv-dir \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--enable-mbregex \
--enable-mbstring \
--enable-intl \
--with-mcrypt \
--enable-ftp \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--with-gettext \
--enable-opcache \
--with-xsl

編譯安裝:
[[email protected] php-7.1.5]# make
[[email protected] php-7.1.5]# make install

優化處理配置:
[[email protected] ~]# ln -s /usr/local/php-7.1.5 /usr/local/php
[[email protected] php-7.1.5]# cp php.ini-development /usr/local/php/lib/php.ini
[[email protected] php-7.1.5]# vi /usr/local/php/lib/php.ini
##修改以下內容
mysqli.default_socket = /usr/local/mysql/mysql.sock //將php與mysql關聯
date.timezone = Asia/Shanghai //設置時區
pdo_mysql.default_socket=/usr/local/mysql/mysql.sock //修改mysql.sock文件路徑

驗證安裝的模塊:
[[email protected] php-7.1.5]# /usr/local/php/bin/php -m

配合fpm模塊:
[[email protected] php-7.1.5]# cd /usr/local/php/etc/
[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf
[[email protected] etc]# cd /usr/local/php/etc/php-fpm.d/
[[email protected] php-fpm.d]# cp www.conf.default www.conf
[[email protected] php-fpm.d]# vim /usr/local/php/etc/php-fpm.conf
##修改以下內容
pid = run/php-fpm.pid //分號去掉

配置systemd管理:
[[email protected] php-fpm.d]# vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.
conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target
[[email protected] php-fpm.d]# systemctl daemon-reload

啓動fpm模塊:
[[email protected] php-fpm.d]# systemctl start php-fpm.service
[[email protected] php-fpm.d]# systemctl enable php-fpm.service
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to /usr/lib/systemd/system/php-fpm.service.

默認9000端口提供服務

安裝nginx:
安裝依賴包:
[[email protected] ~]# yum -y install pcre* openssl-devel

解壓源碼包:
[[email protected]localhost ~]# cd /home/tools/
[[email protected] tools]# mv /root/nginx-1.14.2.tar.gz .
[[email protected] tools]# tar zxvf nginx-1.14.2.tar.gz

預編譯:
[[email protected] tools]# cd nginx-1.14.2
./configure --prefix=/usr/local/nginx \
--with-http_ssl_module --with-http_stub_status_module \
--with-http_stub_status_module --with-pcre

編譯:
[[email protected] nginx-1.14.2]# make && make install

檢查是否安裝成功:
[[email protected] nginx-1.14.2]# /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

備份並修改配置文件:
[[email protected] nginx-1.14.2]# cd /usr/local/nginx/conf/
[[email protected] conf]# cp nginx.conf nginx.conf.bak
[[email protected] conf]# cat nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" ';
access_log logs/access.log main;

server {
    listen       80;
    server_name  192.168.10.130;
    location / {
        root   html/www;
        index  index.php index.html index.htm;
    }
    location ~ .*\.(php|php5)?$ {
        root   html/www;  #PHP程序訪問的站點數據信息
        fastcgi_pass  127.0.0.1:9000; #9000代表就是PHP服務程序
        fastcgi_index index.php; #指定動態請求的默認首頁文件
        include fastcgi.conf;
    }
}

}

加入systemd管理:
[[email protected] conf]# vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx server daemon
Documentation=man:nginx(8)
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
[[email protected] conf]# systemctl daemon-reload
[[email protected] conf]# systemctl start nginx
[[email protected] conf]# systemctl enable nginx

默認站點目錄:
[[email protected] conf]# cd /usr/local/nginx/html/

測試文件添加:
測試PHP文件:
[[email protected] conf]# cd /usr/local/nginx/html/
[[email protected] html]# mkdir www
[[email protected] html]# echo '<?php phpinfo(); ?>' > www/phpinfo.php
測試Mysql文件:
[[email protected] html]# vim www/mysql.php
<?php
$link=mysqli_connect('localhost','root','000000');
if($link) echo "<h1>Database connection successful</h1>";
else echo "Fail!!";
?>

瀏覽器訪問:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章