Mostrando entradas con la etiqueta Ubuntu. Mostrar todas las entradas
Mostrando entradas con la etiqueta Ubuntu. Mostrar todas las entradas
jueves, 12 de julio de 2018
How to install PHP (7 or 7.2) on Ubuntu
Install PHP 7.2 on Ubuntu
PHP 7.2 stable version has been released. Use the following set of commands to enable PPA for PHP 7.2 in your Ubuntu system and install it. You can use this version for production use also.
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install -y php7.2
Now use the following command to check installed php version on your system.
php -v
PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 22 2018 08:44:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Install PHP 7.1 on Ubuntu
Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install PHP 7.1 version.
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install -y php7.1
Now use the following command to check installed php version on your system.
php -v
PHP 7.1.18-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 11 2018 14:22:30) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.1.18-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
Install PHP 7.0 on Ubuntu
Use the following set of commands to add PPA for PHP 7 in your Ubuntu system and install PHP 7.0 version.
sudo apt-get install python-software-properties sudo add-apt-repository ppa:ondrej/php sudo apt-get update sudo apt-get install -y php7.0
Now use the following command to check installed php version on your system.
php -v
PHP 7.0.30-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: May 2 2018 12:43:14) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.30-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies
Install PHP 7 Modules
You may also need to install modules based on your application requirements. Use the following command to search available PHP 7 modules in the package repository.
sudo apt-cache search php7*
php-all-dev - package depending on all supported PHP development packages php7.0 - server-side, HTML-embedded scripting language (metapackage) php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.0-cli - command-line interpreter for the PHP scripting language php7.0-common - documentation, examples and common module for PHP php7.0-curl - CURL module for PHP php7.0-dev - Files for PHP7.0 module development php7.0-gd - GD module for PHP php7.0-gmp - GMP module for PHP ... ... ... php7.1-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP php7.1-xmlrpc - XMLRPC-EPI module for PHP php7.1-zip - Zip module for PHP php7.1-opcache - Zend OpCache module for PHP php7.1 - server-side, HTML-embedded scripting language (metapackage) php7.1-xsl - XSL module for PHP (dummy) ... ... php7.2-bcmath - Bcmath module for PHP php7.2-bz2 - bzip2 module for PHP php7.2-cgi - server-side, HTML-embedded scripting language (CGI binary) php7.2-cli - command-line interpreter for the PHP scripting language php7.2-common - documentation, examples and common module for PHP php7.2-curl - CURL module for PHP php7.2-dba - DBA module for PHP
You can install the required PHP modules on your system as below command. Make sure to install packages for correct PHP version by specifying the version with the package name. Without defining package version, it will install the latest package.
Install PHP 7.0 modules
You may need some additional packages and PHP modules in order for PHP to work with your applications. You can install the most commonly needed modules with:
apt-get install php-pear php7.0-dev php7.0-zip php7.0-curl php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-xml libapache2-mod-php7.0
Install PHP 7.2 modules
You may need some additional packages and PHP modules in order for PHP to work with your applications. You can install the most commonly needed modules with:
apt-get install php-pear php7.2-dev php7.2-zip php7.2-curl php7.2-gd php7.2-mysql php7.2-mcrypt php7.2-xml libapache2-mod-php7.2
How to change the PHP version you’re using
If you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one.
To set PHP 7.0 as the default, run:
update-alternatives --set php /usr/bin/php7.0
To set PHP 7.2 as the default, run:
update-alternatives --set php /usr/bin/php7.2
If you’re following our LAMP tutorials and you’re using Apache, you can configure Apache to use PHP 7.2 with the following command:
a2enmod php7.2
And then restart Apache for the changes to take effect:
systemctl restart apache2
Speed up PHP by using an opcode cache
You can improve the performance of your PHP by using a caching method. We’ll use APCu, but there are other alternatives available.
If you have the ‘php-pear’ module installed (we included it in our instructions above), you can install APCu with the following command:
pecl install apcu
There are also other ways you can install APCu, including using a package.
To start using APCu, you should run the following command for PHP 7.2:
echo "extension=apcu.so" | tee -a /etc/php/7.2/mods-available/cache.ini
And the following command for PHP 7.0:
echo "extension=apcu.so" | tee -a /etc/php/7.0/mods-available/cache.ini
If you’re following our LAMP tutorials and you’re using Apache, create a symlink for the file you’ve just created.
For PHP 7.2:
ln -s /etc/php/7.2/mods-available/cache.ini /etc/php/7.2/apache2/conf.d/30-cache.ini
For PHP 7.0:
ln -s /etc/php/7.0/mods-available/cache.ini /etc/php/7.0/apache2/conf.d/30-cache.ini
And finally, reload Apache for the changes to take effect:
systemctl restart apache2
viernes, 2 de septiembre de 2016
Linux - Comando Lsof
La propia palabra Lsof ya nos dice lo que hace, “LS Open Files” . Nos ayuda a listar ficheros abiertos, y nos será super útil en determinadas situaciónes donde no sepamos qué carpetas tiene en uso una determinada herramienta.
1 – Ejecutándolo sin más, nos da una lista de los procesos activos y los ficheros usados:
nexolinux m3t4g4m3 # lsof COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME init 1 root cwd DIR 8,1 4096 2 / init 1 root txt REG 8,1 124704 917562 /sbin/init init 1 root 0u CHR 1,3 0t0 4369 /dev/null init 1 root 1u CHR 1,3 0t0 4369 /dev/null init 1 root 2u CHR 1,3 0t0 4369 /dev/null init 1 root 3r FIFO 0,8 0t0 6323 pipe
2- Podemos usarlo para saber qué procesos tiene cogidos un fichero:
nexolinux m3t4g4m3 # lsof /var/log/syslog
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
rsyslogd 488 syslog 1w REG 8,1 1151 268940 /var/log/sysloge
3 – Listar ficheros abiertos en un directorio ( +D directorio )
nexolinux m3t4g4m3 # lsof +D /var/log/ COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME rsyslogd 488 syslog 1w REG 8,1 1151 268940 /var/log/syslog rsyslogd 488 syslog 2w REG 8,1 2405 269616 /var/log/auth.log console-k 144 root 9w REG 8,1 10871 269369 /var/log/ConsoleKit/history
4 – Listar ficheros abiertos basados en procesos ( -c proceso )
nexolinux m3t4g4m3 # lsof -c ssh COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ssh-agent 1528 lakshmanan 1u CHR 1,3 0t0 4369 /dev/null ssh-agent 1528 lakshmanan 2u CHR 1,3 0t0 4369 /dev/null ssh-agent 1528 lakshmanan 3u unix 0xdf70e240 0t0 10464 /tmp/ssh-sUymKXxw1495/agent.1495
5 – Listar ficheros abiertos por un usuario. ( -u )
nexolinux m3t4g4m3 # lsof -u m3t4g4m3 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME update-no 1892 m3t4g4m3 20r FIFO 0,8 0t0 14536 pipe update-no 1892 m3t4g4m3 21w FIFO 0,8 0t0 14536 pipe bash 1995 m3t4g4m3 cwd DIR 8,1 4096 393218 /home/m3t4g4m3
6 - Listar procesos abiertos por puerto. ( -i )
exolinux m3t4g4m3 # lsof -i :3000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME ruby 10975 root 12u IPv4 103067 0t0 TCP server:3000 (LISTEN)
jueves, 14 de julio de 2016
Running PHP Script From Cron
OVERVIEW
Cron is a job based scheduler used in Unix type operating systems. It allows you to schedule tasks to be run at given intervals such as scheduling a php script to run weekly, every second day, hourly, every 3 minutes, weekends, and so on.
In this article, I will show how easy it is in running a php script from cron. It will also show you how you can run a php script via a url using wget.
In this article, I will show how easy it is in running a php script from cron. It will also show you how you can run a php script via a url using wget.
RUNNING PHP SCRIPT FROM CRON
I will show you 3 ways on running php script from cron which are:
- Running php script via command line in cron
- Running php script via php5-cgi in cron
- Running php script remotely via website url in cron
Running a php script usually requires the php script to have execute permissions set. Running PHP script from cron is usually a matter of specifying the file and as long as the script has execute permissions (i.e. chmod +x) then all should be good. Here are three ways I have found work very well.
RUNNING PHP SCRIPT ON COMMAND LINE FROM CRON
In order for the script to run correctly you should add the following to your php script. The informs the bash what type of script it is executing.
- #!/usr/bin/php
- <?php
- //.. your code follows here
Next we add the entry into cron.
- # you could output to a file by changing /dev/null to /some/file/to/save.log
- */10 * * * * /home/user/scripts/updatesomething.php > /dev/null
Note we didn’t need to execute the script via php (/usr/bin/php /path/to/script.php) since we added the header to the php script.
RUNNING PHP SCRIPT VIA PHP5-CGI IN CRON
To execute the php script from cron you need to have php5-cgi installed. You can install this on Debian use “apt-get install php5-cgi” or the equivalent command for your distribution of linux.
- # PHP5-CGI: execute the php script every 2 minutes and send output to /dev/null
- # you could output to a file by changing /dev/null to /some/file/to/save.txt
- */2* * * * php5-cgi -q /home/user/scripts/parselogs.php > /dev/null
RUNNING PHP SCRIPT VIA WEBSITE URL IN CRON
And lastly we will use wget from the cron to download a website url and thus, execute the url that the php script is located at. We do this in the cron to allow the url to be downloaded at set times. To use wget, you need to install itwget using “apt-get install wget” or the equivalent command for your distribution of linux.
- # wget will visit the url but won't save the file. send it to /dev/null
- # this executes the script as if you visited the link in your browser
- 0 * * * * wget -O /dev/null http://www.example.com/some_cron_script.php
And there we go, your php script will be run by cron on time, every time.
martes, 22 de marzo de 2016
Supervisord: Restarting and Reloading
No hay comentarios
:
Posted by
daycry
at
17:18
Labels:
beanstalk
,
beanstalkd
,
queue
,
supervisor
,
supervisorctl
,
Ubuntu
Supervisord is a great daemon for managing application processes. However it does not have a reload option, and restart works different than we get used to. These command makes the following effects.
service supervisor restart |
Restart supervisor service without making configuration changes available. It stops, and re-starts all managed applications.
supervisorctl restart <name> |
Restart application without making configuration changes available. It stops, and re-starts the application.
If you create a new configuration. None of the commands above will make it available. If you want to apply your configuration changes in both existing and new configurations, start applications in new configurations,and re-start all managed applications, you should run:
service supervisor stopservice supervisor start |
If you do not want to re-start all managed applications, but make your configuration changes available, use this command:
supervisorctl reread |
This command only updates the changes. It does not restart any of the managed applications, even if their configuration has changed. New application configurations cannot be started, neither. (See the “update” command below)
supervisorctl update |
Restarts the applications whose configuration has changed.
Note: After the update command, new application configurations becomes available to start, but do not start automatically until the supervisor service restarts or system reboots (even if autostart option is not disabled). In order to start new application, e.g app2, simply use the following command:
Note: After the update command, new application configurations becomes available to start, but do not start automatically until the supervisor service restarts or system reboots (even if autostart option is not disabled). In order to start new application, e.g app2, simply use the following command:
supervisorctl start app2 |
lunes, 14 de diciembre de 2015
Creating MySQL Backups With AutoMySQLBackup
No hay comentarios
:
Posted by
daycry
at
12:23
Labels:
automysqlbackup
,
Cron
,
Linux
,
MySQL
,
Ubuntu
AutoMySQLBackup is a shell script that lets you take daily, weekly and monthly backups of your MySQL databases using mysqldump. It can back up multiple databases, compress the backups, back up remote databases, and email the logs. This tutorial explains how to install and use it on an Ubuntu 9.10 server.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
AutoMySQLBackup uses mysqldump to create SQL dumps of your databases. Please note that mysqldump will lock your databases while the backup is being created, and this can take from less than a second up to a few minutes, depending on the size of your database. If you're running a high-traffic web site with a large database, then AutoMySQLBackup is not for you!
This script will not help in the event of a hard drive crash. You should copy your backups offline regularly for best protection.
I'm running all the steps in this tutorial with root privileges, so make sure you're logged in as root:
sudo su
2 Using AutoMySQLBackup
You can install AutoMySQLBackup as follows:
aptitude install automysqlbackup
Then open /etc/default/automysqlbackup and take a look at the configuration options. They are all well explained. You should at least configure the following settings:
vi /etc/default/automysqlbackup
[...] # Host name (or IP address) of MySQL server e.g localhost DBHOST=localhost [...] # List of DBNAMES for Daily/Weekly Backup e.g. "DB1 DB2 DB3" # The following is a quick hack that will find the names of the databases by # reading the mysql folder content. Feel free to replace by something else. #DBNAMES="db_ispconfig web1 web2 web3" DBNAMES=`find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f5 | grep -v ^mysql\$ | tr \\\r\\\n ,\ ` [...] # Backup directory location e.g /backups # Folders inside this one will be created (daily, weekly, etc.), and the # subfolders will be database names. BACKUPDIR="/var/lib/automysqlbackup" [...] # Email Address to send mail to? (user@domain.com) MAILADDR="user@domain.com" [...] |
DBNAMES can contain one or multiple databases, separated by spaces.
If BACKUPDIR does not exist, automysqlbackup will create it automatically (the default directory is /var/lib/automysqlbackup).
If you want to back up local databases, use localhost; if you want to back up remote databases, use the remote hostname (please note that the remote database server must be configured to allow remote connections!).
Now you can run automysqlbackup:
automysqlbackup
Take a look at the /var/lib/automysqlbackup directory...
ls -l /var/lib/automysqlbackup
... and you should find three subdirectories, daily, weekly, and monthly:
root@server1:~# ls -l /var/lib/automysqlbackup total 12 drwxr-xr-x 4 root root 4096 2010-01-27 17:20 daily drwxr-xr-x 2 root root 4096 2010-01-27 17:20 monthly drwxr-xr-x 4 root root 4096 2010-01-27 17:20 weekly root@server1:~#These directories will contain subdirectories named after the databases you chose to backup. For example, if you chose the database db_ispconfig, there will be a directory /var/lib/automysqlbackup/daily/db_ispconfig containing the database dump:
ls -l /var/lib/automysqlbackup/daily/db_ispconfig/ root@server1:~# ls -l /var/lib/automysqlbackup/daily/db_ispconfig/ total 40 -rw------- 1 root root 37016 2010-01-27 17:20 db_ispconfig_2010-01-27_17h20m.Wednesday.sql.gz root@server1:~#The .gz extension means it's compressed. To restore a database, you'd first have to uncompress the dump:
gunzip /var/lib/automysqlbackup/daily/db_ispconfig/db_ispconfig_2010-01-27_17h20m.Wednesday.sql.gz
... (this will give you the uncompressed dump named db_ispconfig_2010-01-27_17h20m.Wednesday.sql in the/var/lib/automysqlbackup/daily/db_ispconfig/ directory) and then restore it as described onhttp://www.howtoforge.com/faq/6_4_en.html.
Of course, you don't want to run automysqlbackup manually all the time. Fortunately, there's a cron job for this in/etc/cron.daily/automysqlbackup which takes care of running automysqlbackup automatically once per day.
Suscribirse a:
Entradas
(
Atom
)
Sígueme en las Redes Sociales
Donaciones
Datos personales
Entradas populares
-
En este apartado vamos a explicar como ejercutar archivos PHP a través del terminal de Ubuntu. Lo primero que tendríamos que hacer es inst...
-
En este blog voy a comentar un tema que se utilizan en casi todas las páginas web que existen, y es el tema de la paginación. La paginaci...
-
Este post trata de la integración de la librería PHPExcel en Codeigniter, aunque se podría aplicar a cualquier librería, como por ejemplo mP...
-
Ejemplo para añadir o sumar un número determinado de hora/s, minuto/s, segundo/s a una fecha en php. Con la función strtotime se puede ...
-
Este tema es uno de los temas primordiales sobre el framework Codeigniter, ya que en alguna ocación nos hemos visto obligados a recoger dato...
© Espacio Daycry - Espacio de programación 2013 . Powered by Bootstrap , Blogger templates and RWD Testing Tool



