
programmer.jpg
“工欲善其事必先利其器”,身為一個(gè)開(kāi)發(fā)人員,快熟的搭建一個(gè)能使用的環(huán)境是必備的技能之一。我們來(lái)記錄一個(gè)簡(jiǎn)單的LA(N)MP環(huán)境的搭建的過(guò)程,也方便后面的查閱
安裝Apache&Nginx

nginx_Apache.jpg
①.升級(jí)一下yum源(不是必須的),升級(jí)會(huì)花點(diǎn)時(shí)間,需要選擇的地方都選擇都輸入“y”即可
yum update
②. 安裝Apache
yum list |grep httpd //查看有哪些Apache可以安裝
yum install -y httpd //安裝Apache指令
http -v //安裝完成后查看Apache版本指令
顯示內(nèi)容如下
Server version: Apache/2.4.6 (CentOS)
Server built: Apr 12 2017 21:03:28
③.通過(guò)瀏覽器訪問(wèn)
在本機(jī)的瀏覽器的地址欄中輸入虛擬主機(jī)的ip地址,但是瀏覽器中沒(méi)有顯示有效的內(nèi)容
2017-06-11_124942.png
這種情況基本是Centos自帶的防火墻開(kāi)啟造成的
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.防火墻上開(kāi)啟80端口
[root@localhost /]# firewall-cmd --permanent --zone=public --add-port=80/tcp //開(kāi)啟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 Sun 2017-06-11 13:08:10 CST; 8s ago //防火墻的狀體是開(kāi)啟的
刷新瀏覽器依舊能訪問(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: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.tuna.tsinghua.edu.cn
No 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 nginx
nginx-debuginfo.x86_64 : Debug information for package nginx
nginx-module-geoip.x86_64 : nginx GeoIP dynamic modules
nginx-module-geoip-debuginfo.x86_64 : Debug information for package nginx-module-geoip
nginx-module-image-filter.x86_64 : nginx image filter dynamic module
nginx-module-image-filter-debuginfo.x86_64 : Debug information for package nginx-module-image-filter
nginx-module-njs.x86_64 : nginx nginScript dynamic modules
nginx-module-njs-debuginfo.x86_64 : Debug information for package nginx-module-njs
nginx-module-perl.x86_64 : nginx Perl dynamic module
nginx-module-perl-debuginfo.x86_64 : Debug information for package nginx-module-perl
nginx-module-xslt.x86_64 : nginx xslt dynamic module
nginx-module-xslt-debuginfo.x86_64 : Debug information for package nginx-module-xslt
nginx-nr-agent.noarch : New Relic agent for NGINX and NGINX Plus
nginx-release-centos.noarch : nginx repo configuration and pgp public keys
pcp-pmda-nginx.x86_64 : Performance Co-Pilot (PCP) metrics for the Nginx Webserver
nginx.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 --reload
success
[root@localhost /]# firewall-cmd --zone=public --list-ports //查看所有打開(kāi)的端口
80/tcp 8080/tcp //80,8080已經(jīng)打開(kāi)
[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 generated for root@localhost: uvrpXRuul6/h
[root@localhost /]# mysql -u root -p //進(jìn)入數(shù)據(jù)庫(kù)系統(tǒng)
mysql> set password for 'root'@'localhost'=password('Aa@123456'); //重新為數(shù)據(jù)庫(kù)設(shè)置密碼
Query OK, 0 rows affected, 1 warning (0.01 sec)
//將MySQL設(shè)置為開(kāi)機(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=utf8
init_connect='SET NAMES utf8'
[root@localhost ~]# systemctl restart mysqld //重啟MySQL
//進(jìn)入MySQL數(shù)據(jù)庫(kù)
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.18 |
+-----------+
1 row in set (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 rows in set (0.01 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.rpm
Retrieving https://mirror.webtatic.com/yum/el7/epel-release.rpm
warning: /var/tmp/rpm-tmp.F1aZTS: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:epel-release-7-5 ################################# [100%]
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.rnxYY3: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing... ################################# [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版本
PHP 7.1.5 (cli) (built: May 12 2017 21:54:58) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies
[root@localhost ~]# systemctl restart httpd //重啟Apache
[root@localhost ~]# vim /var/www/html/index.php
<?php
phpinfo();
?>
刷新瀏覽器
2017-06-11.png



