參考官方文檔:http://nginx.org/en/linux_pac...php
官當提供了利用yum來安裝、升級nginx的方法
在/etc/yum.repos.d/目錄下建立nginx.repo文件,輸入如下代碼:html
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/OSRELEASE/$basearch/ gpgcheck=0 enabled=1
將OSRELEASE替換爲'5'、'6','7'或者'5.x'、'6.x'、'7.x',根據當前centos的系統版本替換便可。
設置好nginx.repo文件以後,開始用yum安裝nginxmysql
# sudo yum install -y nginx
yum提示安裝完成,則代表安裝成功
到此nginx安裝完成了。等咱們安裝完php,再對nginx進行設置!linux
# wget http://cn2.php.net/get/php-7.0.1.tar.gz/from/this/mirror
建議安裝以前先看看安裝幫助文件INSTALLnginx
# tar zxvf php-7.0.0.tar.gz # cd php-7.0.0
首先查看安裝幫助sql
# ./configure --help
開始預編譯數據庫
# ./configure --prefix=/usr/local/php \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable-inline-optimization \ --enable-gd-native-ttf \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip
若是配置錯誤,須要安裝須要的模塊,直接yum一併安裝依賴庫vim
# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
# make && make install
# cp php.ini-development /usr/local/php/lib/php.ini # cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf # cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf # cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
須要注意的是php7中www.conf這個配置文件配置phpfpm的端口號等信息,若是你修改默認的9000端口號需在這裏改,再改nginx的配置windows
# /etc/init.d/php-fpm
查看phpinfo()
centos
注意:這一點是額外的,能夠根據自身需求而定,我我的以爲每次用/etc/init.d/php-fpm 啓動很不方便!
編輯php-fpm.conf
# vim /usr/local/php/etc/php-fpm.conf
把pid 改爲 /run/php-fpm.pid
pid = /run/php-fpm.pid
加php-fpm管理器到systemctl中
# vim /usr/lib/systemd/system/php-fpm.service
按i寫入如下內容
[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
啓動php-fpm
systemctl start php-fpm.service
添加到開機啓動
systemctl enable php-fpm.service
若是設置成功,能夠將以前添加到/etc/init.d/php-fpm刪除
# vim /usr/local/php/etc/php-fpm.d/www.conf
查看listen的值,默認是 listen=127.0.0.1:9000
# cd /etc/nginx/conf.d # vim default.conf
看到相似內容
server { 2 listen 80; 3 server_name localhost; 4 5 #charset koi8-r; 6 #access_log /var/log/nginx/log/host.access.log main; 7 8 location / { 9 root /usr/share/nginx/html; 10 index index.html index.htm; 11 } 12 13 #error_page 404 /404.html; 14 15 # redirect server error pages to the static page /50x.html 16 # 17 error_page 500 502 503 504 /50x.html; 18 location = /50x.html { 19 root /usr/share/nginx/html; 20 } 21 22 # proxy the PHP scripts to Apache listening on 127.0.0.1:80 23 # 24 #location ~ \.php$ { 25 # proxy_pass http://127.0.0.1; 26 #} 27 28 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 29 # 30 location ~ \.php$ { 31 root /usr/share/nginx/html; 32 fastcgi_pass 127.0.0.1:9000; 33 fastcgi_index index.php; 34 # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 35 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 36 include fastcgi_params; 37 } 38 39 # deny access to .htaccess files, if Apache's document root 40 # concurs with nginx's one 41 # 42 #location ~ /\.ht { 43 # deny all; 44 #} 45 }
去掉30行至37行的註釋,將root修改成19行的路徑(默認localhost域名訪問的文件路徑)
考慮到國內的網速較慢,mysql文件包較大,使用yum安裝不太現實,源碼編譯耗時較久,在此咱們採用rpm包安裝!
能夠參考官方文檔:
http://dev.mysql.com/doc/refm...
按照官方文檔,咱們須要逐一下載各個rpm包,然而官方文檔也說了有打包好的rar供咱們下載,咱們須要作的只是按照本身的系統版本,下載對應的rar包
下表列出了各個系統對應mysql的rar包名,當前個人系統個版本是centOS7.1 64位,故我選擇下載mysql-5.7.10-1.el7.x86_64.rpm-bundle.tar,帶-bundle.tar的表明是全部rpm包的集合包!
注意:考慮到國內下載mysql官網mysql包可能較慢,特此提供國內的一個鏡像:http://mirrors.sohu.com/mysql...
找到mysql-5.7.10-1.el7.x86_64.rpm-bundle.tar這個包,下載下來
下載的rar包能夠在windows下用rar軟件解壓,而後搬到centos中,因爲本人使用的是vagrant,因此直接將解壓好的文件夾放到了共享目錄,供虛擬機訪問
進入解壓好的mysql包文件夾
# cd mysql-5.7.10-1.el7.x86_64.rpm-bundle
使用yum進行安裝(也可使用rpm命令安裝,不過可能會遇到依賴性的錯誤,使用yum安裝,最大好處就是不用解決軟件包之間的依賴性!yum使用本地下載好的軟件包安裝起來也比較方便)
# sudo yum install mysql-community-{server,client,common,libs}-* mysql-5.*
看到相似如下輸出
Dependencies Resolved ========================================================================================================================= Package Arch Version Repository Size ========================================================================================================================= Installing: mysql-community-client x86_64 5.7.10-1.el7 /mysql-community-client-5.7.10-1.el7.x86_64 109 M mysql-community-common x86_64 5.7.10-1.el7 /mysql-community-common-5.7.10-1.el7.x86_64 2.5 M mysql-community-libs x86_64 5.7.10-1.el7 /mysql-community-libs-5.7.10-1.el7.x86_64 9.8 M replacing mariadb-libs.x86_64 1:5.5.41-2.el7_0 mysql-community-libs-compat x86_64 5.7.10-1.el7 /mysql-community-libs-compat-5.7.10-1.el7.x86_64 9.2 M replacing mariadb-libs.x86_64 1:5.5.41-2.el7_0 Transaction Summary ========================================================================================================================= Install 4 Packages Total size: 130 M Is this ok [y/d/N]:
這裏輸入y。看到相似如下輸出:
Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. Installing : mysql-community-common-5.7.10-1.el7.x86_64 1/5 Installing : mysql-community-libs-5.7.10-1.el7.x86_64 2/5 Installing : mysql-community-client-5.7.10-1.el7.x86_64 3/5 Installing : mysql-community-libs-compat-5.7.10-1.el7.x86_64 4/5 Erasing : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 5/5 warning: file /etc/my.cnf: remove failed: No such file or directory Verifying : mysql-community-common-5.7.10-1.el7.x86_64 1/5 Verifying : mysql-community-libs-5.7.10-1.el7.x86_64 2/5 Verifying : mysql-community-client-5.7.10-1.el7.x86_64 3/5 Verifying : mysql-community-libs-compat-5.7.10-1.el7.x86_64 4/5 Verifying : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 5/5 Installed: mysql-community-client.x86_64 0:5.7.10-1.el7 mysql-community-common.x86_64 0:5.7.10-1.el7 mysql-community-libs.x86_64 0:5.7.10-1.el7 mysql-community-libs-compat.x86_64 0:5.7.10-1.el7
本人測試過程當中發現沒裝上mysql-community-server.x86_64 0:5.7.10-1.el7
因而再次安裝
# sudo yum install mysql-community-server-5.7.10-1.el7.x86_64.rpm
到此一共安裝了六個軟件包
啓動mysql:
# sudo service mysqld start
驗證是否啓動成功:
# ps -aux | grep mysql
若是看到mysql進程則說明啓動成功!
注意:新版mysql考慮到安全問題,root默認密碼再也不是root,有些說法認爲,新版mysql會在root家目錄下生成一個".mysql_secret"文件,本人並未查看到該文件。
首先修改mysql配置文件
# sudo vim /etc/my.cnf
在[mysqld]下面添加"skip-grant-tables",表示禁用受權,這樣用戶能夠直接登陸mysql!
重啓mysql
# sudo service mysqld restart
登陸mysql
# mysq
進入到mysql客戶端界面
mysql >use mysql; mysql >UPDATE user SET authentication_string=PASSWORD("NEWPASSWORD") WHERE User='root'; mysql >FLUSH PRIVILEGES; mysql >quit;
注意:authentication_string=PASSWORD("NEWPASSWORD")中的PASSWORD是mysql的加密函數,用於生成加密字符串,因此不要漏掉這個函數!另外列名是User,而不是user。
註釋配置文件中的免受權登陸代碼
# sudo vim /etc/my.cnf
重啓mysql:
# sudo service mysqld restart
重啓登陸mysql客戶端:
# mysql -uroot -p
輸入密碼,便可進行操做,若是仍是報1820的錯,則說明以前你設置的密碼不符合密碼規則,爲了安全 ,新版mysql密碼規則有所變化,設置的密碼需包含大寫、小寫字母、數字、特殊符號。
到此mysql安裝、設置基本完成,爲了方便後期開發,我選擇新建一個超級用戶,若是你也有該需求,能夠參考
使用mysql自帶客戶端添加可遠程登錄的用戶,首先使用root用戶登錄本地的mysql,執行如下命令:
mysq> GRANT ALL PRIVILEGES ON *.* TO admin@localhost IDENTIFIED BY "你的密碼" WITH GRANT OPTION;
上句代碼新增了一個admin用戶能夠經過密碼訪問本機mysql數據庫。
執行如下代碼
mysq> GRANT ALL PRIVILEGES ON *.* TO admin@'%' IDENTIFIED BY "123456" WITH GRANT OPTION;
這一句代碼則是授予用戶admin用戶經過任意主機訪問mysql數據庫
若是進行以上設置,依然沒法遠程鏈接,能夠考慮有多是iptables的問題
退出mysql客戶端
mysql> exit;
CentOS 7.0默認使用的是firewall做爲防火牆,這裏改成iptables防火牆。
關閉firewall:
# systemctl stop firewalld.service #中止firewall
# systemctl disable firewalld.service #禁止firewall開機啓動