LAMP是
Linux,Apache,MySQL,PHP的缩写。这个教程主要是讲在
centos安装有php和mysql支持的apache web服务器。在这个教程我使用主机名server1.example.com对应IP地址192.168.0.100。这些设置可能不同于你,你必须替换成你正确的。
添加外部源,保证MySQL和PHP最新
因为系统基本的源的MySQL和PHP程序比较旧,所以我们添加比较新的外部源。
在底部增加下面信息
安装MySQL
执行yum程序安装MySQL
- yum install mysql mysql-server
添加MySQL进启动项(这样系统启动时会自动启动MySQL),并立即启动MySQL服务器:
- chkconfig --levels 235 mysqld on
- /etc/init.d/mysqld start
设置MySQL root帐号密码:
- mysql_secure_installation
- NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
- SERVERS 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):
- 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
- them. 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
- access. 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
Apache在CentOS软件包可用,因此我们可以使用yum安装:
设置系统启动时自启动Apache
- chkconfig --levels 235 httpd on
并启动Apache
安装PHP
我们可以按照下面的命令安装PHP和Apache PHP模块:
然后重启Apache服务器:
- /etc/init.d/httpd restart
安装相关模块使用PHP支持MySQL
为了让PHP支持MySQL,我们可以安装php-mysql软件包。你也可以安装其它的php模块。可以使用以下命令搜索可用的php模块:
选择一些你需要的模块进行安装:
- yum install php-mysql php-common php-mbstring php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
现在重启Apache:
- /etc/init.d/httpd restart
安装phpMyAdmin
- vi /etc/httpd/conf.d/phpmyadmin.conf
填入如下内容:
- #
- # 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
简单配置文件:
apache的配置文件是/etc/httpd/conf下
modules放在/usr/lib/httpd下
php的配置文件在/etc/php.d/下 和/etc/php.ini
php的modules放在/usr/lib/php/modules下
在iptables里开放80端口
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
vsftpd作为FTP服务器,在
Linux系统中是非常常用的。下面我们介绍如何在
centos系统上安装vsftp。
什么是vsftpd
vsftpd是一款在Linux发行版中最受推崇的FTP服务器程序。特点是小巧轻快,安全易用。
vsftpd 的名字代表”very secure FTP daemon”, 安全是它的开发者 Chris Evans 考虑的首要问题之一。在这个 FTP 服务器设计开发的最开始的时候,高安全性就是一个目标。
安装vsftpd
1、以管理员(root)身份执行以下命令
2、设置开机启动vsftpd ftp服务
3、启动vsftpd服务
管理vsftpd相关命令:
停止vsftpd: service vsftpd stop
重启vsftpd: service vsftpd restart
配置防火墙
- vi /etc/sysconfig/iptables
在REJECT行之前添加如下代码
- -A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
保存和关闭文件,重启防火墙
配置vsftpd服务器
默认的配置文件是/etc/vsftpd/vsftpd.conf,你可以用文本编辑器打开。
- vi /etc/vsftpd/vsftpd.conf
添加ftp用户
下面是添加ftpuser用户,设置根目录为/home/wwwroot/ftpuser,禁止此用户登录SSH的权限,并限制其访问其它目录。
1、修改/etc/vsftpd/vsftpd.conf
将底下三行
- #chroot_list_enable=YES
- # (default follows)
- #chroot_list_file=/etc/vsftpd.chroot_list
改为
- chroot_list_enable=YES
- # (default follows)
- chroot_list_file=/etc/vsftpd/chroot_list
3、增加用户ftpuser,指向目录/home/wwwroot/ftpuser,禁止登录SSH权限。
- useradd -d /home/wwwroot/ftpuser -g ftp -s /sbin/nologin ftpuser
4、设置用户口令
5、编辑文件chroot_list:
- vi /etc/vsftpd/chroot_list
内容为ftp用户名,每个用户占一行,如:
peter
john
6、重新启动vsftpd
另外,如果觉得以后管理ftp用户名嫌麻烦,可以使用centos官方发布的脚本管理。地址如下:
出现的错误