Avoid giving 777 permissions

Just a quick post for me to remember the following workflow of commands:

sudo find . -type d -exec chmod 755 {} \;
sudo find . -type f -exec chmod 644 {} \;
sudo chgrp -R www-data .
sudo chmod -R g+w .
2010-06-28 [, , ]
View Comments

Remove startup scripts on Ubuntu

sudo update-rc.d -f script_name remove
2009-10-20 [, , ]
View Comments

Enable PHP error logging

In php.ini:

display_errors = Off
log_errors = On
error_log = /var/log/php-errors.log

Make the log file, and writable by www-data:

sudo touch /var/log/php-errors.log
sudo chown www-data:www-data /var/log/php-errors.log
2009-07-14 [, ]
View Comments

PHP and nginx on Ubuntu: the easy way

I’ve now changed my slice from running lighttpd to nginx. Here’s the simplest way, in around 6 commands, to get PHP up and running via FastCGI.

Install and setup

Install PHP 5:

sudo aptitude install php5-cgi

Install nginx:

sudo aptitude install nginx

Create PHP 5 FastCGI start-up script:

sudo nano /etc/init.d/php-fastcgi

Inside, put:

#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000

PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
      echo -n "Starting PHP FastCGI: "
      start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}
stop() {
      echo -n "Stopping PHP FastCGI: "
      killall -q -w -u $USER $PHP_CGI
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL

Make start-up script executable:

sudo chmod +x /etc/init.d/php-fastcgi

Launch PHP:

sudo /etc/init.d/php-fastcgi start

Launch at start-up:

sudo update-rc.d php-fastcgi defaults

That’s it. All installed and ready to go.

Test

In your server config, add the following:

location ~ \.php$ {
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
    include         fastcgi_params;
}

Restart nginx:

sudo /etc/init.d/nginx restart

Create a file in your web root (in the example above, /var/www/nginx-default/test.php):

<?php

phpinfo();

Visit the page in your browser and you should see the standard PHP info page. And you’re done.

Source: Aberration

2009-06-13 [, , , ]
View Comments

Quick lighttpd, PHP, iMagick setup on Ubuntu 8.10 Intrepid

Install lighttpd:

sudo aptitude install lighttpd

Install PHP and ImageMagick:

sudo aptitude install php5-common php5-dev php5-mysql php5-sqlite php5-cgi php5-curl php5-gd php-pear libmagick9-dev

Install iMagick:

sudo pecl install imagick

Press enter on prompt.

Add the following to the bottom of /etc/php5/cgi/php.ini:

extension=imagick.so

Then:

sudo lighttpd-enable-mod fastcgi
sudo /etc/init.d/lighttpd reload

Merge video files with mencoder

To merge video files together with mencoder is simple:

mencoder -oac copy -ovc copy file1.avi file2.avi file3.avi -o full_movie.avi

GDM Login Screen Resolution Too Big

If you’ve noticed that the login screen for Ubuntu Gutsy (GDM) is too big, and that you can use the mouse to move the screen around, you’ll need to update your xorg.conf file.

sudo gvim /etc/X11/xorg.conf

When gVim opens, type in the following:

/Virtual

Then hit enter. That’ll search the file for the line that we need to comment out. When it’s found, hit i on the keyboard to enter the Insert mode of gVim. Now prepend a # before the Virtual keyword to comment out the entire line.

Hit escape on the keyboard, then type in :wq to save and quit.

Next time you have the login screen in front of you, it should be using the correct screen resolution.

2008-02-26 [, , , , , , ]
View Comments