Documents Product Categories LEMP Stack(Nginx PHP8.1 MariaDB10.6) on Ubuntu22.04

LEMP Stack(Nginx PHP8.1 MariaDB10.6) on Ubuntu22.04

Jun 28, 2024
OneinStack.com 《LEMP Image Guide》 LEMP Image Guide Date Version Description 7.15/2017 V1.2 Alibaba cloud Image doc V1.2 1.5/2017 V1.1 Alibaba cloud Image doc V1.1 11.25/2016 V1.0 Alibaba cloud Image doc V1.0 NOTE: By default, network access is turned off to a ECS instance. You can specify rules in a security group that allows access from an IP address range, port, or ECS security group. You must specify port numbers (for TCP): • 22 (ssh) • 80 (http) • 443 (https) • 21, 20000~30000 (ftp) Security groups document URL: https://www.alibabacloud.com/help/doc-detail/25475.htm https://oneinstack.comOneinStack.com 《LEMP Image Guide》 LEMP IMAGE GUIDE ........................................................................................................................... 1 1 IMAGE ENVIRONMENT DESCRIPTION ......................................................................................... 3 1.1 IMAGE VERSION DESCRIPTION .......................................................................................................... 3 1.2 APPLICATION INSTALLATION DIRECTORIES ........................................................................................... 4 1.3 HOW DO USE SCRIPTS TO OPTIMIZE THE PARAMETERS ........................................................................... 5 2 HOW TO CHANGE YOUR PHP VERSION ....................................................................................... 6 3 MIGRATING WEBSITE FROM OS DISK TO DATA DISK ................................................................... 7 4 MYSQL/MARIADB DATABASES MANAGEMENT .......................................................................... 8 4.1 DISPLAY DEFAULT MYSQL ROOT PASSWORD ....................................................................................... 8 4.2 CHANGE MYSQL ROOT PASSWORD .................................................................................................. 9 4.3 CREATE A MYSQL DATABASE ........................................................................................................ 10 4.4 DELETE A MYSQL DATABASE ........................................................................................................ 11 4.5 CREATE A DATABASE USER ............................................................................................................ 12 4.6 HOW TO SETUP A REMOTE MYSQL CONNECTION .............................................................................. 13 5 HOW TO MANAGE VIRTUAL HOST ............................................................................................ 15 5.1 HOW TO ADD A VIRTUAL HOST ....................................................................................................... 15 5.2 HOW TO DELETE A VIRTUAL HOST ................................................................................................... 17 6 HOW TO MANAGE FTP USER ACCOUNTS .................................................................................. 18 7 HOW TO BACKUP ..................................................................................................................... 19 8 HOW TO MANAGE SERVICE ...................................................................................................... 21 9 HOW TO UPGRADE................................................................................................................... 22 10 HOW TO ADD EXTENSIONS .................................................................................................. 23 11 HOW TO UNINSTALL ............................................................................................................. 24 12 MORE ................................................................................................................................... 25 12.1 HOW TO DEPLOY A WEBSITE ON A SERVER ........................................................................................ 25 12.2 ABOUT THE PHP OPCODE CACHE ................................................................................................... 27 12.3 PROPER PERMISSIONS FOR FILES/FOLDERS ........................................................................................ 29 12.4 ABOUT REDIS AND MEMCACHED ................................................................................................... 30 12.5 ABOUT IPTABLES FIREWALL ........................................................................................................... 31 https://oneinstack.comOneinStack.com 《LEMP Image Guide》 1 Image environment description 1.1 Image version description Software version:  Nginx1.12.0  PHP7.1.7,PHP7.0.21, PHP5.6.30, PHP5.5.38,PHP5.4.45,PHP5.3.29  MySQL5.6.36 or MariaDB10.1.25  Redis3.2.9  Memcached1.4.39  Jemalloc4.5.0  Pure-FTPd1.0.46  phpMyAdmin4.4.15.10 Image Feature: 1. Source compiler installation, download the latest and most stable version from the official, security optimization 2. Providing multiple PHP versions (PHP-7.1,PHP-7.0, PHP-5.6, PHP-5.5, PHP-5.4, PHP-5.3) 3. Jemalloc optimize Nginx,MySQL/MariaDB 4. Providing add a virtual host script, include Let''s Encrypt SSL certificate 5. Add ftp acount to nginx via the shell script menu 6. Provide Nginx,MySQL,PHP, Redis, Memcached,phpMyAdmin upgrade script 7. Provide local backup and remote backup (rsync between servers) 、 Alibaba cloud OSS backup(Intranet) script https://oneinstack.comOneinStack.com 《LEMP Image Guide》 1.2 Application Installation Directories Nginx install directory: /usr/local/nginx Database install directory: /usr/local/mysql or /usr/local/mariadb Database data directory: /data/mysql or /data/mariadb Database Configuration File: /etc/my.cnf PHP install directory: /usr/local/php PHP Configuration Path: /usr/local/php/etc PHP Configuration File: /usr/local/php/etc/php.ini PHP Additional .ini File: /usr/local/php/etc/php.d Memcached install directory: /usr/local/memcached Memcached Configuration File: /etc/init.d/memcached Redis install directory: /usr/local/redis Redis Configuration File: /usr/local/redis/etc/redis.conf Web Context document root: /data/wwwroot/default phpMyAdmin install directory: /data/wwwroot/default/phpMyAdmin Web logs directory: /data/wwwlogs Index demo url: http:// Opcache Control Panel url: http:///ocp.php phpmyadmin url: http:// /phpMyAdmin #Pay attention to upper and lower case, rename or delete for security advice PHP Proberv url: http:// / proberv.php The default ip direct access to the contents of the corresponding root directory:/data/wwwroot/default , This directory contains the home pagedemo,Opcache Control Panel,phpinfo,phpmyadmin,Probes and other documents,Directory inside the file can be deleted, the directory can not be deleted. https://oneinstack.comOneinStack.com 《LEMP Image Guide》 1.3 How do use scripts to optimize the parameters Because this image was build based on 1 Core 1G ECS,the configuration and parameters for MySQL/MariaDB,PHP are original without any change, highly recommended If this is not the case, run the following optimization script: cd /root/oneinstack #Must enter the directory execution under oneinstack ./optimize.sh #Do not sh optimize.sh or bash optimize.sh such execution NOTE: 1. It may take 1 minute, do not interrupt 2. This script will automatically optimize MySQL, PHP and other parameters according to the system configuration https://oneinstack.comOneinStack.com 《LEMP Image Guide》 2 How to Change your PHP Version cd /root/oneinstack #Must enter the directory execution under oneinstack ./change_php_version.sh #Do not sh change_php_version.sh such execution https://oneinstack.comOneinStack.com 《LEMP Image Guide》 3 Migrating website from OS disk to Data disk Note:If you purchased a data disk(And only one data disk),It is recommended to mount the data disk first,the site content, database storage data cloud disk,If there is no purchase data cloud disk Ignore the tutorial! cd /root/oneinstack #Must enter the directory execution under oneinstack ./move_auto_fdisk.sh #mount data disk and migrate As shown below: https://oneinstack.comOneinStack.com 《LEMP Image Guide》 4 MySQL/MariaDB databases management NOTE: Use following URL to open phpMyAdmin page: http:///phpMyAdmin phpMyAdmin is an application for MySQL databases management. With it you can create, alter, drop, delete, import and export MySQL database tables. You can also run MySQL queries, optimize, repair and check tables, change collation. 4.1 Display default MySQL root password cd /root/oneinstack #Must enter the directory execution under oneinstack grep dbrootpwd options.conf #Display MySQL root password https://oneinstack.comOneinStack.com 《LEMP Image Guide》 4.2 Change MySQL root password cd /root/oneinstack # Must enter the directory execution under oneinstack ./reset_db_root_password.sh https://oneinstack.comOneinStack.com 《LEMP Image Guide》 4.3 Create a MySQL Database For example: create a database named ''oneinstack'' # mysql -uroot –p # enter mysql console Enter password: # Enter mysql root password MySQL [(none)]> create database oneinstack; # Notice the semicolon at the end MySQL [(none)]> show databases; MySQL [(none)]> exit; # quit mysql console,Notice the semicolon at the end https://oneinstack.comOneinStack.com 《LEMP Image Guide》 4.4 Delete a MySQL Database MySQL [(none)]> drop database oneinstack; #delete oneinstack database MySQL [(none)]> exit; # quit mysql console,Notice the semicolon at the end https://oneinstack.comOneinStack.com 《LEMP Image Guide》 4.5 Create a Database User For security purposes, we usually create a unique database connection account for each web application(Account name can not be root)。 E.g:add a user named : db_user,password :123456,Authorization for the localhost to the oneinstack database all permissions,the commands are as follows : # mysql -uroot –p MySQL [(none)]> grant all privileges on oneinstack.* to db_user@''localhost'' identified by ''123456''; # Notice the semicolon at the end MySQL [(none)]> flush privileges; MySQL [(none)]> exit; # quit mysql console,Notice the semicolon at the end https://oneinstack.comOneinStack.com 《LEMP Image Guide》 4.6 How to setup a remote MySQL connection For security reasons, OneinStack only allows the cloud host localhost to connect to the database,if you need a remote connection to the database,the following operations are required: 1. You must open port 3306 for Security groups 2. Database authorization Remote Connection Create a new account(Account name can not be root) E.g:add a user named linuxeye,password 123456,Authorized as % (% Represents all ip can connect, you can set the designated ip)oneinstack database all authority, the commands are as follows # mysql -uroot -p MySQL [(none)]> grant all privileges on oneinstack.* to linuxeye@''%'' identified by ''123456''; # Authorization statement,Special attention to the semicolon MySQL [(none)]> flush privileges; MySQL [(none)]> exit; # Quit the database console,Special attention to the semicolon As shown below: https://oneinstack.comOneinStack.com 《LEMP Image Guide》 https://oneinstack.comOneinStack.com 《LEMP Image Guide》 5 How to manage virtual host 5.1 How to add a virtual host cd /root/oneinstack # Must enter the directory execution under oneinstack ./vhost.sh #NOTE: If no SSL certificate is purchased,SSL under Nginx please enter n https://oneinstack.comOneinStack.com 《LEMP Image Guide》 In the above figure, the directory is the root directory of the Web site,the script is created automatically,Upload the code to the directory when deploying the site (the directory, subdirectories, and file permissions are all:www), correspond Nginx the configuration file path is: /usr/local/nginx/conf/vhost/www.oneinstack.com.conf ( www.oneinstack.com Is the domain name that is bound) Nginx rewrite rule: /usr/local/nginx/conf/rewrite/wordpress.conf Add a virtual host will automatically create this directory https://oneinstack.comOneinStack.com 《LEMP Image Guide》 5.2 How to delete a virtual host cd /root/oneinstack # Must enter the directory execution under oneinstack ./vhost.sh del https://oneinstack.comOneinStack.com 《LEMP Image Guide》 6 How to manage FTP User Accounts cd /root/oneinstack # Must enter the directory execution under oneinstack ./pureftpd_vhost.sh #Do not sh pureftpd_vhost.sh such execution https://oneinstack.comOneinStack.com 《LEMP Image Guide》 7 How to backup Backup Set Parameters cd /root/oneinstack # Must enter the directory execution under oneinstack ./backup_setup.sh https://oneinstack.comOneinStack.com 《LEMP Image Guide》 Perform the backup immediately: cd /root/oneinstack #Must enter the directory execution under oneinstack ./backup.sh Set Scheduled Task Automatic Scheduled Backup: Example:Can be added to scheduled tasks, such as automatic backups every day 1:00 # echo ''0 1 * * * cd ~/oneinstack;./backup.sh > /dev/null 2>&1 & '' >> /var/spool/cron/root View the backup: View the local backup: ls -l /data/backup/ https://oneinstack.comOneinStack.com 《LEMP Image Guide》 8 How to manage service Nginx: service nginx {reload|start|stop|status|restart } PHP: service php-fpm {reload|start|stop|status|restart } MySQL: service mysqld {start|stop|restart|reload|status} Pure-Ftpd: service pureftpd {start|stop|restart|status} Redis: service redis-server {start|stop|status|restart|reload} Memcached: service memcached {start|stop|status|restart|reload} https://oneinstack.comOneinStack.com 《LEMP Image Guide》 9 How to upgrade cd /root/oneinstack # Must enter the directory execution under oneinstack ./upgrade.sh # Do not sh upgrade.sh or bash upgrade.sh such execution https://oneinstack.comOneinStack.com 《LEMP Image Guide》 10 How to add Extensions cd /root/oneinstack # Must enter the directory execution under oneinstack ./addons.sh #NOTE: Support install and uninstall function https://oneinstack.comOneinStack.com 《LEMP Image Guide》 11 How to uninstall Some items can be uninstalled separately, such as RDS database, the database can be uninstalled separately cd /root/oneinstack # Must enter the directory execution under oneinstack ./uninstall.sh # NOTE: Please backup your https://oneinstack.comOneinStack.com 《LEMP Image Guide》 12 More 12.1 How to deploy a website on a server 1. Create the database required for the site,reference《Create a database》 2. Add a virtual host,reference《How to add a virtual host》 3. Create an FTP account,reference《How to manage FTP accounts》 4. Deploy the code to the site root directory NOTE:Ftp upload code do not need to modify permissions,default is already www; Download the code in server , you must modify the site root and subdirectories,Directory file permissions are www; If there is a problem with site permissions,Please refer to《About site root permissions》 wget Download the code to deploy a WordPress,As shown below: https://oneinstack.comOneinStack.com 《LEMP Image Guide》 Access http://www.oneinstack.com,enter the database address(localhost), user named(root),password(database root password),。 As shown below: https://oneinstack.comOneinStack.com 《LEMP Image Guide》 12.2 About the PHP opcode cache by default,in order to reduce PHP compile time,improve performance(Opcache is recommended for production environments),The PHP environment loads the Opcache module by default(PHP7.1,7.0,5.6,5.5),Please refer to the principle: 《In-depth understanding of PHP Opcode caching principles》 But this will appear PHP code updates, take 2 to 3 minutes to take effect,This affects the efficiency of the site during the commissioning phase suggest that you close or refresh the cache every time there is a code update(Recommended method two) Method 1:Uninstall Opcache cd /root/oneinstack #Must enter the directory execution under oneinstack ./addons.sh https://oneinstack.comOneinStack.com 《LEMP Image Guide》 Method 2: Refresh the PHP cache Access http:///ocp.php, Or direct access http:///ocp.php/ocp.php?RESET=1 As shown below: https://oneinstack.comOneinStack.com 《LEMP Image Guide》 12.3 Proper permissions for files/folders Web site root permissions to follow: file 644, folder 755 ,Permissions Users and groups www If there is a file permissions problem, execute the following three commands: chown -R www.www /data/wwwroot/ find /data/wwwroot/ -type d -exec chmod 755 {} \; find /data/wwwroot/ -type f -exec chmod 644 {} \; https://oneinstack.comOneinStack.com 《LEMP Image Guide》 12.4 About Redis and Memcached Redis default port:6379 Memcached default port:11211 default only listen IP:127.0.0.1 1. How to increase the maximum memory size of Redis vi /usr/local/redis/etc/redis.conf maxmemory 1024000000 # service redis-server restart # restart the redis for changes to take effect 2. How to increase the maximum memory size of memcached vi /etc/init.d/memcached CACHESIZE=256 # service memcached restart # restart the memcached for changes to take effect 3. How to change the listening port for redis vi /usr/local/redis/etc/redis.conf bind 127.0.0.1 changed to bind 0.0.0.0 service redis-server restart # restart the redis for changes to take effect 4. How to change the listening port for memcached vi /etc/init.d/memcached OPTIONS=
To view the full page, please visit: LEMP Stack(Nginx PHP8.1 MariaDB10.6) on Ubuntu22.04 Product Userguide

LEMP Stack(Nginx PHP8.1 MariaDB10.6) on Ubuntu22.04

This image is built with Ubuntu22.04 64bit and bundled with following popular software for web service solution.
Buy now