安裝Apache&Nginx
nginx_Apache.jpg
①.升級(jí)一下yum源(不是必須的),升級(jí)會(huì)花點(diǎn)時(shí)間,需要選擇的地方都選擇都輸入“y”即可
yum update
②. 安裝Apache
yumlist|grep httpd//查看有哪些Apache可以安裝yum install -y httpd//安裝Apache指令http -v//安裝完成后查看Apache版本指令顯示內(nèi)容如下Server version: Apache/2.4.6(CentOS)Server built:? Apr12201721:03:28
③.通過(guò)瀏覽器訪問(wèn)
在本機(jī)的瀏覽器的地址欄中輸入虛擬主機(jī)的ip地址,但是瀏覽器中沒(méi)有顯示有效的內(nèi)容
2017-06-11_124942.png
這種情況基本是Centos自帶的防火墻開啟造成的
1.關(guān)閉防火墻[root@localhost /]# systemctl systemctl stop firewalld//關(guān)閉防火墻[root@localhost /]# systemctl systemctl status firewalld//查看防火墻狀態(tài)[root@localhost /]# systemctl systemctl restart httpd//重啟Apache
再次刷新瀏覽器
2017-06-11.png
如果不想關(guān)閉防火墻,那我們可以在防火墻上允許訪問(wèn)80端口(這是Apache默認(rèn)的端口)
2.防火墻上開啟80端口[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=80/tcp//開啟80端口并且永久生效success[root@localhost /]# firewall-cmd --reload//重新載入防火墻配置success[root@localhost /]# systemctl status firewalld● firewalld.service - firewalld - dynamic firewall daemon? Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: active (running) since Sun2017-06-1113:08:10CST;8s ago//防火墻的狀體是開啟的
刷新瀏覽器依舊能訪問(wèn)到Apache的默認(rèn)頁(yè)面
④.安裝Ngixn
[root@localhost /]# yum search nginx//搜索沒(méi)有nginx這個(gè)安裝包 很遺憾的是沒(méi)有[root@localhost /]# yum install nginx//嘗試安裝Loaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.tuna.tsinghua.edu.cn * updates: mirrors.tuna.tsinghua.edu.cnNo package nginx available.//還是沒(méi)有nginx的安裝包//將nginx放到y(tǒng)um repro庫(kù)中[root@localhost /]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm[root@localhost /]# yum search nginx//再次搜索nginx安裝包======================================================== N/S matched: nginx =========================================================nginx-debug.x86_64 : debug version of nginxnginx-debuginfo.x86_64 : Debug informationforpackage nginxnginx-module-geoip.x86_64 : nginx GeoIP dynamic modulesnginx-module-geoip-debuginfo.x86_64 : Debug informationforpackage nginx-module-geoipnginx-module-image-filter.x86_64 : nginx image filter dynamicmodulenginx-module-image-filter-debuginfo.x86_64 : Debug informationforpackage nginx-module-image-filternginx-module-njs.x86_64 : nginx nginScript dynamic modulesnginx-module-njs-debuginfo.x86_64 : Debug informationforpackage nginx-module-njsnginx-module-perl.x86_64 : nginx Perl dynamicmodulenginx-module-perl-debuginfo.x86_64 : Debug informationforpackage nginx-module-perlnginx-module-xslt.x86_64 : nginx xslt dynamicmodulenginx-module-xslt-debuginfo.x86_64 : Debug informationforpackage nginx-module-xsltnginx-nr-agent.noarch : New Relic agentforNGINXandNGINX Plusnginx-release-centos.noarch : nginx repo configurationandpgppublickeyspcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metricsforthe Nginx Webservernginx.x86_64 : High performance web server//是存在nginx安裝包的[root@localhost /]# yum install nginx//安裝nginx[root@localhost /]# nginx -v//查看nginx版本nginx version: nginx/1.12.0[root@localhost /]# systemctl restart nginx// 重啟nginx
我希望通過(guò)80端口訪問(wèn)的是Apach服務(wù)器柠掂,通過(guò)8080端口訪問(wèn)的是nginx服務(wù)器轩猩,這么做?
[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=8080/tcp? success[root@localhost /]# firewall-cmd --reloadsuccess[root@localhost /]# firewall-cmd --zone=public --list-ports//查看所有打開的端口80/tcp8080/tcp//80,8080已經(jīng)打開[root@localhost /]# cd /etc/nginx/conf.d[root@localhost conf.d]# vim default.conf//將其中的listen 80;修改為 listen 8080;[root@localhost conf.d]# systemctl restart nginx//重啟nginx
通過(guò)瀏覽器訪問(wèn)
2017-06-11.png
安裝MySql
2017-06-11.png
CetOS7已使用了MariaDB替代了默認(rèn)的MySQL ,所以我們想使用MySQL還得多做點(diǎn)事情
[root@localhost /]# yum install wget? ? ? //安裝wget[root@localhost /]# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm? ? //下載mysql5.7的rpm文件[root@localhost /]# yum localinstall mysql57-community-release-el7-8.noarch.rpm? ? //安裝rmp文件[root@localhost /]#yum install mysql-community-server? //安裝MySQL數(shù)據(jù)庫(kù) 約190M左右[root@localhost /]# systemctl start mysqld? //啟動(dòng)數(shù)據(jù)庫(kù)[root@localhost /]# grep 'temporary password' /var/log/mysqld.log? //查看MySQL數(shù)據(jù)的原始密碼文件 2017-06-11T06:18:16.057811Z 1 [Note] A temporary password is generatedforroot@localhost: uvrpXRuul6/h? ? [root@localhost /]# mysql -u root -p? ? //進(jìn)入數(shù)據(jù)庫(kù)系統(tǒng)mysql>setpasswordfor'root'@'localhost'=password('Aa@123456'); //重新為數(shù)據(jù)庫(kù)設(shè)置密碼Query OK, 0 rows affected, 1 warning (0.01 sec)//將MySQL設(shè)置為開機(jī)啟動(dòng)項(xiàng)[root@localhost /]# systemctl enable mysqld[root@localhost /]# systemctl daemon-reload//設(shè)置數(shù)據(jù)的默認(rèn)字符集(非必須的)[root@localhost ~]# vim /etc/my.cnf//將下面兩行配置代碼加入到my.cnf最后面character_set_server=utf8init_connect='SET NAMES utf8'[root@localhost ~]# systemctl restart mysqld? //重啟MySQL//進(jìn)入MySQL數(shù)據(jù)庫(kù)mysql> select version();? ? +-----------+| version() |+-----------+| 5.7.18? ? |+-----------+1 rowinset(0.00 sec)mysql> show variables like'%character%';+--------------------------+----------------------------+| Variable_name? ? ? ? ? ? | Value? ? ? ? ? ? ? ? ? ? ? |+--------------------------+----------------------------+| character_set_client? ? | utf8? ? ? ? ? ? ? ? ? ? ? || character_set_connection | utf8? ? ? ? ? ? ? ? ? ? ? || character_set_database? | utf8? ? ? ? ? ? ? ? ? ? ? || character_set_filesystem | binary? ? ? ? ? ? ? ? ? ? || character_set_results? ? | utf8? ? ? ? ? ? ? ? ? ? ? || character_set_server? ? | utf8? ? ? ? ? ? ? ? ? ? ? || character_set_system? ? | utf8? ? ? ? ? ? ? ? ? ? ? || character_sets_dir? ? ? | /usr/share/mysql/charsets/ |+--------------------------+----------------------------+8 rowsinset(0.01 sec)
如果報(bào)錯(cuò) 以下是解決辦法
mysql> show datbases;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'datbases' at line 1
mysql> alter?user 'root'@'%' identified by 'roots';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
安裝PHP7
php7.jpg
//安裝依賴文件yum install 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 libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel//安裝php組新版本rpm[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpmRetrieving https://mirror.webtatic.com/yum/el7/epel-release.rpmwarning: /var/tmp/rpm-tmp.F1aZTS: Header V4 RSA/SHA1 Signature, key ID62e74ca5: NOKEYPreparing...################################# [100%]Updating / installing...1:epel-release-7-5################################# [100%][root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpmRetrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpmwarning: /var/tmp/rpm-tmp.rnxYY3: Header V4 RSA/SHA1 Signature, key ID62e74ca5: NOKEYPreparing...################################# [100%]Updating / installing...1:webtatic-release-7-3################################# [100%][root@localhost ~]# yum search php71? //查看有哪些php最新版的安裝包文件[root@localhost ~]# yum install mod_php71w php71w-mysqlnd php71w-cli php71w-fpm? //安裝php7最新版[root@localhost ~]# php -v? ? //查看php版本PHP7.1.5(cli) (built: May12201721:54:58) ( NTS )Copyright (c)1997-2017The PHP GroupZend Engine v3.1.0, Copyright (c)1998-2017Zend Technologies[root@localhost ~]# systemctl restart httpd? ? //重啟Apache[root@localhost ~]# vim /var/www/html/index.php
刷新瀏覽器
2017-06-11.png
作者:龔天元
鏈接:http://www.reibang.com/p/ed2d1820bd3e
來(lái)源:簡(jiǎn)書
簡(jiǎn)書著作權(quán)歸作者所有上炎,任何形式的轉(zhuǎn)載都請(qǐng)聯(lián)系作者獲得授權(quán)并注明出處。