Master Operator: Set up productive HTTP environment on CentOS 8 (NGINX+PHP+MySQL)
This article is an updated version of Master Operator: Set up productive HTTP environment on CentOS 7 (NGINX+PHP+MySQL)
1.Installing NGINX
You know how it is. Install the compile tools, then dependencies. Download the source pack, unzip, configure, make and install then add to the system startup.
Tools and dependencies
yum -y install gcc gcc-c++ autoconf automake zlib zlib-devel openssl openssl-devel pcre-devel make
Add user and group
sudo groupadd -r nginx
sudo useradd -s /sbin/nologin -g nginx -r nginx
Download source pack and extract the files
In my days, you are expected to get the latest version here: http://nginx.org/en/download.html
And then download the distribution like this:
wget http://nginx.org/download/nginx-1.13.11.tar.gz
Then you get a .tar.gz zipped file.
Run tar xzvf nginx-1.13.11.tar.gz && cd nginx-1.13.11
to extract the binary files then enter the folder.
Configure, make and make install
./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --with-http_ssl_module --with-http_gzip_static_module --with-http_v2_module
Remember to make && make install
Add to the startup
Save the configuration below into /lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Remember to execute systemctl enable nginx
to enable the autostart.
2.Installing PHP7
Run the following command to install the dependencies of PHP:
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm
yum install epel-release -y
Install Tools and dependencies
yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel libc-client-devel sqlite-devel.x86_64 libzip-devel
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
ldconfig -v
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.
ln -s /usr/lib64/libc-client.so /usr/lib/libc-client.so
Download source pack and unzip
In my days, you are expected to get the latest version here: http://php.net/downloads.php
And then use some command similar to this:
wget http://us2.php.net/distributions/php-7.3.6.tar.gz
Then you get a .tar.gz zipped file.
Run tar xzvf php-7.3.6.tar.gz && cd php-7.3.6.tar.gz
to extract the binary files then enter the folder.
Choose your PHP version wisely. You may need some libraries and features which requires a specific version of PHP.
Configure, make and make install
go into the folder of your PHP
./configure \
--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-fpm \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-libxml-dir \
--with-xmlrpc \
--with-openssl \
--with-mhash \
--with-pcre-regex \
--with-sqlite3 \
--with-zlib \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--with-cdb \
--enable-dom \
--enable-exif \
--enable-fileinfo \
--enable-filter \
--with-pcre-dir \
--enable-ftp \
--with-gd \
--with-openssl-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib-dir \
--with-freetype-dir \
--enable-gd-jis-conv \
--with-gettext \
--with-gmp \
--with-mhash \
--enable-json \
--enable-mbstring \
--enable-mbregex \
--enable-mbregex-backtrack \
--with-onig \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-zlib-dir \
--with-pdo-sqlite \
--with-readline \
--enable-session \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-wddx \
--with-libxml-dir \
--with-xsl \
--enable-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-opcache \
--with-imap=imap \
--with-kerberos \
--with-imap-ssl
Remember to run make && make install
after you got things done right.
Then vi /etc/profile and add the text below to the bottom of this file.
PATH=$PATH:/usr/local/php/bin export PATH
source /etc/profile
will make the changes take effect instantly.
Add to the start up
cp php.ini-production /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/sbin/php-fpm
chmod +x /usr/local/sbin/php-fpm
and edit or create /lib/systemd/system/php-fpm.service with following content
[Unit]
Description=PHP FastCGI process manager
After=local-fs.target network.target nginx.service
[Service]
PIDFile=/run/php/php-fpm.pid
ExecStartPre=/bin/mkdir --parents /run/php
ExecStart=/usr/local/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
Type=simple
[Install]
WantedBy=multi-user.target
Remember to execute systemctl enable php-fpm
to enable the autostart.
3.Install MySQL
Easiest one as you can do it with yum install
Install/Update the yum repo
Go to https://dev.mysql.com/downloads/repo/yum/ and check the latest version of the yum repo of your OS version.
Just like the one above.
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
md5sum mysql57-community-release-el7-11.noarch.rpm
If the MD5 matches, go on. If not, retry downloading.
sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
sudo yum install mysql-server
When things are done, set the automatic startup and configure the MySQL for using:
systemctl start mysqld
systemctl enable mysqld
systemctl status mysqld
# No longer needed in the latest release.
# No default password for root anymore
grep 'temporary password' /var/log/mysqld.log
sudo mysql_secure_installation