CentOS 6.3 yum安裝LAMP(Apache+MySQL+PHP )

一、      安裝並配置MySQL 

1.1 執行yum 命令安裝MySQL

yum -y install mysql mysql-server

1.2 把添加MySQL進開機啓動項,並立即啓動MySQL

chkconfig --levels 235 mysqld on/etc/init.d/mysqld start

1.3 設置MySQL root帳號密碼

mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQLSERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current

password for the root user.  If you've just installed MySQL, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

Enter current password for root (enter for none): <-- 輸入系統root密碼

OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL

root user without the proper authorisation.

Set root password? [Y/n] <-- ENTER

New password: <-- 你的MySQL root密碼

Re-enter new password: <-- 你的MySQL root密碼

Password updated successfully!

Reloading privilege tables..

... Success!

By default, a MySQL installation has an anonymous user, allowing anyone

to log into MySQL without having to have a user account created for

  1. This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

Remove anonymous users? [Y/n] <-- ENTER

... Success!

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <-- ENTER

... Success!

By default, MySQL comes with a database named 'test' that anyone can

  1. This is also intended only for testing, and should be removed

before moving into a production environment.

Remove test database and access to it? [Y/n] <-- ENTER

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

Reload privilege tables now? [Y/n] <-- ENTER

... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL

installation should now be secure.

Thanks for using MySQL!

      安裝Apache 

2.1 使用yum命令安裝Apache

yum –y install httpd

2.2 設置開機啓動Apache

chkconfig --levels 235 httpd on

2.3 啓動Apache

/etc/init.d/httpd start

2.4 現在直接在瀏覽器鍵入http://localhost 或http://本機IP,應該會看到Apache的測試頁面

      安裝配置PHP 

3.1 使用yum命令安裝PHP

yum –y install php

3.2 重啓Apache服務器

/etc/init.d/httpd restart

3.3 安裝相關模塊使用PHP支持MySQL:爲了讓PHP支持MySQL,我們可以安裝php-mysql軟件包;也可使用以下命令搜索可用的php模塊

yum search php

選擇需要的模塊進行安裝

yum –y install php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc

3.4 重啓Apache服務器

/etc/init.d/httpd restart

      安裝配置phpMyAdmin 

安裝好MySQL,Apache及PHP後,爲了可視化的管理MySQL數據庫,我們需要安裝phpMyAdmin

4.1 下載最新版本phpMyAdmin,下載地址:http://www.phpmyadmin.net/home_page/downloads.php ,選擇最新版本,如phpMyAdmin-3.5.2-all-languages.tar.bz2

4.2 解壓程序包

tar -xvf phpMyAdmin-3.5.2-all-languages.tar.bz2

4.3 移動目錄phpMyAdmin-3.5.2-all-languages到/usr/share/phpMyAdmin文件夾(建議手工操作,複製粘貼至/usr/share/目錄下,後重命名文件名爲phpMyAdmin,使用下面的命令行可能導致打開http://localhost/ phpmyadmin時,提示403錯誤,暫時不知怎麼回事- -!)

mv phpMyAdmin-3.5.2-all-languages /usr/share/phpMyAdmin

4.4 進入phpMyAdmin目錄

cd /usr/share/phpMyAdmin

4.5 拷貝樣本配置文件到config.inc.php文件

cp config.sample.inc.php config.inc.php

4.6 修改Apache配置

vi /etc/httpd/conf.d/phpmyadmin .conf

4.7 寫入如下內容

#  Web application to manage MySQL

#<Directory "/usr/share/phpMyAdmin">

#  Order Deny,Allow

#  Deny from all

#  Allow from 127.0.0.1

#</Directory>

Alias /phpmyadmin /usr/share/phpMyAdmin

Alias /phpMyAdmin /usr/share/phpMyAdmin

Alias /mysqladmin /usr/share/phpMyAdmin

寫入並退出

4.8 重啓Apache服務器

/etc/init.d/httpd restart

4.9 至此,打開頁面http://localhost/phpmyadmin 即可輕鬆管理你的mySQL數據庫



#####################################################################3333

mysql的一些筆記!

yum安裝mysql很是方便,但安裝好之後的問題卻搞了半天。

首先,安裝mysql。
yum list | grep mysql; 選擇合適的版本,yum intall 該版本;
yum list | grep mysql-server;選擇合適的版本,yum intall 該版本。
安裝完成後,添加 mysqld 服務。
/sbin/chkconfig –-add mysqld [在服務清單中添加mysql服務]
接着開始啓動mysql。
service mysqld start;(即/etc/init.d/mysqld start。也可設成開機自啓動:/sbin/chkconfig mysqld on
然後,額。。。出現 “MySQL Daemon failed to start”的信息,怎麼辦?自己是這樣解決的。
1. 初始化數據庫
    /usr/bin/mysql_install_db --user=mysql
    cp /usr/share/mysql/my-small.cnf /etc/my.cnf(可選)
2. 以safe方式登錄mysql
     cd /usr ; 
    /usr/bin/mysqld_safe &
3. 再次啓動mysqld服務時就可以了。
下面就是常規的操作了:
  更改 root 密碼:  mysqladmin -u root password 'newpassword'
  添加mysql用戶: GRANT ALL PRIVILEGES ON my_db.* TO 'user'@'localhost' IDENTIFIED BY 'password';
  刪除test數據庫: mysql -u root -p mysql> DROP DATABASE test; 
  刪除匿名帳戶: DELETE FROM mysql.user WHERE user = ''; 
  重載權限: mysql> FLUSH PRIVILEGES; 
  設置默認編碼等一些初始參數(my.cnf)(若無my.cnf, 則可cp /usr/share/mysql/my-small.cnf /etc/my.cnf)
   vi /etc/my.cnf
   [mysqld]
   datadir=/var/lib/mysql
   socket=/var/lib/mysql/mysql.sock
   user=mysql
   default-character-set=utf8 [添加]
   default-storage-engine=INNODB [添加]
   old_passwords=1
   [client]
   default-character-set=utf8 [添加]
   [mysqld_safe]
   log-error=/var/log/mysqld.log
   pid-file=/var/run/mysqld/mysqld.pid

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章