linux LAMP build

[root@lamp ~]# tar xf apr-1.6.5.tar.gz -C /usr/src/
[root@lamp ~]# tar xf apr-util-1.6.1.tar.gz -C /usr/src/
[root@lamp ~]# tar xf httpd-2.4.38.tar.gz -C /usr/src/
[root@lamp ~]# cd /usr/src/
[root@lamp src]# ls
apr-1.6.5  apr-util-1.6.1  debug  httpd-2.4.38  kernels
[root@lamp src]# mv  apr-1.6.5/   httpd-2.4.38/srclib/apr
[root@lamp src]# mv  apr-util-1.6.1/   httpd-2.4.38/srclib/apr-util

(3) Compile and install Apache

[root@lamp src]# cd httpd-2.4.38/
[root@lamp httpd-2.4.38]# ./configure --prefix=/usr/local/httpd --enable-charset-lite --enable-rewrite --enable-cgi --enable-so && make && make install

Module introduction:
mod_charset_lite specifies character set conversion or recoding
mod_rewrite provides a rule-based rewriting engine to dynamically rewrite the requested url
mod_cgi executes CGI script
mod_so loads executable code and modules to the server at startup or restart

Reference: http://httpd.apache.org/docs/2.4/mod/#C

(4) Optimize after installation,
modify the program user program group

[root@lamp ~]# useradd -M -s /sbin/nologin apache
[root@lamp ~]# chown -R apache.apache /usr/local/httpd/
[root@lamp ~]# sed -i 's/User daemon/User apache/' /usr/local/httpd/conf/httpd.conf
[root@lamp ~]# sed -i 's/Group daemon/Group apache/' /usr/local/httpd/conf/httpd.conf

Modify servername

[root@lamp ~]# sed -i '/#ServerName/ s/#//' /usr/local/httpd/conf/httpd.conf

Increase system command variable path

[root@lamp ~]# echo 'PATH=$PATH:/usr/local/httpd/bin/' >> /etc/profile
[root@lamp ~]# . /etc/profile

Create a startup script and set the startup to start automatically

[root@lamp ~]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
[root@lamp ~]# sed -i '1a# chkconfig: 35 85 15' /etc/init.d/httpd 
[root@lamp ~]# head -2 /etc/init.d/httpd 
#!/bin/sh
# chkconfig: 35 85 15
[root@lamp ~]# chkconfig --add httpd

[root@lamp ~]# chmod +x /etc/rc.d/rc.local 
[root@lamp ~]# echo "/etc/init.d/httpd start" >> /etc/rc.d/rc.local
启动服务测试
[root@lamp ~]# /etc/init.d/httpd start
[root@lamp ~]# netstat -anpt | grep :80
tcp6       0      0 :::80                   :::*                    LISTEN      64521/httpd  

[root@lamp ~]# curl 192.168.1.66
<html><body><h1>It works!</h1></body></html>

2. Install MySQL
(1) Install dependent packages

[root@lamp ~]# yum -y install cmake bison ncurses ncurses-devel autoconf openssl-devel

(2) Compile and install MySQL

[root@lamp ~]# useradd -M -s /sbin/nologin mysql
[root@lamp ~]# tar xf mysql-5.6.43.tar.gz -C /usr/src/
[root@lamp ~]# cd /usr/src/mysql-5.6.43/
[root@lamp mysql-5.6.43]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_TCP_PORT=3306 \
-DSYSCONFDIR=/etc \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_SSL=system \
-DINSTALL_SHAREDIR=share \

Options reference: https://dev.mysql.com/doc/refman/5.6/en/source-configuration-options.html

[root@lamp mysql-5.6.43]# make && make install

(3) Optimization after installation

[root@lamp mysql-5.6.43]# rm -f /etc/my.cnf
[root@lamp mysql-5.6.43]# pwd
/usr/src/mysql-5.6.43
[root@lamp mysql-5.6.43]# cp support-files/my-default.cnf /etc/my.cnf
[root@lamp mysql-5.6.43]# chown -R mysql.mysql /usr/local/mysql/

[root@lamp ~]# echo 'PATH=$PATH:/usr/local/mysql/bin/' >> /etc/profile
[root@lamp ~]# . /etc/profile

(4) Initialize the database

[root@lamp ~]# /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

(5) Add as a system service and set it to self-start after booting

[root@lamp ~]# cp /usr/src/mysql-5.6.43/support-files/mysql.server /etc/init.d/mysqld
[root@lamp ~]# chmod +x /etc/init.d/mysqld
[root@lamp ~]# chkconfig --add mysqld

(6) Simple security reinforcement

[root@lamp ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/lamp.err'.
 SUCCESS!
[root@lamp ~]# netstat -anpt | grep :3306
tcp6       0      0 :::3306                 :::*                    LISTEN      84304/mysqld  

[root@lamp ~]# mysql_secure_installation

Set a password
and select all y

Or just modify the mysql root password:

[root@lamp ~]# mysqladmin -uroot password "123123"

Login test

[root@lamp ~]# mysql -uroot -p
Enter password:

or:

[root@lamp ~]# mysql -uroot -p -h localhost -P 3306

3. Install PHP
(1) Install dependent packages

[root@lamp ~]# yum -y install libjpeg-devel libpng-devel freetype-devel libxml2-devel zlib-devel curl-devel libicu-devel openssl-devel 

(2) Install PHP from source code

[root@lamp ~]# tar xf php-7.3.2.tar.gz -C /usr/src/
[root@lamp ~]# cd /usr/src/php-7.3.2/
[root@lamp php-7.3.2]# ./configure  --prefix=/usr/local/php  --with-apxs2=/usr/local/httpd/bin/apxs  --with-mysql-sock=/tmp/mysql.sock  --with-pdo-mysql  --with-mysqli  --with-zlib  --with-curl  --with-gd  --with-jpeg-dir  --with-png-dir  --with-freetype-dir  --with-openssl  --enable-mbstring  --enable-xml  --enable-session  --enable-ftp  --enable-pdo  --enable-tokenizer  --enable-intl && make && make install

Create php.ini configuration file and configure database interface

[root@lamp php-7.3.2]# cp php.ini-development /usr/local/php/lib/php.ini
[root@lamp php-7.3.2]# vim /usr/local/php/lib/php.ini
1175 mysqli.default_socket = /tmp/mysql.sock

4. Configure Apache to parse PHP

[root@lamp ~]# vim /usr/local/httpd/conf/httpd.conf

……

258 <IfModule dir_module>
259     DirectoryIndex index.html index.php
260 </IfModule>
……
395     AddType application/x-compress .Z
396     AddType application/x-gzip .gz .tgz
397     AddType application/x-httpd-php .php
398     AddType application/x-httpd-php-source .phps
……
[root@lamp ~]# httpd -t
Syntax OK
[root@lamp ~]# /etc/init.d/httpd stop
[root@lamp ~]# /etc/init.d/httpd start

5. Write a test page test

[root@lamp ~]# vim /usr/local/httpd/htdocs/1.php
<?php
phpinfo();
?>

Guess you like

Origin blog.csdn.net/qq_39109226/article/details/111245576