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

Source code installs LAMP environment + yii2 framework

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

When some new software versions appear and you want to try it, but local installation with yum does not meet your needs, then my friend, you need to use source code installation as I do to achieve your goal.

Because the developer colleagues want an environment of Apache 2.4.25 + Mysql 5.7.17 + php7.1.5 + yii2-basic to do activities.

In order to meet the application requirements, let's start to do it now!

First, install Apache

Originally, as long as you can connect to the Internet, you can easily install Apache with yum, and the installed version will be better than that on the official website.

The latest source package downloaded is still new.

But I found that the Apache installed by yum could not meet some of my later needs, mostly because of my failure.

So I chose to install the source code directly.

Of course, friends who have had source code installation must also know that there will be dependent libraries to install first, otherwise they will prompt which dependent libraries can not be found during source code installation, resulting in not being installed.

It is very simple to install the dependent package of Apache: zlib zlib-devel pcre-devel pcre apr apr-util

Before installing apache in the source code, we need to uninstall the apache that is already installed on the system through the rpm package. As follows:

First find out the rpm package loaded with httpd.

Rpm-qa | grep httpd

Uninstall the installed httpd-related rpm package by instruction

Rpm-e-nodeps httpd-2.4.6-1.el7.centos.x86_64rpm-e-nodeps httpd-tools-2.4.6-1.el7.centos.x86_64

I install dependency packages using yum to facilitate installation, but two dependency packages (apr and apr-util) can't find the class library when Apache compiles, so I have to install it again in the form of source code installation.

Installation packages for these two dependent libraries can be found at http://apr.apache.org/download.cgi

Http://mirrors.noc.im/apache//apr/apr-1.5.2.tar.gz

Http://mirrors.noc.im/apache//apr/apr-util-1.5.4.tar.gz

Then extract it in the system directory and install it (be sure to install gcc-c++ or use yum install gcc-c++ make if make is not installed)

Tar-xf apr-1.5.2.tar.gz cd apr-1.5.2. / configure-- prefix=/data0/apr/ make & & make install tar-xf apr-util-1.5.4.tar.gz cd apr-util-1.5.4. / configure-- prefix=/data0/apr-util-- with-apr=/data0/apr/ make & & make install

All right, at this point, you can start installing Apache

First go to the Apache website to download the version you want, http://httpd.apache.org/download.cgi, the latest stable version 2.4.25.

Decompress after download

Tar-xf httpd-2.4.25.tar.gz

Enter the unzipped directory

Cd httpd-2.4.25

You can install the configuration according to your own needs and use. / configure-- help to view

After seeing which parameters to configure for the installation, we will begin to configure the parameters and check

. / configure\-- prefix=/data0/apache/\-- with-apr=/data0/apr/\-- with-apr-util=/data0/apr-util/\-- enable-so\-- enbale-deflate=shared\-- enbale-expires=shared\-- enable-rewrite=shared\-- enable-static-support

If there is no error prompt, then start compiling and installing

Make & & make install

After the installation, go to the installation directory and turn on the Apache service

Cd / data0/apache/bin/./apachectl start

An error may be reported:

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

It doesn't matter, it can be solved:

Vim / data0/apache/conf/httpd.conf## adds a line of ServerName localhost

After modifying the configuration file, restart the service to make it effective: visit http://IP with a browser to see if it works appears!

At this point, it can be said that Apache has been installed.

Copy the startup script of apache to the / etc/rc.d/init.d directory

Cp / data0/apache/bin/apachectl / etc/init.d/httpd

In fact, the startup of apache is to call the command / data0/apache/bin/httpd to view the contents of the script, as follows:

Cat / etc/init.d/httpd | grep-v ^ # | grep-v ^ $ACMD= "$1" ARGV= "$@" HTTPD='/data0/apache//bin/httpd'if test-f / data0/apache//bin/envvars; then. / data0/apache//bin/envvarsfiLYNX= "lynx-dump" STATUSURL= "http://localhost:80/server-status"ULIMIT_MAX_FILES="ulimit-S-n `ulimit-H-n`" if ["x$ULIMIT_MAX_FILES"! = "x"]; then $ULIMIT_MAX_FILESfiERROR=0if ["x$ARGV" = "x"]; then ARGV= "- h" ficase $ACMD instart | stop | restart | graceful | graceful-stop) $HTTPD-k $ARGV ERROR=$?; startssl | sslstart | start-SSL) echo The startssl option is no longer supported. Echo Please edit httpd.conf to include the SSL configuration settings echo and then use "apachectl start". ERROR=2;; configtest) $HTTPD-t ERROR=$?;; status) $LYNX $STATUSURL | awk'/ process$/ {print; exit} {print}'; fullstatus) $LYNX $STATUSURL;; *) $HTTPD "$@" ERROR=$?esacexit $ERROR

Start apache as follows:

/ etc/init.d/httpd startnetstat-lntp | grep 80lsof-I: 80

You can also start with / data0/apache/bin/httpd. As follows:

/ data0/apache/bin/httpd-k start

Bin mainly stores the program command directory.

Conf mainly stores apache configuration files.

Htdocs mainly stores site directories.

Logs mainly stores default log files.

Modules mainly stores the running module of apache. For example, the compiled modules of php and memcache are stored here.

II. MySQL source code installation

All right, let's get started with the MySQL installation.

1. Install according to the package before installation

Yum-y install gcc gcc-c++ ncurses ncurses-devel cmake bison bison-devel openssl openssl-devel pcre pcre-devel

two。 Download the source package

2.1it is recommended to download http://dev.mysql.com/downloads/mysql/ from the official website and choose "Source Code". In the process of downloading, you need to sign up for an Oracle account. If you have a direct login, it is good.

2.2 provide a download address: http://101.96.10.47/dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.17.tar.gz

Or https://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz.

The boost library has been added to the new version of the source code. If you do not need to download this library in the source code, otherwise an error will be reported, so you need to click below.

3. New MySQL users and user groups

Groupadd-r mysqluseradd-r-g mysql mysql

4. Enter the installation step

Tar-zvxf mysql-boost-5.7.17.tar.gzcd mysql-5.7.17

Create a new MySQL database data file directory

Mkdir-p / www/mysql-datamkdir-p / www/mysql-logsmkdir-p / www/mysql-temp

Make an edit

Cmake-DCMAKE_INSTALL_PREFIX=/www/mysql\-DMYSQL_DATADIR=/www/mysql-data\-DMYSQL_UNIX_ADDR=/www/mysql/mysql.sock\-DWITH_BOOST=/www/boost_1_59_0\-DSYSCONFDIR=/etc\-DWITH_INNOBASE_STORAGE_ENGINE=1\-DWITH_PARTITION_STORAGE_ENGINE=1\-DWITH_FEDERATED_STORAGE_ENGINE=1\-DWITH_BLACKHOLE_STORAGE_ENGINE=1\-DWITH_MYISAM_STORAGE_ENGINE=1\-DENABLED_LOCAL_INFILE=1\-DENABLE_DTRACE=0\-DDEFAULT_CHARSET=utf8mb4 \-DDEFAULT_COLLATION=utf8mb4_general_ci\-DWITH_EMBEDDED_SERVER=1

The above configuration explains:

-DCMAKE_INSTALL_PREFIX=/www/mysql / / set installation directory-DMYSQL_DATADIR=/www/mysql/data / / set database storage directory-DMYSQL_UNIX_ADDR=/www/mysql/mysql.sock / / set UNIX socket directory-DDEFAULT_CHARSET=utf8mb4 / / set default character set-DDEFAULT_COLLATION=utf8mb4_general_ci / / set default proofreading rules-DWITH_INNOBASE_STORAGE_ENGINE=1 / / Add InnoDB engine support-DSYSCONFDIR=/etc / / sets the directory where the my.cnf configuration file is located The default is the installation directory. If available, you can add a copy here later.

For editing and installation

Make & & make install

# clean up the 00:00 file after the installation is complete

Make clean

Set the startup script to boot (that is, make mysql as a service)

# copy the executable file to the specified directory and change the name to mysqld

Cp / www/mysql/support-files/mysql.server / etc/init.d/mysqld

# Grant executable permissions

Chmod + x / etc/init.d/mysqld

# set to boot

Systemctl enable mysqld

Modify the executable directory of mysql

Chown-Rf mysql:mysql / www/mysqlchown-Rf mysql:mysql / www/mysql-datachown-Rf mysql:mysql / www/mysql-logschown-Rf mysql:mysql / www/mysql-temp

The configuration file modifies / etc/my.cnf

# reference. For more information on the parameters, please search by yourself.

[mysqld] character-set-server = utf8mb4collation-server = utf8mb4_general_ciskip-external-lockingskip-name-resolveuser = mysqlport = 3306basedir = / www/mysqldatadir = / www/mysql-datatmpdir = / www/mysql-temp# server_id = .socket = / www/mysql/mysql.socklog-error = / www/mysql-logs/mysql_error.logpid-file = / www/mysql-data/mysql.pidopen_files_limit = 10240back_log = 600max_connections=500max_connect_errors = 6000 waitworthy timeoutflows 605800 open_ Tables = 600#table_cache = 650#opened_tables = 630max_allowed_packet = 32Msort_buffer_size = 4Mjoin_buffer_size = 4Mthread_cache_size = 300query_cache_type = 1query_cache_size = 256Mquery_cache_limit = 2Mquery_cache_min_res_unit = 16ktmp_table_size = 256Mmax_heap_table_size = 256Mkey_buffer_size = 256Mread_buffer_size = 1Mread_rnd_buffer_size = 16Mbulk_insert_buffer_size = 64M### (non-distinguishing size setting Fixed) lower_case_table_names=1default-storage-engine = INNODBinnodb_buffer_pool_size = 1Ginnodb_log_buffer_size = 32Minnodb_log_file_size = 128Minnodb_flush_method = Olympiad longevity querytimetime.log [mysqldump] quickmax_allowed_packet = 32Mcharacter_set_server = UTF8 [mysqld _ safe] Log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pidcharacter_set_server = utf8 codes: the above character_set_server = utf8 is used to solve the number problem

Add environment variabl

Add the following at the end of vi / etc/profile#: # mysql envexport PATH=$PATH:/www/mysql/bin:/www/mysql/lib

Make the configuration file effective

Source / etc/profile

Initialize the database

Mysqld-initialize-insecure-user=mysql-basedir=/www/mysql-datadir=/www/mysql-data

Note:

Previous versions of MySQL, mysql_install_db, are under mysql_basedir/script.

MySQL 5.7is placed directly under the mysql_install_db/bin directory.

"- initialize" has been discarded, generate a random password (~ / .mysql_secret)

"- initialize-insecure" does not generate a password

There can be no data files in the "- datadir" directory

Or use the following sentences:

Mysql_install_db-user=mysql-basedir=/www/mysql-datadir=/www/mysql-data

Start the database

Systemctl start mysqld

View database status

Systemctl status mysqld

View mysql service processes and ports

Ps-ef | grep mysqlnetstat-tunpl | grep 3306

Set the database root user password

MySQL is the same as the Oracle database, which comes with a root user by default (this is the same as the

Root users are completely irrelevant), we initialize the password of the root user after setting up the security configuration of the MySQL database.

During the preparation process, just type y all the way. This only shows that in the MySQL5.7.17 version, the user's password policy is divided into low-level ones.

There are three kinds of LOW, medium MEDIUM and super STRONG. Medium MEDIUM level is recommended! Of course, you don't have to wait.

Level setting

After consulting the official documents, it is found that there are three password policies:

Policy test implementation

0-LOW length

1-MEDIUM length; numbers, lowercase / uppercase and special characters

2-STRONG length; numbers, lowercase / uppercase and special characters; dictionary files

License: future usage related secrets will need to be implemented in accordance with this standard, but relevant modifications can also be made.

Mysql_secure_installation

Except

Disallow root login remotely

Remove test database and accesss to it can be n

Everything else is y.

Enter the database

Mysql-uroot-p password

"build other uses"

Mysql > create user 'hua'@'localhost' identified by' hlj123';## (can be modified later)

Set up the storage engine

Mysql > set storage_engine=INNODB

Build database

Mysql > create database zgz character set utf8

Check to see if the establishment is successful

Mysql > show databases

Permission to use related database permissions

Mysql > GRANT ALL PRIVILEGES ON *. * TO 'root'@'10.60.0.117' IDENTIFIED BY' Fnn@88' WITH GRANT OPTION;mysql > flush privileges

Check whether the database permission is enabled for the number of connections.

Mysql-h 10.60.0.117-uroot-pFnn@88 zgz

If the database entry is successful, otherwise restart the mysql service and try again

If the server is allowed to access the related database through any server

Mysql > GRANT ALL PRIVILEGES ON databasename.tables TO 'root'@'%' IDENTIFIED BY' Fnn@88' WITH GRANT OPTION;mysql > flush privileges

Find out the number of databases you need

Mysqldump-h 10.157.136.134-uroot-proot-- events-- ignore-table=mysql.event-- default-character-set=UTF8 jspxcms > zgz.sql

Create an empty number in advance to store the data that needs to be imported, and then you only need to execute the database boot command

Mysql > use zgz;mysql > source / root/zgz.sql;## (this is where you put the zgz.sql)

Determine whether the data table is created successfully, that is, whether the data file is imported successfully

Mysql > show tables

When you need to check the pre-password policy, you can do the following:

Mysql > show VARIABLES like "% password%" +-+-+ | Variable_name | Value | |-+- -| | default_password_lifetime | 0 | disconnect_on_expired_password | ON | | log_builtin_as_identified_by_password | OFF | | mysql_native_password_proxy_users | OFF | | old_passwords | 0 | report_password | | sha256_password_proxy_users | OFF | | validate_password_dictionary_file | | validate_password_length | 8 | | validate_password_ | Mixed_case_count | 1 | validate_password_number_count | 1 | | validate_password_policy | MEDIUM | | validate_password_special_char_count | 1 | +-+-+ 13 rows in setTime: 0.030s

Modify the default password policy (of course, it is not recommended to change it to a lower security policy in the actual environment)

Mysql > set global validate_password_policy = 0

Validate_password_number_count specifies the length of the data in the password

Validate_password_special_char_count specifies the length of special characters in the password

Validate_password_mixed_case_count specifies the length of uppercase and lowercase letters in the password.

The default value of these parameters is 1, so the minimum value of validate_password_length is 4.

If you show that the value of the specified validate_password_length is less than 4, although it will not report an error

However, the value of validate_password_length will be set to 4.

Modify validate_password_number_count,validate_password_special_char_count

Any one of the values in validate_password_mixed_case_count, validate_password_length will be modified dynamically

In addition, the level of password policy can be set through the my.cnf profile

Vi / etc/ my.cnf[mysqld] validate_password_policy=2

When validate_password_policy sets mysql to start, if the password policy level is set to 3, then you need to specify a dictionary file

Of course, you can also close the validate_password plug-in through the my.cnf configuration file.

Just add a row

Validate_password = off

After editing the configuration file, restart the mysqld service to take effect.

Mysql > show VARIABLES like "validate_password%" +-+-+ | Variable_name | Value | |-+-| +-+-+ 0 rows in setTime: 0.008s

After you close the validate_password plug-in, you don't have some parameter variables for validate_password.

The new version of MySQL listens by default on the address family of IPv6. Change to listen on IPv4 address family

Modify my.cnf to add one line configuration: bind-address = 0.0.0.0

Just restart mysqld.

3. Php source code installation

Go to PHP website to download the latest version: the latest stable version of http://php.net/downloads.php is 7.1.5.

Again, install the dependency package first:

Yum install-y php-mcrypt libmcrypt libmcrypt-devel autoconf freetype gd jpegsrc libmcrypt libpng libpng-devel libjpeg libxml2 libxml2-devel zlib curl curl-devel

Decompress

Tar-xf php-7.1.15.tar.gzcd php-7.1.5./configure\-- prefix=/data0/php/\-- with-apxs2=/data0/apache/bin/apxs\-- enable-fpm\-- enable-mbstring\-- enable-mysqlnd\-- with-gd\-- with-curl\-- with-openssl\-with-mysqli=mysqlnd\-- with-pdo-mysql=mysqlnd\-- with-config-file-path=/data0/php/etc/

Check to see if there are any errors. If so, some dependent packages may not be installed. Just follow the prompts to install the dependent packages.

And then compile

Make & & make install

If you have an error, it may go wrong if you compile make several times without seeing it clearly.

Just go straight to it.

Make clean

Just clear off the residue, solve the problem of dependent package, and do make & & make install

After the compilation is completed, we copy the configuration files in the source package to the installation directory of PHP. There are two configurations in the source package.

Php.ini-development php.ini-production, just look at the name, one is the development environment, the other is the production environment.

We will copy the development environment here.

Cp-raf php.ini-development / data0/php/etc/php.ini

At this point, you will need to have Apache parse the PHP file, so set up the Apache configuration file:

Vim / data0/apache/conf/httpd.conf###add php Addtype application/x-httpd-php .php .phtml

Restart the Apache service

Httpd restart

Test whether php is installed successfully

Add the php file test.php under the / data0/apache/htdocs/ file directory of apache

Vi test.php

Visit http://IP/test.php in the browser and the data information of your installation will be displayed.

At this point, we can say that your new LAMP environment has been built successfully!

Add extensions to PHP

One thing that may be involved here is the addition of extensions to PHP, because the development environment may be an integrated environment, so the development colleagues are not very clear about it.

What extension modules are needed for their code. What are we going to do? In order to adapt to the developer's code environment, we need to open the extension module they need, otherwise there may be some problems when the application is running, and we have an obligation to do something in advance.

First of all, ask developers to use statements in their integrated environment.

Php-m

Then you also use php-m on your deployment environment

Add extensions according to the PHP modules provided by the developer.

Because the adding actions are all the same, just to take one example, install the openssl extension. Under your source code installation package ext, there will be an openssl directory to enter that directory.

First call the phpize that we have compiled

/ data0/php/bin/phpize

If there is a mistake,

Cannot find config.m4. Make sure that you run'/ data/php/bin/phpize' in the top level source directory of the module

Then copy the config0.m4 to config.m4.

Cp-raf config0.m4 config.m4

Execute again

/ data0/php/bin/phpize

Ah, now it's OK. When you're done, you'll find there are more files in it, including configure files. This is what we want.

. / configure\-with-php-config=/usr/local/php/bin/php-configmake & & make install

If an error occurs during such compilation, it is usually due to the lack of a dependency package, so just install the dependency package.

At this point, you will find .so files in your extension directory.

(if the extension directory is not specified, it is located in / data0/php/lib/php/extensions/no-debug-zts-xxx)

Then add the extension to php.ini

Vim / data0/php/etc/php.ini##addextension=/data0/php/lib/php/extensions/no-debug-zts-20160303/openssl.so

Then restart apache and visit test.php again and you will find that the extension is installed.

Fifth, build the yii2 environment

In fact, yii2-basic is installation-free.

Download http://www.yiiframework.com/download/yii2-basic directly from the official website and decompress it to your web directory

Tar-xf yii-basic-app-2.0.11.tgz

Modify the config/web.php file to add a key to the cookieValidationKey configuration item

Vim / data0/apache/htdocs/basic/config 'cookieValidationKey' = >' jfsbkjsbfdskjgfdskjbgfsdhjgfajds',## is filled in casually, if left empty, an error will be reported, and the official document also says that it cannot be left empty.

To facilitate browsing, change the default access path of apache to the frame directory of yii2!

The methods are as follows:

Vim / data0/apache/conf/httpd.conf## find DocumentRoot and change it to the path you want. DocumentRoot "/ data0/apache//htdocs/basic/web"

Open a browser to visit http://IP, and the following screen appears, indicating that you have installed it.

From the above steps, it is not very simple ah, , interested friends, you can also try!

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

Database

Wechat

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

12
Report