CentOS7 yum搭建lamp

來源:互聯網
上載者:User

標籤:centos7 lamp

簡易搭建lamp


環境說明:

        server:CentOS7-192.168.230.202

        client: win8.1-192.168.230.59

        Apache/2.4.6 

        php Version 5.4.16

        5.5.52-MariaDB

yum group install Development Tools

#安裝開發工具,GCC...



yum install httpd mariadb mariadb-server php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt -y


#安裝apache mariadb php以及各種運行庫和工具


service httpd start 啟動


650) this.width=650;" src="http://s5.51cto.com/wyfs02/M02/8B/DE/wKioL1hbc1_DjdnNAAA_58A2a08651.png-wh_500x0-wm_3-wmp_4-s_163967230.png" title="(P$E0AX2TYFS)2JI$DRVVT5.png" alt="wKioL1hbc1_DjdnNAAA_58A2a08651.png-wh_50" />

在本地 curl是可以的,

在其他用戶端是與80無法通訊


650) this.width=650;" src="http://img.baidu.com/hi/face/i_f29.gif" alt="i_f29.gif" />原因好簡單嘛


selinux 和firewalld


setenforce 0

#關閉selinux

systemctl stop firewalld

#關閉防火牆嘛


在用戶端本地hosts添加

192.168.230.202 www.rex.com


vi /etc/httpd/conf/httpd.conf #編輯
找到 #ServerName www.example.com:80
修改為 ServerName www.rex.com:80  

找到

#<IfModule dir_module>

    DirectoryIndex index.php index.html

</IfModule>

添加index.php



現在可以在工作目錄添加網頁

路徑為/var/www/html

[[email protected] ~]# vim /var/www/html/index.php[[email protected] ~]# cat /var/www/html/index.php<?php        phpinfo();?>


systemctl restart httpd

#reload會報錯Empty reply from server,


650) this.width=650;" src="http://s2.51cto.com/wyfs02/M00/8B/E0/wKioL1hblPXyieFjAACMprmdjRI288.png" title="%@($%%FHGSJG04GN46Y{(TT.png" alt="wKioL1hblPXyieFjAACMprmdjRI288.png" />


重新整理後就會顯示php 的版本及詳細內容。



mysql


網上許多教程都是使用mysql

由於版本的問題,還是使用有開源協議的mariadb,使用方法與mysql一樣


上面的yum已經一次性安裝了


cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷貝設定檔(注意:如果/etc目錄下面預設有一個my.cnf,直接覆蓋即可)

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/8B/E5/wKiom1hbppKTuNuzAADqpB1IE9g460.png-wh_500x0-wm_3-wmp_4-s_4215543330.png" title="QQ圖片20161222181621.png" alt="wKiom1hbppKTuNuzAADqpB1IE9g460.png-wh_50" />


兩個檔案還是有區別的


service mariadb start##讓我啟動服務哈Redirecting to /bin/systemctl start  mariadb.service[[email protected] ~]# mysqladmin -u root password##修改mysql的root密碼,當然可以用New password: rexhahaConfirm new password: rexhaha



在一遍文章上看到的MySQL的簡單配置,我們用到主要有加密,以及授權

mysqladmin -u root passwordgrant all privileges on *.* to ‘root‘@‘192.168.230.%‘;#%指的是shell的*字元,代表所有
用root帳號進入MySQL管理後台,它會提示你輸入密碼:[[email protected] ~]# mysql -u root –p建立本機使用者:mysql> create user ‘使用者名稱‘@‘localhost‘ identified by ‘密碼‘;建立新資料庫:mysql> create database 資料庫名;將指定資料庫的所有許可權授給指定使用者:mysql> grant all privileges on 資料庫名.* to ‘使用者名稱‘@‘localhost‘;重新整理系統許可權表:mysql> flush privileges;進入mysql資料庫(系統內建),並查詢是否存在指定使用者(如果有出現一堆東西,則表明存在):mysql> use mysql;mysql> select * from user where user = ‘使用者名稱‘;如果要刪除本機使用者,使用:mysql> drop user ‘使用者名稱‘@‘localhost‘;如果要刪除資料庫,使用:mysql> drop database 資料庫名;查看存在的資料庫:mysql> show databases;退出MySQL管理後台:mysql> exit


[[email protected] ~]# mysql -uroot -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 9Server version: 5.5.52-MariaDB MariaDB ServerCopyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.MariaDB [(none)]> create user ‘rex‘@‘localhost‘ identified by ‘rexhaha‘    -> ;##上面那句結尾忘記加;號了,所以到一下行才加上   Query OK, 0 rows affected (0.02 sec)##執行成功的反饋MariaDB [(none)]> create database rexhome;##建立rexhome資料庫Query OK, 1 row affected (0.00 sec)MariaDB [(none)]> grant all privileges on *.* to ‘rex‘ @ ‘localhost‘;ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘‘localhost‘‘ at line 1##報錯提示MariaDB [(none)]> grant all privileges on rexhome.* to ‘rex‘ @ ‘localhost‘ ; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘‘localhost‘‘ at line 1##加資料庫名測試了一下還是報錯MariaDB [(none)]> grant all privileges on rexhome.* to ‘rex‘@‘localhost‘ ;  ##原來是在‘user’@‘host’地方加了空格Query OK, 0 rows affected (0.02 sec)MariaDB [(none)]> grant all privileges on *.* to ‘rex‘@‘localhost‘ ;       ##授權給rex帳號,所有資料及所有表的許可權Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges;更新許可權表Query OK, 0 rows affected (0.00 sec)

測試資料庫是否已串連

vim /var/www/html/index.php

<?php $link=mysql_connect("localhost","rex","rexhaha"); if(!$link) echo "FAILD!串連錯誤,使用者名稱密碼不對"; else echo "OK!可以串連"; ?>

650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/8B/EF/wKiom1hcy1GBrh_nAABeW4kODPg536.png-wh_500x0-wm_3-wmp_4-s_250284901.png" title="QQ圖片20161223150541.png" alt="wKiom1hcy1GBrh_nAABeW4kODPg536.png-wh_50" />


650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />650) this.width=650;" src="http://img.baidu.com/hi/jx2/j_0058.gif" alt="j_0058.gif" />



測試完後,因為這個頁面裡面的資訊還挺重要的,所以應該把phpinfo.php這個檔案刪除。

CentOS7 yum搭建lamp

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.