Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

CentOS 6.7 uses yum to quickly build LAMP environment

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

LAMP refers to the first letter of Linux (operating system), Apache HTTP server, MySQL database software (sometimes MariaDB) and PHP (sometimes Perl or Python). It is generally used to set up web servers.

Linux is free and open source software, which means that the source code is available for the operating system.

Apache is the most popular open source WEB server software in use.

MySQL is a multi-thread, multi-user SQL database management system.

PHP,Perl or Python:PHP is a programming language that originally designed and produced dynamic websites. PHP is the application software mainly used on the server side. Perl is similar to Python.

Configure the yum source:

Since the yum installation is used here, the premise is that the yum source must be configured. In order to speed up the download, it is recommended to use NetEase's yum source. After we install the system, the default is the system's own yum source, domestic users use yum to install software, it is relatively slow, in order to improve efficiency, generally configure the domestic yum source.

The better yum sources in China are NetEase yum source, Sohu yum source and so on. Now introduce how to configure NetEase 163yum source:

Official link [help on using CentOS Images]: http://mirrors.163.com/.help/centos.html

The structure of the collection is: i386 ~ x86 ~ 64 ~ SRPMS

Included versions are: 5.x and 6.x series

Update time: update every 5 hours

1. Back up / etc/yum.repos.d/CentOS-Base.repo first

[root@localhost ~] # mv / etc/yum.repos.d/CentOS-Base.repo / etc/yum.repos.d/CentOS-Base.repo.$ (date+%F) _ backup

2. Choose to download the corresponding repo file according to different versions of CentOS and put it in the / etc/yum.repos.d/ directory.

[root@localhost ~] # cd / etc/yum.repos.d/

# CentOS 5.x

[root@localhost ~] # wget http://mirrors.163.com/.help/CentOS5-Base-163.repo-O / etc/yum.repo.d

# CentOS 6.x

[root@localhost ~] # wget http://mirrors.163.com/.help/CentOS6-Base-163.repo-O / etc/yum.repo.d

3. Finally, execute the yum makecache generation cache

[root@localhost ~] # yum clean all

[root@localhost ~] # yum makecache

OK, it can be configured in three simple steps.

This approach is very convenient for beginners, but the customizability is not strong, and the software version is low. It is generally used in experimental and learning environments.

Preparation:

1. Configure the firewall to open port 80 and port 3306

[root@localhost ~] # vim / etc/sysconfig/iptables

-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 80-j ACCEPT # allows port 80 to pass through the firewall

-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 3306-j ACCEPT # allow port 3306 to pass through the firewall

Note: many netizens add these two rules to the last line of the firewall configuration, causing the firewall to fail to start, and the correct one should be added to the default port 22 rule.

As follows:

# # #

# Firewall configuration written by system-config-firewall

# Manual customization of this file is not recommended.

* filter

: INPUT ACCEPT [0:0]

: FORWARD ACCEPT [0:0]

: OUTPUT ACCEPT [0:0]

-An INPUT-m state-- state ESTABLISHED,RELATED-j ACCEPT

-An INPUT-p icmp-j ACCEPT

-An INPUT-I lo-j ACCEPT

-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 22-j ACCEPT

-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 80-j ACCEPT

-An INPUT-m state-- state NEW-m tcp-p tcp-- dport 3306-j ACCEPT

-An INPUT-j REJECT-- reject-with icmp-host-prohibited

-A FORWARD-j REJECT-- reject-with icmp-host-prohibited

COMMIT

# # #

[root@localhost ~] # / etc/init.d/iptables restart # restart the firewall to make the configuration effective

2. Close SELINUX

[root@localhost ~] # vim / etc/selinux/config

# SELINUX=enforcing # comment out

# SELINUXTYPE=targeted # comment out

SELINUX=disabled # increased

: wq! # Save exit

[root@localhost] # shutdown-r now# restart the system

Installation:

First, install Apache

[root@localhost ~] # yum-y install httpd # install when prompted

[root@localhost ~] # / etc/init.d/httpd start # start Apache

Note: an error will be prompted after Apache starts:

Starting httpd:httpd: Could not reliably determine the server's fully qualif domain name, using:: 1 for ServerName

Solution:

[root@localhost ~] # vim / etc/httpd/conf/httpd.conf # Editor

Find # ServerName www.example.com:80

Change it to ServerName www.jbaobao.net:80 # and set it to your own domain name. If you don't have a domain name, you can set it to localhost.

: wq! # Save exit

[root@localhost ~] # chkconfig httpd on # is set to boot

[root@localhost ~] # / etc/init.d/httpd restart # restart Apache

Install apache related extensions

[root@localhost ~] # yum-y install httpd-manual mod_ssl mod_perl mod_auth_mysql

Type http://localhost or http:// native IP directly into the browser, and you will see the test page of Apache, where you need to pay attention to the setting of iptables.

Second, install MySQL

1. Install MySQL

[root@localhost ~] # yum-y install mysql mysql-server mysql-devel # asks if you want to install

[root@localhost ~] # / etc/init.d/mysqld start # start MySQL

[root@localhost ~] # chkconfig mysqld on # is set to boot

[root@localhost ~] # cp / usr/share/mysql/my-medium.cnf / etc/my.cnf # copy the configuration file (Note: if there is a my.cnf by default under the / etc directory, you can overwrite it directly)

2. Set the password for the root account

[root@localhost ~] # / usr/bin/mysql_secure_installation

Enter and enter Y according to the prompt

Enter the password twice and enter

Enter Y all the way according to the prompt

Last appeared: Thanks for using MySQL!

After setting the MySql password, restart MySQL:

[root@localhost ~] # / etc/init.d/mysqld start # start

[root@localhost ~] # netstat-tulpn | grep-I mysql

Tcp 0 0 0.0.0.0 3306 0.0.0.015 * LISTEN 1723/mysqld

OK, see that mysqld has been started, listening on port 3306.

Third, install PHP5

Install related modules: to make PHP support MySQL, you can install the php-mysql package; you can also use the command to search for available php modules

1. Install PHP5

[root@localhost ~] # yum-y install php # install when prompted

2. Install the common components of PHP to make PHP5 support MySQL

[root@localhost ~] # yum search php

[root@localhost ~] # yum-y install libmcrypt libjpeg* gd gd-devel php-gd php-mysql php-common php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash # here choose to install with the above installation package

[root@localhost ~] # / etc/init.d/mysqld restart # restart MySql

[root@localhost ~] # / etc/init.d/httpd restart # restart Apche

Fourth, install Webmin

Webmin is the most powerful Unix system management tool based on Web at present. The administrator accesses various management functions of Webmin through the browser and completes the corresponding management actions.

Download the Webmin RPM package

[root@localhost ~] # wget http://prdownloads.sourceforge.net/webadmin/webmin-1.580-1.noarch.rpm

Please go to the official website to see if it is the latest version of the link. Webmin Download

Install Webmin

[root@localhost] # rpm-U webmin-1.550-1.noarch.rpm

* the following error occurred on this machine:

Header V3 DSA signature: NOKEY, key ID 11f63c51

The solution is as follows: please refer to linux Header V3 DSA signature: NOKEY, key ID error Resolution

[root@localhost ~] # rpm--import / etc/pki/rpm-gpg/RPM*

[root@localhost] # rpm-U webmin-1.550-1.noarch.rpm

Start Webmin

[root@localhost ~] # / etc/rc.d/init.d/webmin start

If you access the Webmin,Ip through the browser as: 192.168.1.63, then the URL for accessing Webmin is http://192.168.1.63:10000, the user name is: root, and the password is: root.

Configuration section

1. Apache configuration

[root@localhost ~] # vim / etc/httpd/conf/httpd.conf # edit file

ServerTokens OS # is modified to: ServerTokens Prod at line 44 (the name of the server operating system is not displayed when an error page appears)

ServerSignature On # is modified to: ServerSignature Off at line 536 (the version of Apache is not displayed in the error page)

At line 331, Options Indexes FollowSymLinks # is modified to: Options Includes ExecCGI FollowSymLinks (allows the server to execute CGI and SSI, and forbids listing directories)

# AddHandler cgi-script .cgi # modified at line 796 to: AddHandler cgi-script .cgi .pl (allows CGI scripts with a .pl extension to run)

AllowOverride None # is modified at line 338 to: AllowOverride All (allow .htaccess)

AddDefaultCharset UTF-8 # is changed to: AddDefaultCharset GB2312 at line 759 (adding GB2312 as the default encoding)

Options Indexes MultiViews FollowSymLinks # changed to Options MultiViews FollowSymLinks at line 554 (does not display the tree directory structure on the browser)

DirectoryIndex index.html index.html.var # is modified to: DirectoryIndex index.html index.htm Default.html Default.htm index.php Default.php index.html.var at line 402 (set the default home file and add index.php)

KeepAlive Off # was modified at line 76 to: KeepAlive On (programmatic online allowed)

At line 83, MaxKeepAliveRequests 100 # is modified to: MaxKeepAliveRequests 1000 (increase the number of simultaneous connections)

: wq! # Save exit

Or modify by command

[root@localhost] # sed-I 's/ServerTokens OS/ServerTokens Prod/g' / etc/httpd/conf/httpd.conf

[root@localhost] # sed-I 's/ServerSignature On/ServerSignature Off/g' / etc/httpd/conf/httpd.conf

[root@localhost ~] # / etc/init.d/httpd restart # restart

[root@localhost ~] # rm-f / etc/httpd/conf.d/welcome.conf / var/www/error/noindex.html # Delete the default test page

2. Php configuration

[root@localhost ~] # vim / etc/php.ini # Editor

Date.timezone = PRC # remove the previous semicolon on line 946 and change it to date.timezone = PRC

Disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin Posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname

# list the functions that can be disabled by PHP on line 386. If some programs need to use this function, you can delete it and undisable it.

Expose_php = Off # suppresses the display of php version information on line 432

Magic_quotes_gpc = On # Open magic_quotes_gpc at line 745 to prevent SQL injection

Short_open_tag = ON # supports php short tags on line 229th

Open_basedir =.: / tmp/ # setting at line 380 allows access to the current directory (that is, the directory where the PHP script files are located) and the / tmp/ directory, which can prevent the php Trojan from crossing the site. if there is a problem with the installer after the change, you can log out of this line or write directly to the program's directory / data/www.osyunwei.com/:/tmp/

: wq! # Save exit

Or

[root@localhost ~] # sed-I'/ expose_php/ {s/On/Off/g}'/ etc/php.ini

[root@localhost ~] # / etc/init.d/mysqld restart # restart MySql

[root@localhost ~] # / etc/init.d/httpd restart # restart Apche

Test piece

[root@localhost ~] # cd / var/www/html

[root@localhost ~] # vim index.php # Edit and enter the following

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report