In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to build LAMP under Linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.
LAMP (Linux-Apache-MySQL-PHP) website architecture is a popular international Web framework, which includes Linux operating system, Apache network server, MySQL database, Perl, PHP or Python programming language. all the products are open source software, which is a mature architecture framework in the world. Many popular commercial applications adopt this framework.
Preparatory work
System environment: centos 6.8 x86x64
[root@localhost ~] # uname-aLinux localhost.localdomain 2.6.32-642.el6.x86_64 # 1 SMP Tue May 10 17:27:01 UTC 2016 x86 "64 GNU/Linux [root@localhost] # cat / etc/redhat-releaseCentOS release 6.8 (Final) [root@localhost ~] #
Whether to install LAMP-related packages: httpd has been installed by default. Here we explain: in this experiment, we use yum to install. Httpd is the package name of Apache software in RPM.
[root@localhost] # rpm-qa httpdhttpd-2.2.15-53.el6.centos.x86_64 [root@localhost ~] # rpm-qa mysql* [root@localhost ~] # rpm-qa php* [root@localhost ~] # L-A-M-P installation
The installation of LAMP is actually very simple, with one command. Personally, I think it is not necessary for beginners to do so many plug-ins; after an in-depth understanding of LAMP, according to their own actual needs to install the module, from easy to difficult, step by step learning.
Inspection of yum warehouse
[root@localhost ~] # yum repolist\\ View the yum warehouse Loaded plugins: fastestmirror, refresh-packagekit SecurityLoading mirror speeds from cached hostfile* base: mirrors.cn99.com* extras: mirrors.cn99.com* updates: mirrors.aliyun.combase | 3.7 kB 00:00 extras | 3.4 kB 00:00 updates | | 3.4 kB 00:00 repo id repo name statusbase CentOS-6-Base 6696extras CentOS- | 6-Extras 62updates CentOS-6-Updates 482repolist: 7240
We are using centos's default network yum repository. Of course, if the default yum repository is slow, we can use epel's software package.
Yum install LAMP
[root@localhost ~] # yum-y install httpd mysql mysql-server mysql-devel php*Loaded plugins: fastestmirror, refresh-packagekit SecuritySetting up Install ProcessLoading mirror speeds from cached hostfile* base: mirrors.cn99.com* extras: mirrors.cn99.com* updates: mirrors.aliyun.comResolving Dependencies-- > Running transaction check--- > Package httpd.x86_64 0vir 2.2.15-53.el6.centos will be updated--- > Package httpd.x86_64 0vir 2.2.15-54.el6.centos will be an update-- > Processing Dependency: httpd-tools = 2.2.15-54.el6.centos for package: httpd-2 .2.15-54.el6.centos.x86x86x86x86x86mm 64muri-> Package mysql.x86_64 0VOV 5.1.73-7.el6 will be installed..Installed: mysql.x86_64 0Rose 5.1.73-7.el6 mysql-devel.x86_64 0Rose 5.1.73-7.el6 mysql-server.x86_64 0Rose 5.1.73-7.el6 Php.x86_64 0rime 5.3.3-48.el6_8 php-bcmath.x86_64 0vir 5.3.3-48.el6_8 php-cli.x86_64 0vir 5.3.3-48.el6_8 .Updated: httpd.x86_64 0rig 2.2.15-54.el6.centos Dependency Updated: httpd-tools.x86_64 0vl 2.2.15-54.el6.centos net-snmp-libs.x86_64 1vig 5.5-57.el6_8.1 openssl.x86_64 0:1.0.1e-48.el6_8.1Complete!
We yum commands to install httpd, install mysql mysql-server and mysql-devel development packages, in the php installation package above we chose the php* command to match the php-related packages. Note that the operation is to let the beginner children's shoes first understand the scheme of LAMP, and after in-depth understanding, they still have to follow up the actual situation to install the packages needed for search.
LAMP initialization
After installing the LAMP, we need to initialize the LAMP, that is, start the service, boot and configure the necessary configuration.
Initialization of Apache
[root@localhost ~] # service httpd start\\ start the httpd service; pay attention to the relationship between httpd and apache Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName [OK] [root@localhost ~] # chkconfig httpd on\\ set httpd launcher
Initialization of mysql
[root@localhost ~] # service mysqld start\\ start the mysql service, you will be prompted to initialize it. Very detailed Initializing MySQL database: Installing MySQL system tables...OKFilling help tables...OKTo start mysqld at boot time you have to copysupport-files/mysql.server to the right place for your systemPLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER! To do so, start the server Then issue the following commands:/usr/bin/mysqladmin-u root password' new-password'/usr/bin/mysqladmin-u root-h localhost.localdomain password' new-password'Alternatively you can run:/usr/bin/mysql_secure_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. This isstrongly recommended for production servers.See the manual for more instructions.You can start the MySQL daemon with:cd / usr; / usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.plcd / usr/mysql-test; perl mysql-test-run.plPlease report any problems with the / usr/bin/mysqlbug script! [OK] Starting mysqld: [OK] [root@localhost ~] # chkconfig mysqld on\\ set mysql to boot automatically [root@localhost ~] # mysqladmin-u root password linuxprobe.com\\ initialize mysql. Here you need to set the password of the root of mysql. Command: mysqladmin-u user password password [root@localhost ~] # mysql-u root-p\\ login mysql to see if you can log in to Enter password:Welcome to the MySQL monitor. Commands end with; or\ g.Your MySQL connection id is 3Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or'\ h' for help. Type'\ c' to clear the current input statement.mysql >\\ ok login succeeded
Note: when yum installs lamp, php is just an integrated component of apache. There is no need to add module applications, just enable it in the configuration file.
Simple testing of the environment
Check to see if regular mysql and httpd are running:
[root@localhost ~] # ps-aux | grep httpd\\ View the httpd process Warning: bad syntax, perhaps a bogus'-'? See / usr/share/doc/procps-3.2.8/FAQroot 2930 0.0 2.9 487660 14664? Ss 10:46 0:00 / usr/sbin/httpdapache 2933 0.0 1.9 487660 9400? S 10:46 0:00 / usr/sbin/httpdapache 2934 0.0 1.8 487660 9112? S 10:46 0:00 / usr/sbin/httpdapache 2935 0.0 1.9 487660 9400? S 10:46 0:00 / usr/sbin/httpdapache 2936 0.0 1.9 487660 9392? S 10:46 0:00 / usr/sbin/httpdapache 2937 0.0 1.8 487660 9116? S 10:46 0:00 / usr/sbin/httpdapache 2938 0.0 1.8 487660 9136? S 10:46 0:00 / usr/sbin/httpdapache 2939 0.0 1.8 487660 9112? S 10:46 0:00 / usr/sbin/httpdapache 2940 0.0 2.3 487844 11840? S 10:46 0:00 / usr/sbin/httpdroot 10163 0.0 0.1 103316 868 pts/3 S+ 12:23 0:00 grep httpd [root@localhost ~] # ps-aux | grep mysql\\ View mysql related processes Warning: bad syntax, perhaps a bogus'-'? See / usr/share/doc/procps-3.2.8/FAQroot 3035 0.0 0.2 108216 1452 pts/1 S 10:47 0:00 / bin/sh / usr/bin/mysqld_safe-- datadir=/var/lib/mysql-- socket=/var/lib/mysql/mysql.sock-- pid-file=/var/run/mysqld/mysqld.pid-- basedir=/usr-- user=mysqlmysql 3137 0.04.3 367512 21444 pts/1 Sl 10:47 0 : 02 / usr/libexec/mysqld-- basedir=/usr-- datadir=/var/lib/mysql-- user=mysql-- log-error=/var/log/mysqld.log-- pid-file=/var/run/mysqld/mysqld.pid-- socket=/var/lib/mysql/mysql.sockroot 10165 0.00.1 103316 868 pts/3 S+ 12:23 0:00 grep mysql [root@localhost ~] # netstat-tanulp | grep 80\\ View httpd port external listening Tcp 0 0 192.168.1.108 tcp 50878 63.80.4.177 tcp 80 ESTABLISHED 2629/clock-applet tcp 0: 80: * LISTEN 2930/httpd [root@localhost ~] # netstat-tanulp | grep 3306\\ View the port of mysql for external listening tcp 0 0 0 LISTEN 3137/mysqld 3306 0 0 0
Relevant settings of the firewall
[root@localhost ~] # iptables-L\\ View iptables rules Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all-- anywhere anywhere state RELATED ESTABLISHEDACCEPT icmp--anywhere anywhere ACCEPT all-anywhere anywhere ACCEPT tcp-anywhere anywhere state NEW tcp dpt:sshREJECT all-anywhere anywhere reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT) target prot opt source destination REJECT All-- anywhere anywhere reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT) target prot opt source destination [root@localhost ~] # iptables-I INPUT 1-p tcp-- dport 80-j ACCEPT\\ the first rule of the chain that adds iptables INPUT allows port 80 of the tcp protocol \\ more settings about iptables Please refer to the relevant content of "linux should learn this way" [root@localhost ~] # service iptables save\\ save our added rules in the configuration file iptables: Saving firewall rules to / etc/sysconfig/iptables: [OK] [root@localhost ~] # iptables-L\\ to view the Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT Tcp-anywhere anywhere tcp dpt:httpACCEPT all-anywhere anywhere state RELATED ESTABLISHEDACCEPT icmp--anywhere anywhere ACCEPT all-anywhere anywhere ACCEPT tcp-anywhere anywhere state NEW tcp dpt:sshREJECT all-anywhere anywhere reject-with icmp-host-prohibitedChain FORWARD (policy ACCEPT) target prot opt source destination REJECT All-anywhere anywhere reject-with icmp-host-prohibitedChain OUTPUT (policy ACCEPT) target prot opt source destination
Test the static file of httpd
Add a static index.html page for testing, or use the default page for testing. For more questions about adding web pages, please refer to "this is how linux should learn"
[root@localhost ~] # echo "hello word" > / var/www/html/index.html
Test the static page with an ie browser:
Novice must see, old bird detour-LAMP easy installation novice must see, old bird detour-LAMP easy installation
Ok, the test succeeded.
Configuration file [root@localhost ~] # ls / etc/httpd/\\ configuration file directory Related configuration module conf/ conf.d/ logs/ modules/ run/ [root@localhost ~] # vi / etc/httpd/conf/httpd.conf magic [root@localhost ~] # vi / etc/httpd/conf/httpd.conf\\ master configuration file [root@localhost ~] # wc-l / etc/httpd/conf/httpd.conf 1009 / etc/httpd/conf/httpd.conf\\ the master configuration file has 1009 lines Many of them are annotated. Form good habits Back up the default configuration file [root@localhost ~] # tail / etc/httpd/conf/httpd.conf\\ more configuration suggestions refer to "linux should learn this" related content # The first VirtualHost section is used for requests without a known# server name.##\\ configuration file add virtual host statement # ServerAdmin webmaster@dummy-host.example.com# DocumentRoot / www/docs/dummy-host.example.com# ServerName dummy-host.example.com# ErrorLog logs/dummy-host.example.com-error_log# CustomLog logs/dummy-host.example.com-access_log common#
Testing of advanced environment
LAMP is a stable and dynamic website architecture solution, here we need to add php support to test dynamic websites.
Enable support for php
[root@localhost ~] # vi / etc/httpd/conf/httpd.conf [root@localhost ~] # cat / etc/httpd/conf/httpd.conf | grep DirectoryIndex\\ adds support for php page in line 402 of configuration file # DirectoryIndex: sets the file that Apache will serve if a directory
Add php test page, test
[root@localhost ~] # vi / var/www/html/index.php [root@localhost ~] # cat / var/www/html/index.php\\ Test page that adds php information [root@localhost ~] # vi / var/www/html/test.php [root@localhost ~] # cat / var/www/html/test.php\\ add php page Test testthis php test
Test:
Novice must see, old bird detour-LAMP easy installation novice must see, old bird detour-LAMP easy installation
❝
Note: dynamic web page building dynamic family forum process briefly, everyone tests Apache:httpd (service name) 80 (port) Mysql: mysqld (service name) 3306 (port, default is only for local monitoring) php: integrated in apache, only need to add php default documents enabled lamp log and other functions, it is recommended to check the relevant documents recommended to install lamp in order to make it easier to understand lamp The production environment should install impassable components according to the actual situation.
LAMP,so easy!!!
Thank you for reading this article carefully. I hope the article "how to build LAMP under Linux" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.