Nginx 安裝 2php
Apache 安裝 3html
Mysql 安裝 4mysql
PHP安裝 7nginx
[root@nginx2 ~]# yum install gcc-c++ -yc++
安裝nginx的時候須要的依賴包,解壓便可web
[root@nginx2 software]# tar -xvf openssl-1.1.0g.tar.gz sql
[root@nginx2 software]# tar -xvf pcre-8.41.tar.gz 數據庫
[root@nginx2 software]# tar -xvf zlib-1.2.11.tar.gz apache
[root@nginx2 software]# tar -xvf nginx-1.12.2.tar.gz centos
添加用戶
[root@nginx2 software]# useradd nginx
[root@nginx2 software]# cd nginx-1.12.2/
配置:
[root@nginx2 nginx-1.12.2]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/software/openssl-1.1.0g --with-pcre=/software/pcre-8.41 --with-zlib=/software/zlib-1.2.11 --with-http_stub_status_module --conf-path=/usr/local/nginx/nginx.conf
編譯&安裝
[root@nginx2 nginx-1.12.2]# make && make install
測試&啓動
[root@nginx2 ~]# cd /usr/local/nginx/sbin/
[root@nginx2 sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
[root@nginx2 sbin]# ./nginx
[root@nginx2 sbin]# ps -ef | grep nginx
root 66606 1 0 22:05 ? 00:00:00 nginx: master process ./nginx
nginx 66607 66606 0 22:05 ? 00:00:00 nginx: worker process
root 66617 47667 0 22:05 pts/0 00:00:00 grep --color=auto nginx
[root@nginx2 nginx]# curl 192.168.119.131
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
安裝依賴包:
[root@nginx2 software]# yum install libtool -y
其餘三個包apr、apr-util、pcre
Apr
[root@nginx2 software]# tar -xvf apr-1.6.3.tar.gz
[root@nginx2 software]# cd apr-1.6.3/
[root@nginx2 apr-1.6.3]# ./configure --prefix=/usr/local/apr/
安裝的時候會報錯:
rm: cannot remove 'libtoolT': No such file or directory
F1:咱們須要把configure文件,查找 $RM "$cfgfile" 這個地方,用#註釋掉
F2:在configure裏面 RM='$RM -f' 這裏的$RM後面必定有一個空格。 若是後面沒有空格,直接鏈接減號,就依然會報錯。把RM='$RM'改成RM='$RM -f'
[root@nginx2 apr-1.6.3]# make && make install
Apr-util
[root@nginx2 software]# yum install expat-devel -y
[root@nginx2 software]# tar -xvf apr-util-1.6.1.tar.gz
[root@nginx2 apr-util-1.6.1]# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/ && make && make install
Pcre
[root@nginx2 software]# tar -xvf pcre-8.41.tar.gz
[root@nginx2 software]# cd pcre-8.41/
[root@nginx2 pcre-8.41]# ./configure --prefix=/usr/local/pcre/ --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/
[root@nginx2 pcre-8.41]# make && make install
安裝apache
[root@nginx2 software]# tar -xvf httpd-2.4.29.tar.gz
[root@nginx2 software]# cd httpd-2.4.29/
[root@nginx2 httpd-2.4.29]# ./configure --help
[root@nginx2 httpd-2.4.29]# ./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/
[root@nginx2 httpd-2.4.29]# make && make install
[root@nginx2 httpd-2.4.29]# cd /usr/local/apache2/
先中止nginx ,咱們先測試apache是否安裝成功
[root@nginx2 apache2]# /usr/local/nginx/sbin/nginx -s stop
[root@nginx2 apache2]# vi conf/httpd.conf
[...]
ServerName localhost:80
[...]
[root@nginx2 apache2]# ./bin/apachectl start
[root@nginx2 ~]# curl 192.168.119.131
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<title>Index of /</title>
</head>
<body>
<h1>Index of /</h1>
<ul></ul>
</body></html>
[root@nginx2 apache2]# ./bin/apachectl stop
將apache服務腳本加入到initd目錄
[root@nginx2 ~]# cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
接着咱們安裝數據庫
或者安裝mariadb
咱們這裏選擇安裝mysql數據庫
安裝cmake、ncurses-devel
[root@nginx2 software]# yum install cmake -y
[root@nginx2 software]# yum install ncurses-devel -y
建立用戶
[root@nginx2 ~]# useradd -r -U mysql -M -d /usr/local/mysql/data
修改安裝目錄的全部者和全部組
[root@nginx2 ~]# mkdir /usr/local/mysql
[root@nginx2 ~]# chown -R mysql:mysql /usr/local/mysql
修改數據目錄的全部者和全部組
[root@nginx2 ~]# mkdir -p /data/mysql
[root@nginx2 ~]# chown -R mysql:mysql /data/mysql/
解壓
[root@nginx2 ~]# cd /software/
[root@nginx2 software]# tar -xvf mysql-5.7.20.tar.gz
[將boost解壓出來便可]
[root@nginx2 software]# tar xvf mysql-boost-5.7.20.tar.gz
配置編譯參數
[root@nginx2 mysql-5.7.20]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS:STRING=utf8,gbk -DMYSQL_DATADIR=/data/mysql/ -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/software/mysql-5.7.20/boost/
安裝
[root@nginx2 mysql-5.7.20]# make && make install
初始化數據庫
[root@nginx2 mysql-5.7.20]# cd /usr/local/mysql/bin/
[root@nginx2 bin]# ./mysql_install_db --user=mysql --datadir=/data/mysql/ --basedir=/usr/local/mysql/
複製mysql服務啓動配置文件
[root@nginx2 mysql]# cp /etc/my.cnf /etc/my.cnf.bak
[root@nginx2 mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
複製mysql服務啓動腳步及加入PATH路徑
[root@nginx2 mysql]# vi /etc/profile
[...]
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
export PATH
[root@nginx2 mysql]# source /etc/profile
修改配置文件
[mysqld]
user=mysql
port=3306
socket=/data/mysql/mysql.sock
datadir=/data/mysql/
basedir=/usr/local/mysql/
explicit_defaults_for_timestamp=true
[client]
socket=/data/myssql/mysql.sock
啓動數據庫
[root@nginx2 bin]# ./mysqld_safe --user=mysql &
查看數據默認的密碼
[root@nginx2 ~]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at 2017-12-04 14:33:58
HkDh1go6#O#=
查看進程
[root@nginx2 ~]# ps -aux | grep mysql
查看端口
[root@nginx2 ~]# netstat -tulnp | grep 3306
查看日誌
[root@nginx2 ~]# tail /data/mysql/nginx2.err
登陸數據庫
1從命令行登陸MySQL數據庫服務器 1、登陸使用默認3306端口的MySQL
[root@nginx2 ~]# mysql -u root -p
2 經過TCP鏈接管理不一樣端口的多個MySQL
[root@nginx2 ~]# mysql -u root -p --protocol=tcp --host=localhost --port=3307
3 經過socket套接字管理不一樣端口的多個MySQL
[root@nginx2 ~]# mysql -u root -p --socket=/data/mysql/mysql.sock
4 經過端口和IP管理不一樣端口的多個MySQL
[root@nginx2 ~]# mysql -u root -p -P 3306 -h 127.0.0.1
中止mysql
[root@nginx2 ~]# mysqladmin -u root -p shutdown
輸入密碼
修改mysql數據庫root用戶密碼
[root@nginx2 mysql]# mysql -u root -p
Enter password: (輸入老密碼,默認密碼)
[...]
查看如今的密碼策略
mysql> show VARIABLES like "%password%";
對應的官方密碼策略表
0 or LOW | Length
1 or MEDIUM | Length;numeric,lowercase/uppercase,and special characters
2 or STRONG | Length;numeric,lowercase/uppercase,and special characters;dictionary file
修改成咱們設定的密碼
mysql> set password='Lxl@890826';
設置密碼永不過時
[root@nginx2 ]# vi /etc/my.cnf
加入:default_password_lifetime=0
修改密碼策略
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=0;
mysql> set password='redhat';
準備工做:
[root@nginx2 ~]# yum install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel -y
解壓,配置
[root@nginx2 software]# tar -xvf php-7.1.12.tar.gz
[root@nginx2 php-7.1.12]# ./configure --prefix=/usr/local/php7.1 --enable-fpm --enable-debug --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-mbstring --with-curl --with-mysqli=/usr/local/mysql/bin/mysql_config
#注意數據庫mysqli=後路徑
編譯,安裝
[root@nginx2 php-7.1.12]# make && make install
[...
Build complete.
Don't forget to run 'make test'.
Installing shared extensions: /usr/local/php7.1/lib/php/extensions/debug-non-zts-20160303/
Installing PHP CLI binary: /usr/local/php7.1/bin/
Installing PHP CLI man page: /usr/local/php7.1/php/man/man1/
Installing PHP FPM binary: /usr/local/php7.1/sbin/
Installing PHP FPM defconfig: /usr/local/php7.1/etc/
Installing PHP FPM man page: /usr/local/php7.1/php/man/man8/
Installing PHP FPM status page: /usr/local/php7.1/php/php/fpm/
Installing phpdbg binary: /usr/local/php7.1/bin/
Installing phpdbg man page: /usr/local/php7.1/php/man/man1/
Installing PHP CGI binary: /usr/local/php7.1/bin/
Installing PHP CGI man page: /usr/local/php7.1/php/man/man1/
Installing build environment: /usr/local/php7.1/lib/php/build/
Installing header files: /usr/local/php7.1/include/php/
Installing helper programs: /usr/local/php7.1/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php7.1/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php7.1/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php7.1/etc/pear.conf
You may want to add: /usr/local/php7.1/lib/php to your php.ini include_path
/software/php-7.1.12/build/shtool install -c ext/phar/phar.phar /usr/local/php7.1/bin
ln -s -f phar.phar /usr/local/php7.1/bin/phar
Installing PDO headers: /usr/local/php7.1/include/php/ext/pdo/
...]
複製配置文件
[root@nginx2 php-7.1.12]# cp php.ini-production /usr/local/php7.1/lib/php.ini
[root@nginx2 ~]# cp /usr/local/php7.1/etc/php-fpm.conf.default /usr/local/php7.1/etc/php-fpm.conf
複製啓動腳本文件
[root@nginx2 ~]# cp /software/php-7.1.12/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@nginx2 ~]# chmod +x /etc/init.d/php-fpm
啓動
[root@nginx2 ~]# /etc/init.d/php-fpm start
[root@nginx2 etc]# ps -ef | grep php
root 32511 1 0 23:30 ? 00:00:00 php-fpm: master process (/usr/local/php7.1/etc/php-fpm.conf)
nobody 32512 32511 0 23:30 ? 00:00:00 php-fpm: pool www
nobody 32513 32511 0 23:30 ? 00:00:00 php-fpm: pool www
報錯:
[root@nginx ~]# /etc/init.d/php-fpm start
Starting php-fpm [29-Nov-2017 16:43:01] WARNING: Nothing matches the include pattern '/usr/local/php7.1/etc/php-fpm.d/*.conf' from /usr/local/php7.1/etc/php-fpm.conf at line 125.
[29-Nov-2017 16:43:01] ERROR: No pool defined. at least one pool section must be specified in config file
[29-Nov-2017 16:43:01] ERROR: failed to post process the configuration
[29-Nov-2017 16:43:01] ERROR: FPM initialization failed
failed
解決:
[root@nginx php-fpm.d]# pwd
/usr/local/php7.1/etc/php-fpm.d
[root@nginx php-fpm.d]# cp www.conf.default www.conf
若是還有報錯多是配置文件php-fpm.conf最後一行,默認是註釋的,去掉註釋便可。
include=/usr/local/php7.1/etc/php-fpm.d/*.conf
[root@nginx2 ~]# vi /usr/local/nginx/nginx.conf
[root@nginx2 nginx]# cat nginx.conf
worker_processes 4;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.doudoua.com localhost;
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location / {
root html/a;
index index.html index.htm;
}
location ~ \.php$ {
root /www/php/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/a$fastcgi_script_name;
include fastcgi_params;
}
}
}
建立php首頁
[root@nginx2 a]# pwd
/usr/local/nginx/html/a
[root@nginx2 a]# vi index.php
<?php
phpinfo();
?>
測試配置文件,重啓
[root@nginx2 ~]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/nginx.conf test is successful
[root@nginx2 ~]# /usr/local/nginx/sbin/nginx -s reload