簡易搭建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 啟動
在本地 curl是可以的,
在其他客戶端是與80無法通信
原因好簡單嘛
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
[root@localhost ~]# vim /var/www/html/index.php [root@localhost ~]# cat /var/www/html/index.php <?php phpinfo(); ?>
systemctl restart httpd
#reload會報錯Empty reply from server,
刷新后就會顯示php 的版本及詳細內容。
mysql
網上許多教程都是使用mysql
由于版本的問題,還是使用有開源協議的mariadb,使用方法與mysql一樣
上面的yum已經一次性安裝了
cp /usr/share/mysql/my-huge.cnf /etc/my.cnf #拷貝配置文件(注意:如果/etc目錄下面默認有一個my.cnf,直接覆蓋即可)
兩個文件還是有區別的
service mariadb start ##讓我啟動服務哈 Redirecting to /bin/systemctl start mariadb.service [root@localhost ~]# mysqladmin -u root password ##修改mysql的root密碼,當然可以用 New password: rexhaha Confirm new password: rexhaha
在一遍帖子上看到的MySQL的簡單配置,我們用到主要有加密,以及授權
mysqladmin -u root password grant all privileges on *.* to 'root'@'192.168.230.%'; #%指的是shell的*字符,代表所有
用root賬號進入MySQL管理后臺,它會提示你輸入密碼: [root@localhost ~]# 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
[root@localhost ~]# mysql -uroot -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 5.5.52-MariaDB MariaDB Server Copyright (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!可以連接"; ?>
測試完后,因為這個頁面里面的信息還挺重要的,所以應該把phpinfo.php這個檔案刪除。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。