A simple guide to building a LAMP+VSFTPD environment on CentOS _php tips

Source: Internet
Author: User
Tags install php mysql commands php script phpinfo vps filezilla ftp protocol web hosting

VPS can be viewed as a server that only you use (in fact it is a virtual machine), you can install any software on it, with the maximum permissions. The more permissions, the greater the responsibility, you need to install your own WEB server, database, PHP, and other maintenance work to be handled by itself.

Now most VPS provides the operating system is Linux, and there is no graphical interface, only the SSH command line interface, so need some simple Linux command line. Linux has a number of distributions, the best distribution may be Redhat, but it is commercial software, can not be used for free, but fortunately it also has a community version CentOS, completely using the Redhat source code, remove Redhat LOGO, replace into their own, In addition to remove some of the closed-source software, so the system function, performance and stability is almost equivalent to Redhat, chose it.
Installing Linux

For Linux installation, you can choose your familiar distribution such as Ubuntu, Debian, Fedora and so on, the service chamber to minimize the installation of the default installed, I chose the version is CentOS 6.3, considering the VPS memory is small, installed a 32-bit version.

After installation to log in as root, and allow the system to make some necessary updates. Linux and Mac all come with Terminal, and if it's Windows, it's recommended to use PuTTY for SSH connections.

#以 root User Login server
ssh root@198.xxx.xxx.xxx ...
#系统更新
Yum Update
...

Install Apache

Apache is a legacy free Open-source Web server on a Linux platform, and more than half of the world's web sites are said to run on Apache. To install Apache, enter the following command at the command line:

Yum Install httpd

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

Once installed, execute the following command to start the Apache service:

Service httpd Start

The default Web hosting directory is located in/var/www/html/, then access http://198.xxx.xxx.xxx in the browser, if a test page of Apache can appear, then the Apache has been installed successfully.
Installing MySQL

MySQL is a very popular database software, originally developed by the company MySQL AB, Sweden, after being acquired by Sun, currently for the Oracle company's products, the installation of MySQL commands are as follows:

Yum Install Mysql-server

To start the MySQL service:

Service mysqld Start

Then you need to set a password for the MySQL root user and enter the command:

/usr/bin/mysql_secure_installation

If you execute the above command, MySQL will ask you to provide the password for the root user now, because we have just installed, so the password is empty, direct return, and then set the new root user password.

Then there will be some security options for you to choose Y or N. For example, whether to remove the anonymous login, whether to prevent the root user from remote landing, if you choose Y, then root can only be logged in localhost, as well as whether to remove the test database, immediately refresh the table of rights, and so on, about the following:

[Root@centos6 ~]#/usr/bin/mysql_secure_installation

Note:running all PARTS The This SCRIPT are 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'll be blank, so you should just

Press ENTER here.

Enter current password for root (enter to 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 the anonymous user, allowing anyone to log into MySQL without have to have a user AC Count created for them. This is intended only for testing, and to make the installation go a bit smoother. Should remove them before moving into a production Environment. Remove anonymous users? [y/n] Y ...

success! Normally, Root should only is allowed to connect from ' localhost '.

This ensures is someone cannot guess at the root password from the network. Disallow root login remotely? [y/n] Y ...

success! By default, the MySQL comes with a database named ' test ' that anyone can access.

This is also intended only for testing, and should are removed before into a moving production. Remove test database and access to it? [y/n] y-dropping Test Database ...
 success! -Removing privileges on test database ...

success!

Reloading the privilege tables would ensure this all changes made so far would take effect. Reload privilege tables now? [y/n] Y ...

success!



Cleaning up ... All done!

If you have ' ve completed all of the above steps, your MySQL installation should now be secure.

 The for using mysql!

Installing 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 point you need to test whether PHP will work correctly, you can build a test page.

#切换到 the Apache default page directory
cd/var/www/html
#创建一个 php script file Touch
phpinfo.php
#向文件写入一小段 php script, test with
Echo ' <?php phpinfo ();?> ' > phpinfo.php

# because you just installed PHP, don't forget to restart Apache, or PHP will not work properly
Service httpd Restart

The browser then accesses http://198.xxx.xxx.xxx/phpinfo.php to see if PHP is working properly.

If the page can display server-related environment information correctly, the LAMP environment can be working properly.
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 Linux Very popular "Very secure FTPD", that is very secure FTP:

Yum Install vsftpd

Once installed, there are some simple configurations to make:

#编辑 vsftpd config file
vi/etc/vsftpd/vsftpd.conf ...

#不允许匿名登陆
anonymous_enable=no

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

#可以写入
write_enable=yes

# All users can only access their home directory
chroot_local_user=yes ...

#重启 vsftpd above settings to take effect
service vsftpd restart

How to access the server with the FTP protocol, this is recommended FileZilla this FTP client tool, has the Windows version, Linux version and Mac OS version.

Landing vsftpd generally with the Linux user area login, but not allowed to log in with the root user, so, need to create a new Linux User:

#添加用户 Lichao
adduser lichao

#为 lichao Set password
passwd Lichao

#如果出于安全考虑, this user you just want it to be able to login vsftpd,
# Instead of SSH login to the server, you can prevent its SSH landing
usermod-s/sbin/nologin Lichao

At this point, you can use any FTP tools such as FileZilla, to lichao this user and the corresponding password to login vsftpd, the default directory is/home/lichao
set Apache, MySQL, and VSFTPD services to boot

Set up their boot-up commands as follows:

Chkconfig httpd on
chkconfig mysqld on
chkconfig vsftpd on

PHP will start with Apache.

At this point, a basic complete Dynamic Web server, database server, FTP Server installation completed.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.