egrep -v “^ #|^ $” 去除所有以#号开头的文件

Demo system

  1. [Alex@Test01 ~]$ uname -a
  2. Linux Test01 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
  3. [Alex@Test01 ~]$ ip addr | grep eth0
  4. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
  5. inet 10.0.2.128/24 brd 10.0.2.255 scope global eth0

Install httpd

  1. [Alex@Test01 yum.repos.d]$ sudo yum install -y httpd
  2. [Alex@Test01 ~]$ rpm -qa | grep httpd
  3. httpd-2.2.15-39.el6.centos.x86_64
  4. httpd-tools-2.2.15-39.el6.centos.x86_64
  5. # remove welcome page
  6. [Alex@Test01 yum.repos.d]$ sudo rm -f /etc/httpd/conf.d/welcome.conf
  7. # remove default error page
  8. [Alex@Test01 yum.repos.d]$ sudo rm -f /var/www/error/noindex.html

Configure httpd . Replace the server name to you own one.

  1. [Alex@Test01 ~]# sudo vi /etc/httpd/conf/httpd.conf
  2. # line 44: change
  3. ServerTokens Prod
  4. # line 76: change to ON
  5. KeepAlive On
  6. # line 262: Admin's address
  7. ServerAdmin luchuanjia@msn.com
  8. # line 338: change
  9. AllowOverride All
  10. # line 276: change to your server's name
  11. ServerName www.ultraera.org:80
  12. # line 402: add file name that it can access only with directory's name
  13. DirectoryIndex index.html index.htm
  14. # line 536: change
  15. ServerSignature Off
  16. # line 759: comment out
  17. # AddDefaultCharset UTF-8
  18. [Alex@Test01 ~]# sudo /etc/init.d/httpd start
  19. Starting httpd:[ OK ]
  20. [Alex@Test01 ~]# sudo chkconfig httpd on # set httpd start with system.

create a HTML test page

  1. [Alex@Test01 ~]# sudo vi /var/www/html/index.html
  2. it's ok.

HowTo Install LNMP on CentOS 6.x - 图1

Install PHP.

  1. [Alex@Test01 ~]$ sudo yum install -y php php-mbstring php-pear
  2. [Alex@Test01 ~]$ rpm -qa | grep php
  3. php-common-5.3.3-46.el6_6.x86_64
  4. php-5.3.3-46.el6_6.x86_64
  5. php-mbstring-5.3.3-46.el6_6.x86_64
  6. php-cli-5.3.3-46.el6_6.x86_64
  7. php-pear-1.9.4-4.el6.noarch
  8. [Alex@Test01 ~]$ sudo vi /etc/httpd/conf/httpd.conf
  9. # line 402 add file name that it can access only with directory's name
  10. DirectoryIndex index.html index.htm index.php
  11. [Alex@Test01 ~]$ sudo vi /etc/php.ini
  12. # line 946 set your timezone
  13. date.timezone = "Asia/Shanghai"
  14. [Alex@Test01 ~]$ sudo /etc/init.d/httpd restart
  15. Stopping httpd:[ OK ]
  16. Starting httpd:[ OK ]

create a php test page.

  1. [Alex@Test01 ~]# sudo vi /var/www/html/index.php
  2. <?php
  3. phpinfo();
  4. ?>

HowTo Install LNMP on CentOS 6.x - 图2

Install MySQL

  1. [Alex@Test01 ~]$ sudo -y install mysql-server
  2. [Alex@Test01 ~]$ rpm -qa | grep mysql-server
  3. mysql-server-5.1.73-5.el6_6.x86_64
  4. [Alex@Test01 ~]$ sudo vi /etc/my.cnf
  5. [mysqld]
  6. datadir=/var/lib/mysql
  7. socket=/var/lib/mysql/mysql.sock
  8. user=mysql
  9. # Disabling symbolic-links is recommended to prevent assorted security risks
  10. symbolic-links=0
  11. # add
  12. character-set-server=utf8
  13. [Alex@Test01 ~]$ sudo /etc/rc.d/init.d/mysqld start
  14. Initializing MySQL database: WARNING: The host 'www.ultraera.org' could not be looked up with resolveip.
  15. This probably means that your libc libraries are not 100 % compatible
  16. with this binary MySQL version. The MySQL daemon, mysqld, should work
  17. normally with the exception that host name resolving will not work.
  18. This means that you should use IP addresses instead of hostnames
  19. when specifying MySQL privileges !
  20. Installing MySQL system tables...
  21. OK
  22. Filling help tables...
  23. OK
  24. ...
  25. ...
  26. ...
  27. You can test the MySQL daemon with mysql-test-run.pl
  28. cd /usr/mysql-test ; perl mysql-test-run.pl
  29. Please report any problems with the /usr/bin/mysqlbug script!
  30. [ OK ]
  31. Starting mysqld: [ OK ]
  32. [Alex@Test01 ~]$ sudo chkconfig mysqld on

Initial settings for MySQL

  1. [root@www ~]#mysql_secure_installation
  2. NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
  3. SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
  4. In order to log into MySQL to secure it, we'll need the current
  5. password for the root user. If you've just installed MySQL, and
  6. you haven't set the root password yet, the password will be blank,
  7. so you should just press enter here.
  8. # Enter
  9. Enter current password for root (enter for none):
  10. OK, successfully used password, moving on...
  11. Setting the root password ensures that nobody can log into the MySQL
  12. root user without the proper authorisation.
  13. # set root password
  14. Set root password? [Y/n]y
  15. New password: # input any password
  16. Re-enter new password:
  17. Password updated successfully!
  18. Reloading privilege tables..
  19. ... Success!
  20. By default, a MySQL installation has an anonymous user, allowing anyone
  21. to log into MySQL without having to have a user account created for
  22. them. This is intended only for testing, and to make the installation
  23. go a bit smoother. You should remove them before moving into a
  24. production environment.
  25. # remove anonymous users
  26. Remove anonymous users? [Y/n]y
  27. ... Success!
  28. Normally, root should only be allowed to connect from 'localhost'. This
  29. ensures that someone cannot guess at the root password from the network.
  30. # disallow root login remotely
  31. Disallow root login remotely? [Y/n]y
  32. ... Success!
  33. By default, MySQL comes with a database named 'test' that anyone can
  34. access. This is also intended only for testing, and should be removed
  35. before moving into a production environment.
  36. # remove test database
  37. Remove test database and access to it? [Y/n]y
  38. - Dropping test database...
  39. ... Success!
  40. - Removing privileges on test database...
  41. ... Success!
  42. Reloading the privilege tables will ensure that all changes made so far
  43. will take effect immediately.
  44. # reload privilege tables
  45. Reload privilege tables now? [Y/n]y
  46. ... Success!
  47. Cleaning up...
  48. All done! If you've completed all of the above steps, your MySQL
  49. installation should now be secure.
  50. Thanks for using MySQL!
  51. # try to connect with root
  52. [root@www ~]#mysql -u root -p
  53. Enter password:# MySQL root password
  54. Welcome to the MySQL monitor. Commands end with ; or \g.
  55. Your MySQL connection id is 10
  56. Server version: 5.1.73 Source distribution
  57. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  58. Oracle is a registered trademark of Oracle Corporation and/or its
  59. affiliates. Other names may be trademarks of their respective
  60. owners.
  61. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  62. # display user list
  63. mysql>select user,host,password from mysql.user;
  64. +------+-----------+-------------------------------------------+
  65. | user | host | password |
  66. +------+-----------+-------------------------------------------+
  67. | root | localhost | ***************************************** |
  68. | root | 127.0.0.1 | ***************************************** |
  69. +------+-----------+-------------------------------------------+
  70. 2 rows in set (0.00 sec)
  71. # display database list
  72. mysql>show databases;
  73. +--------------------+
  74. | Database |
  75. +--------------------+
  76. | information_schema |
  77. | mysql |
  78. +--------------------+
  79. 2 rows in set (0.00 sec)
  80. mysql>exit
  81. Bye