Setting up a LAMP (Apache, MySQL, PHP) development environment on Ubuntu 14.04 (Trusty) LTS for local Drupal/Wordpress development
This is how I normally set up my local Drupal development machines after a fresh Ubuntu 14.04 LTS (desktop/MATE edition) install.
1. Install required packages
From Terminal, execute the following command to update the repository information and to get the system up-to-date:
sudo apt-get update sudo apt-get upgrade
Next, install some basic necessities:
sudo apt-get install openssh-server sshpass \ geany gedit emacs vim gimp inkscape \ git-core curl zlib1g-dev build-essential \ python python-dev python-pip python-gpgme \ libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 \ libncurses-dev libgdbm-dev \ libxml2-dev libxslt1-dev libcurl4-openssl-dev \ software-properties-common python-software-properties \ g++ make build-essential wwwconfig-common
Next, install the latest version of Git from the Ubuntu Git Maintainers PPA:
sudo apt-get remove git sudo add-apt-repository ppa:git-core/ppa sudo apt-get update sudo apt-get install git
Next, run the following command to install the required packages:
sudo apt-get install apache2 apache2-doc \ mysql-server mysql-client libmysqlclient-dev \ php5 libapache2-mod-php5 php5-gd php5-mysql php5-cli \ php5-curl php5-mcrypt php5-imagick phpmyadmin \ php-invoker php5-xdebug php5-sqlite php-apc \ php5-dev php-pear \ drush postfix
Give the following inputs when asked for:
- MySQL Configuration:
- New password for the MySQL "root" user: somesecurepasswordformysqlroot
- Postfix Configuration:
- General type of mail configuration:
Internet Site
- System mail name:
myname-local
- General type of mail configuration:
- Configuring phpmyadmin:
- Web server to reconfigure automatically:
apache2
- Configure database for phpmyadmin with dbconfig-common?
Yes
- Password of the database's administrative user: somesecurepasswordformysqlroot
- Password for phpmyadmin: somesecurepasswordforphpmyadmin
- Web server to reconfigure automatically:
2. Install PHP PECL uploadprogress:
sudo pecl install -Z uploadprogress sudo sh -c 'echo "extension=uploadprogress.so" >> /etc/php5/mods-available/uploadprogress.ini' sudo ln -s /etc/php5/mods-available/uploadprogress.ini /etc/php5/apache2/conf.d/20-uploadprogress.ini sudo service apache2 restart
3. Install Drush
Drush installation now works with Composer (a tool for dependency management in PHP - like npm for nodejs, bundler for ruby).
Use the following steps to install Composer globally:
cd ~/ wget -O - https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer sudo ln -s /usr/local/bin/composer /usr/bin/composer
Then use the following commands to install Drush globally:
sudo apt-get remove drush cd ~/ rm -rf ~/.drush sudo git clone https://github.com/drush-ops/drush.git /usr/local/src/drush cd /usr/local/src/drush sudo git checkout 7.0.0 #or whatever version you want. sudo chmod a+x drush sudo ln -s /usr/local/src/drush/drush /usr/bin/drush sudo composer install cd drush --version
4. Fix the Fully Qualified Domain Name issue for Apache
Now, when you try restarting apache, you get an error as shown below:
~$ sudo service apache2 restart * Restarting web server apache2 AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message [ OK ]
To fix this, run the following commands:
echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf sudo a2enconf fqdn sudo service apache2 restart
5. Enable the mod_rewrite apache module (for "Clean URLs"):
sudo a2enmod rewrite sudo service apache2 restart
6. Increase the upload_max_filesize php.ini value
Open the file for editing with:
sudo vim /etc/php5/apache2/php.ini
and change the line which says:
upload_max_filesize = 2M
to
upload_max_filesize = 100M
Save the file, exit. Then restart apache:
sudo service apache2 restart
7. Enable PHP in user directories (such as ~/public_html):
Run the following command to open up the corresponding config file for editing:
sudo vim /etc/apache2/mods-available/php5.conf
and comment out the following lines by adding a hash symbol '#' to the start of each line:
<IfModule mod_userdir.c> <Directory /home/*/public_html> php_admin_flag engine Off </Directory> </IfModule>
such that the lines now look as follows:
#<IfModule mod_userdir.c> # <Directory /home/*/public_html> # php_admin_flag engine Off # </Directory> #</IfModule>
8. Allow '.htaccess' files to override any apache server option under '~/public_html':
Open up the file for editing:
sudo vim /etc/apache2/mods-available/userdir.conf
and change the line that says:
AllowOverride FileInfo AuthConfig Limit Indexes
to
AllowOverride All
Save and exit.
Now enable mod_userdir:
sudo a2enmod userdir sudo service apache2 restart
9. Test the setup
Now create the ~/public_html folder, and create a test php site:
mkdir -p ~/public_html/test echo "<?php phpinfo(); ?>" > ~/public_html/test/info.php
Now change the USERNAME part in the following variable to your linux username, and then open up the URL in your web browser to make sure everything is working fine:
http://localhost/~USERNAME/test/info.php
You should see a huge table listing of all the PHP config.
- 30627 reads
Comments
Oleksii (not verified)
Wed, 10/21/2015 - 03:33
Permalink
I'm excited
Thank you for the such a good LAMP roadmap. It is really save my time. 1000 thanks
Add new comment