Home  >  Article  >  Backend Development  >  A simple guide to setting up a LAMP vsftpd environment on CentOS, centosvsftpd_PHP tutorial

A simple guide to setting up a LAMP vsftpd environment on CentOS, centosvsftpd_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:45:17930browse

A simple guide to setting up a LAMP vsftpd environment on CentOS, centosvsftpd

VPS can be regarded as a server that only you use (in fact, it is a virtual machine) , you can install any software on it with maximum permissions. As the saying goes, with greater authority comes greater responsibility. You need to install the web server, database, PHP, and other maintenance work yourself.

The operating system provided by most VPS now is Linux, and it does not have a graphical interface. It only provides an SSH command line interface, so you need to know some simple Linux command lines. Linux has many distributions. The best distribution may be Redhat, but it is commercial software and cannot be used for free. Fortunately, it also has a community version CentOS, which completely uses the source code of Redhat and removes the Redhat LOGO. Replace it with your own and remove some closed source software, so the system functions, performance and stability are almost the same as Redhat, so I chose it.
Install Linux

For Linux installation, you can choose a distribution you are familiar with such as Ubuntu, Debian, Fedora, etc. The service provider will install it by default in a minimal installation mode. The version I chose is CentOS 6.3, taking into account the VPS memory Smaller, the 32-bit version is installed.

After installation, log in as the root user and allow the system to perform some necessary updates. Both Linux and Mac come with Terminal. If it is Windows, it is recommended to use PuTTY for SSH connection.

#以 root 用户登陆服务器
ssh root@198.xxx.xxx.xxx
...
#系统更新
yum update
...

Install Apache

Apache is an old free and open source web server on the Linux platform. It is said that more than half of the websites in the world run on Apache. To install Apache, enter the following command at the command line:

yum install httpd

The Apache installed by default may not be the latest version, but it is the most stable version tested on this Linux version. If you must install the latest version, you need to download the latest version from the Apache official website.

After installation, execute the following command to start the Apache service:

service httpd start

The default web page storage directory is located in /var/www/html/, and then visit http://198.xxx.xxx.xxx in the browser. If a test page of Apache can appear, it means that Apache has been installed successfully. .
Install MySQL

MySQL is a very popular database software. It was originally developed by the Swedish company MySQL AB and was later acquired by Sun. It is currently a product of Oracle. The command to install MySQL is as follows:

yum install mysql-server

Start the MySQL service:

service mysqld start

Then you need to set a password for the MySQL root user. You can enter the following command:

/usr/bin/mysql_secure_installation

If you execute the above command, MySQL will ask you to provide the password of the current root user. Because we have just installed it, the password is empty. Just press Enter and set the new root user password.

There will then be some security options asking you to choose Y or N. For example, whether to remove anonymous login, whether to prevent root users from logging in remotely, if you select y, then root can only log in through localhost, and whether to remove the test database, refresh the permission table immediately, etc. The general situation is as follows:

[root@CentOS6 ~]# /usr/bin/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] y
New password:
Re-enter new password:
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] y
 ... 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] y
 ... 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] y
 - 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] y
 ... 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!

Install PHP

PHP is a widely used open source dynamic scripting language. To install PHP and make it work with MySQL, you need to execute the following command:

yum install php php-mysql

At this time, you need to test whether PHP can work properly. You can create a test page.

#切换到 Apache 默认网页目录
cd /var/www/html
#创建一个 php 脚本文件
touch phpinfo.php
#向文件写入一小段 php 脚本,测试用
echo '<&#63;php phpinfo(); &#63;>' > phpinfo.php
<p># 因为刚刚安装了 PHP,所以别忘了重启一下 Apache,否则 PHP 不能正常工作<br />service httpd restart</p>

Then visit http://198.xxx.xxx.xxx/phpinfo.php in the browser to see if PHP is working normally.

If the page can display server-related environment information normally, it means that the LAMP environment is working normally.
Install vsftpd

To securely upload files to the server or download files from the server, the easiest way is to use FTP. Here we choose the very popular "Very Secure FTPD" under Linux, that is, very secure FTP:

yum install vsftpd

After installation, you still need to perform some simple configuration:

#编辑 vsftpd 配置文件
vi /etc/vsftpd/vsftpd.conf
...

#不允许匿名登陆
anonymous_enable=NO

#本地账户可以登陆
local_enable=YES

#可以写入
write_enable=YES

#所有用户只能访问其 home 目录
chroot_local_user=YES
...

#重启 vsftpd 以上设置才能生效
service vsftpd restart

How to access the server using FTP protocol? Here we recommend the FTP client tool FileZilla, which is available in Windows, Linux and Mac OS versions.

Login to vsftpd usually uses the Linux user area to log in, but the root user is not allowed to log in, so you need to create a new Linux user:

#添加用户 lichao
adduser lichao

#为 lichao 设置密码
passwd lichao

#如果出于安全考虑,这个用户你只想它能登陆 vsftpd,
#而不能以 ssh 方式登陆服务器,可以禁止其 ssh 登陆
usermod -s /sbin/nologin lichao

At this point, you can use any FTP tool such as FileZilla to log in to vsftpd with the user lichao and the corresponding password. The default directory is /home/lichao
Set up Apache, MySQL and vsftpd services to start at boot

The command to set them up at startup is as follows:

chkconfig httpd on
chkconfig mysqld on
chkconfig vsftpd on

PHP will be started with Apache.

At this point, a basically complete dynamic web server, database server, and FTP server are installed.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1041627.htmlTechArticleA simple guide to setting up a LAMP vsftpd environment on CentOS, centosvsftpd VPS can be regarded as a machine that only you can use server (actually it is a virtual machine) on which you can...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn