1.安裝Apache
yum install httpd
相關(guān)命令:
systemctl start httpd.service #啟動(dòng)apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重啟apache
systemctl enable httpd.service #設(shè)置apache開(kāi)機(jī)啟動(dòng)
2.安裝PHP
yum install php php-devel
3.安裝mysql
下載mysql的repo源
$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
安裝mysql-community-release-el7-5.noarch.rpm包
$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
安裝這個(gè)包后,會(huì)獲得兩個(gè)mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。
安裝mysql
$ sudo yum install mysql-server
4.安裝 php和mysql關(guān)聯(lián)模塊
yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
成功安裝之后重啟mysql服務(wù)
# service mysqld restart
初次安裝mysql是root賬戶(hù)是沒(méi)有密碼的
設(shè)置root用戶(hù)密碼
方法1:
# mysql -uroot
mysql> set password for ‘root’@‘localhost’ = password('mypasswd');
mysql> exit
方法2:用mysqladmin
mysqladmin -u root password "newpassword"
如果root已經(jīng)設(shè)置過(guò)密碼,采用如下方法
mysqladmin -u root password oldpass "newpassword"
新建一個(gè)用戶(hù)
grant all privileges on *.* to 創(chuàng)建的用戶(hù)名 @"%" identified by "密碼";
flush privileges; * 刷新剛才的內(nèi)容*
格式:grant 權(quán)限 on 數(shù)據(jù)庫(kù)名.表名 to 用戶(hù)@登錄主機(jī) identified by "用戶(hù)密碼";
如:grant all privileges on *.* to user1@" localhost" identified by "bodatech"; (本地登錄)
user1用戶(hù)只能本地登錄,可以操作所有數(shù)據(jù)庫(kù)
grant all privileges on test.* to user2@"%" identified by "boda";(遠(yuǎn)程登錄)
user2用戶(hù)可以遠(yuǎn)程登錄,并且只能操作test數(shù)據(jù)庫(kù)下的所有表
更新現(xiàn)有用戶(hù)的權(quán)限,只需修改以上命令相關(guān)參數(shù),運(yùn)行即可
@ 后面是訪(fǎng)問(wèn)mysql的客戶(hù)端IP地址(或是 主機(jī)名) % 代表任意的客戶(hù)端。
數(shù)據(jù)庫(kù)操作,詳見(jiàn)鏈接(謝謝老A的分享):
http://www.cnblogs.com/xdpxyxy/archive/2012/11/16/2773662.html
5.Apache配置
找到/etc/httpd/conf/httpd.conf
添加Listen 80 監(jiān)聽(tīng)端口
DocumentRoot "/var/www/html" 網(wǎng)站路徑
修改Directory
<Directory "/var/www/html"> ##這里的路徑和上面修改一致
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Require all granted
</Directory>
多站點(diǎn)配置:http://www.cnblogs.com/makeup/p/5433837.html
6.問(wèn)題總結(jié):
1、linux下php代碼不執(zhí)行 不解析 不運(yùn)行 顯示php代碼
解決方案:
打開(kāi)/etc/httpd/conf/httpd.conf
找到AddType application/x-gzip .gz .tgz
在下一行加入AddType application/x-httpd-php .php
注意AddType application/x-httpd-php .php不要拼寫(xiě)錯(cuò)了。
2、數(shù)據(jù)庫(kù)不能遠(yuǎn)程連接
修改my.conf文件
找到bind-address = 127.0.0.1改為bind-address = 0.0.0.0即可
3、php獲取時(shí)間默認(rèn)UTC
改為北京時(shí)間
找到php.ini /etc/php.ini ,若找不到可執(zhí)行phpinfo()查看
修改date.timezone = "PRC"
4、修改Apache路徑大小寫(xiě)敏感問(wèn)題
找到/etc/httpd/conf/http.conf
添加一下內(nèi)容:
LoadModule speling_module /usr/lib64/httpd/modules/mod_speling.so 加載模塊
CheckSpelling on 開(kāi)啟模塊
聯(lián)系客服