сборка lamp из исходников
В этой статье постарался расписать более менее подробное руководство по компиляции LAMP на основе Apache, PHP, MySQL из исходников, в качетсве системы для сборки была использована CentOS.
Перед началом компиляции необходимо, устанавить пакеты которые понадобятся для сборки:
yum groupinstall "Development tools"
Далее собираем необходимые библиотеки, предварительно скачав и распаковав архивы с официальных сайтов:
pcre
./configure --prefix=/usr/local/pcre-8.33 make make install
zlib
./configure --prefix=/usr/local/zlib-1.2.8 make make install
bzip2
make install PREFIX=/usr/local/bzip2-1.0.6
libxml2
./configure --prefix=/usr/local/libxml2-2.9.0 make make install
curl
./configure --prefix=/usr/local/curl-7.33.0 make make install
openssl
./config --prefix=/usr/local/openssl-1.0.1e shared make make install
И приступаем к компиляции mysql, apache, php:
MySQL
Для сборки mysql, необходимо поставить необходимые зависимости:
Далее переходим в папку с исходным кодом и начинаем процесс компиляции, предварительно скачав и распаковав архив с официального сайта и поставив все необходимые зависимости:
CPPFLAGS="-I/usr/local/openssl-1.0.1e/include" LDFLAGS="-Wl,-rpath,/usr/local/zlib-1.2.8/lib -Wl,-rpath,/usr/local/openssl-1.0.1e/lib" ./configure --prefix=/usr/local/mysql-5.1.72 --with-zlib-dir=/usr/local/zlib-1.2.8 --with-ssl=/usr/local/openssl-1.0.1e --with-unix-socket-path=/var/lib/mysql/mysql.sock --datadir=/var/lib/mysql --with-collation=utf8_general_ci --with-charset=utf8 --with-plugins=innobase,innodb_plugin make make install
После установки, добавляем пользователя и группу:
groupadd mysql useradd -g mysql mysql
Делаем необходимые изменения в конфиге /etc/my.cnf, к примеру как я сделал себе:
[mysqld] port = 3306 datadir = /var/lib/mysql socket = /var/lib/mysql/mysql.sock user = mysql skip-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M # Disabling symolic-links is recommended to prever assorted security risks symbolic-links = 0 # Replication Master Server (default) # binary logging is required for replication log-bin = mysql-bin # binary logging format binlog_format = mixed server-id = 1 [mysqld_safe] log-error = /var/log/mysqld.log pid-file = /var/run/mysqld/mysqld.pid [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [client] port = 3306 socket = /var/lib/mysql/mysql.sock [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
Но если хотите можно использовать предлагаемую конфигурацию из папки с исходным кодом:
cp support-files/my-medium.cnf /etc/my.cnf
Далее переходим в папку с установленным mysql:
Устанавливаем базы данных:
bin/mysql_install_db --user=mysql
И исправляем права на них:
chown -R mysql /var/lib/mysql
Проверяем нашу установку запуском сервера:
Возможно будут проблемы при первом запуске, так как он может не создать pid файл в /var/run/mysqld директории, создаем:
mkdir /var/run/mysqld chown mysql /var/run/mysqld
И не забываем сменить пароль для пользователя root одним из способов:
bin/mysqladmin -u root password "new-password"
bin/mysql_secure_installation
Ну и пробуем зайти на сервер:
bin/mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.1.72-log Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
Так же есть возможность поставить init-скрипт для запуска сервера:
cp support-files/mysql.server /etc/init.d/mysql
Apache
Переходим в папку с исходным кодом и начинаем процесс компиляции, предварительно скачав и распаковав архив с официального сайта и поставив все необходимые зависимости:
LDFLAGS="-Wl,-rpath,/usr/local/pcre-8.33/lib -Wl,-rpath,/usr/local/zlib-1.2.8/lib -Wl,-rpath,/usr/local/openssl-1.0.1e/lib" ./configure --prefix=/usr/local/httpd-2.2.26 --with-pcre=/usr/local/pcre-8.33 --with-z=/usr/local/zlib-1.2.8 --with-ssl=/usr/local/openssl-1.0.1e --enable-deflate --enable-ssl --enable-info --enable-cgi --enable-vhost-alias --enable-rewrite --enable-so --enable-suexec make make install
PHP
Переходим в папку с исходным кодом и начинаем процесс компиляции, предварительно скачав и распаковав архив с официального сайта и поставив все необходимые зависимости:
./configure --prefix=/usr/local/php-5.5.6 --with-pcre-dir=/usr/local/pcre-8.33 --with-zlib-dir=/usr/local/zlib-1.2.8 --with-bz2=/usr/local/bzip2-1.0.6 --with-libxml-dir=/usr/local/libxml2-2.9.0 --with-openssl=/usr/local/openssl-1.0.1e --with-curl=/usr/local/curl-7.33.0 --with-mysql=/usr/local/mysql-5.1.72 --with-apxs2=/usr/local/httpd-2.2.26/bin/apxs --enable-calendar --enable-mbstring --enable-soap --enable-sockets make make install
Ну и чтобы связать php и apache, добавляем в /usr/local/httpd-2.2.26/conf/httpd.conf строку:
AddType application/x-httpd-php .php
/usr/local/httpd-2.2.26/bin/apachectl -k restart
Для проверки создадим файл index.php в /usr/local/httpd-2.2.26/htdocs со следующим содержимым:
Проверяем, открыв браузер или curl’ом перейдя по ссылке http://127.0.0.1/index.php у нас должна отобразиться информация о php.
Вот и все! Все в сборе и работает)
Хочу обратить внимание, что библиотеки и пути с флагами при компиляции могут варироваться в зависимости от потребностей.
How to build a MySQL on Linux quickly?
This article introduces how to build a MySQL on Linux quickly. This’s often used to build a temporary MySQL for testing. In short, we only need three steps: check, download package, install.
First of all, check the disk space and the memory:
These pictures are from my virtual machine(It’s very similar with a physical machine).
I will store the MySQL installation files on /usr/local/mysql80, and data files on /data/mysql8001. So look at the picture, the free space on ‘/’ is enough for me.
The remaining 2626 MB of memory is enough for me. In the production environment, you should evaluate the required memory size and the disk size。
Second, prepare related directories and files
Check out the version of Linux:
I download MySQL Community Server 8.0.12 this time, and you can also download a previous version by click the “Looking for previous GA versions?”
Choose mysql-8.0.12-linux-glibc2.12-x86_64.tar.xz to download(You can copy the download address or download to your computer and move to the server). Then click “Download”.
Also you can right click, choose “Copy link address“, then using wget COMMAND download it on your server:
After downloading, use the tar command to extract the package:
Third, Initialize MySQL service
We can find the mysqld binary file at ./bin, and for more help, using ./mysqld –verbose –help :
For a easy installation, we can just use few options:
. / mysqld — datadir = / data / mysql8001 — basedir = / usr / local / mysql80 — port = 8001 — initialize — user = root
2018-08-13T11:20:53.780874Z 0 [Warning] [MY-011070] [Server] ‘Disabling symbolic links using –skip-symbolic-links (or equivalent) is the default. Consider not using this option as it’ is deprecated and will be removed in a future release.
2018-08-13T11:20:53.780924Z 0 [Warning] [MY-010143] [Server] Ignoring user change to ‘root’ because the user was set to ‘mysql’ earlier on the command line
2018-08-13T11:20:53.780974Z 0 [System] [MY-013169] [Server] /usr/local/mysql80/bin/mysqld (mysqld 8.0.12) initializing of server in progress as process 6281
2018-08-13T11:20:59.265648Z 5 [Note] [MY-010454] [Server] A temporary password is generated for [email protected]: mqlbs9,&sDkC
2018-08-13T11:21:00.738834Z 0 [System] [MY-013170] [Server] /usr/local/mysql80/bin/mysqld (mysqld 8.0.12) initializing of server has completed
Then we get a temporary password from the above information.
After initializing, we should start the MySQL server:
. / mysqld_safe — datadir = / data / mysql8001 — basedir = / usr / local / mysql80 — port = 8001 — log — error = / tmp / 8001 — err . log — socket = / tmp / mysql8001 . sock — pid — file = / data / mysql8001 / mysql8001 . pid — user = root &
2018-08-13T11:23:30.977379Z mysqld_safe Logging to ‘/tmp/8001-err.log’.
2018-08-13T11:23:31.001444Z mysqld_safe Starting mysqld daemon with databases from /data/mysql8001
Log in to server using the MySQL client:
Jamp / build_mysql.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
#! /bin/bash |
# Run as root |
set -e |
apt-get update |
apt-get install -y build-essential |
apt-get install -y libncurses5-dev |
useradd mysql |
cd |
wget http://dev.mysql.com/get/Downloads/MySQL-5.1/mysql-5.1.73.tar.gz |
tar xzvf mysql-5.1.73.tar.gz |
cd mysql-5.1.73 |
./configure \ |
‘ —prefix=/usr ‘ \ |
‘ —exec-prefix=/usr ‘ \ |
‘ —libexecdir=/usr/sbin ‘ \ |
‘ —datadir=/usr/share ‘ \ |
‘ —localstatedir=/var/lib/mysql ‘ \ |
‘ —includedir=/usr/include ‘ \ |
‘ —infodir=/usr/share/info ‘ \ |
‘ —mandir=/usr/share/man ‘ \ |
‘ —with-system-type=debian-linux-gnu ‘ \ |
‘ —enable-shared ‘ \ |
‘ —enable-static ‘ \ |
‘ —enable-thread-safe-client ‘ \ |
‘ —enable-assembler ‘ \ |
‘ —enable-local-infile ‘ \ |
‘ —with-fast-mutexes ‘ \ |
‘ —with-big-tables ‘ \ |
‘ —with-unix-socket-path=/var/run/mysqld/mysqld.sock ‘ \ |
‘ —with-mysqld-user=mysql ‘ \ |
‘ —with-libwrap ‘ \ |
‘ —with-readline ‘ \ |
‘ —with-ssl ‘ \ |
‘ —without-docs ‘ \ |
‘ —with-extra-charsets=all ‘ \ |
‘ —with-plugins=max ‘ \ |
‘ —with-embedded-server ‘ \ |
‘ —with-embedded-privilege-control ‘ |
make |
make install |
mkdir -p /etc/mysql |
mkdir -p /var/lib/mysql |
mkdir -p /etc/mysql/conf.d |
echo -e ‘ [mysqld_safe]\nsyslog ‘ > /etc/mysql/conf.d/mysqld_safe_syslog.cnf |
cp /usr/share/mysql/my-medium.cnf /etc/mysql/my.cnf |
sed -i ‘ s#.*datadir.*#datadir = /var/lib/mysql#g ‘ /etc/mysql/my.cnf |
chown mysql:mysql -R /var/lib/mysql |
mysql_install_db —user=mysql |
mysqld_safe -user=mysql & |
/usr/bin/mysql_secure_installation |
cp /usr/share/mysql/mysql.server /etc/init.d/mysql |
chmod +x /etc/init.d/mysql |
update-rc.d mysql defaults |