centos7.2 Apache+PHP7.2+Mysql5.6环境搭建
yum安裝PHP7.2
由于linux的yum源不存在php7.x,所以我們要更改yum源:
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
查看yum源中有沒有php7.x
yum search php7
看到下圖,證明php已經(jīng)存在yum源中
yum 安裝php72w和各種拓展,選自己需要的即可:
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
安裝完成
查看php版本
php -v
配置php.ini
vi /etc/php.ini 按下esc進入命令模式
?
yum安裝Apacha
yum -y?install httpd
安裝Apache擴展包
yum -y?install httpd-manual?mod_ssl mod_perl mod_auth_mysql
?
yum安裝Mysql
yum -y?install mysql
yum -y?install mysql-server
yum -y?install php-mysql
?
安裝mysql-server遇到問題
錯誤:No package mysql-server available.Package php-mysql-5.4.16-36.el7_1.x86_64 already installed and latest versionNothing to do
原因是因為CentOS 7 版本將MySQL數(shù)據(jù)庫軟件從默認的程序列表中移除,用mariadb代替了
解決方案:從官網(wǎng)下載mysql-server
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm?
rpm -ivh?mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
然后需要確定,輸入y回車即可
Is this ok[y/d/N]:y
?
安裝Mysql擴展包
yum -y?install mysql-connector-odbc?mysql-devel?libdbi-dbd-mysql
?
配置Apache、mysql開機啟動
chkconfig httpd on
chkconfig mysqld on
或者
systemctl enable mysqld
systemctl daemon-reload
?
重啟Apache、mysql服務
service mysqld restart
service php-fpm start
systemctl restart httpd
?
查看mysql運行狀態(tài)
service mysqld status
systemctl status mysqld.service
?
獲取MySQL的臨時密碼
grep 'temporary password' /var/log/mysqld.log
?
登陸并修改密碼
使用默認的密碼登陸
mysql -uroot -p
用該密碼登錄到服務端后,必須馬上修改密碼,不然會報如下錯誤:
mysql> select @@log_error;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
修改密碼
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';
?
授權其他機器登陸
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;???#123456為你需要設置的密碼
mysql> FLUSH ?PRIVILEGES;
mysql> exit;
?
mysq配置默認編碼為utf8
修改/etc/my.cnf配置文件,在[mysqld]下添加編碼配置,如下所示:
[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'
?
重新啟動mysql服務
默認配置文件路徑:配置文件:/etc/my.cnf
日志文件:/var/log//var/log/mysqld.log
服務啟動腳本:/usr/lib/systemd/system/mysqld.service socket
文件:/var/run/mysqld/mysqld.pid
?
如果忘記密碼或者沒有從log日志中找到密碼
首先確認服務器出于安全的狀態(tài),也就是沒有人能夠任意地連接MySQL數(shù)據(jù)庫。
修改MySQL的登錄設置:
vim /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存并且退出vi。
重新啟動mysqld
service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
登錄并修改MySQL的root密碼
Welcome to?the MySQL monitor. Commands end?with?; or?\g.
Your MySQL connection?id is?3 to?server version: 3.23.56
Type ‘help;' or ‘\h'?for?help. Type ‘\c' to clear the buffer.
mysql> USE mysql ;
Database changed
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;
Query OK, 0 rows?affected (0.00 sec)
Rows?matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges?;
Query OK, 0 rows?affected (0.01 sec)
mysql> quit
將MySQL的登錄設置修改回來
vim /etc/my.cnf
將剛才在[mysqld]的段中加上的skip-grant-tables刪除
保存并且退出vim
重新啟動mysqld
service mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
?
?
配置Apache項目
安裝完成Apache后,我們可以使用http://你的服務器ip/測試訪問Apache,如果能顯示如下圖,則說明Apache已經(jīng)安裝成功。
?
注:如果我們測試無法打開這個頁面,那么首先要考慮幾個情況:?
1、是不是開啟了iptables防火墻,如果是的話,可以用systemctl stop iptables關閉后再試
2、是不是開啟了firewalld防火墻,如果是的話,可以用systemctl stop firewalld關閉后再試
3、是不是開啟了SELinux功能,如果是的話,可以用setenforce 0臨時關閉SELinux后再試
4、重啟Apache 服務
systemctl restart httpd
?
Apache安裝好后配置文件在/etc/httpd/conf/httpd.conf編輯它
vim /etc/httpd/conf/httpd.conf
打開文件后,我們輸入/docu,然后按下回車,這樣就可以快速搜索到我們要找到內容。如下圖,可以看到有兩個/var/www/html的地方,我們要修改的就是這兩個地方,把/var/www/html修改成我們想要的路徑,比如/www/soundasia-oa/public,該路徑為我們項目的啟動路徑,那么修改后就是這樣的。?
?
重啟Apache服務了
systemctl restart httpd
?
Centos上Apache重啟,mysql重啟, nginx 重啟方法
1.重啟 apache
service httpd restrat
/etc/init.d/httpd stop
/etc/init.d/httpd start
或
systemctl start httpd.service #啟動
systemctl stop httpd.service #停止
systemctl restart httpd.service #重啟
systemctl enable httpd.service #開機啟動
systemctl disable httpd.service #開機不啟動
systemctl status httpd.service?#檢查httpd狀態(tài)
2.重啟 mysql
service mysql restart
/etc/init.d/mysqld stop
/etc/init.d/mysqld start
3.重啟Nginx
service nginx restart
/etc/init.d/nginx stop
/etc/init.d/nginx start
各linux版本重啟apache命令
Slackware Linux命令:
/etc/rc.d/rc.httpd restart
ubuntu、Debian?系統(tǒng)命令:
/etc/init.d/apache2 restart
Fedora 、Redhat、CentOS系統(tǒng)重啟Apache命令:
/etc/init.d/httpd restart
或
service httpd restart(CentOS 成功)
?
轉載于:https://www.cnblogs.com/mjhblog/p/10529036.html
總結
以上是生活随笔為你收集整理的centos7.2 Apache+PHP7.2+Mysql5.6环境搭建的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: docker commit构建镜像(不推
- 下一篇: pyppeteer(python版pup